Private
Public Access
1
0

improve webpack config for prod compile #23

This commit is contained in:
2016-11-30 20:48:17 +01:00
parent 50b3663889
commit f44bc58df2
4 changed files with 79 additions and 6 deletions

57
webpack-prod.config.js Normal file
View File

@@ -0,0 +1,57 @@
'use strict';
var webpack = require("webpack");
process.env.NODE_ENV = 'production';
var isProd = (process.env.NODE_ENV === 'production');
/**
* Conditionally return a list of plugins to use based on the current environment.
* Repeat this pattern for any other config key (ie: loaders, etc).
* @returns {Array}
*/
function getPlugins() {
var plugins = [];
/**
* Always expose NODE_ENV to webpack, you can now use `process.env.NODE_ENV`
* inside your code for any environment checks; UglifyJS will automatically
* drop any unreachable code.
*/
plugins.push(new webpack.DefinePlugin({
'process.env': {
'NODE_ENV': JSON.stringify(process.env.NODE_ENV)
}
}));
/** Conditionally add plugins for Production builds. */
if (isProd) {
plugins.push(new webpack.optimize.UglifyJsPlugin());
} else {
/** Conditionally add plugins for Development */
}
return plugins;
}
const config = module.exports = {
entry: './web/bundles/mineseeker/js/mine-seeker.js',
output: {
path: './src/Mine/SeekerBundle/Resources/public/js',
filename: 'index.min.js'
},
module: {
loaders: [
{
test: /\.js$/,
exclude: /node_modules/,
loader: 'babel',
query: {
presets: ['es2015', 'react']
}
}
]
},
plugins: getPlugins()
};
module.exports = config;