Reputation: 71
I try building webpack.config.js
file. My command is webpack --config webpack.config.prod.js --progress --colors
. But my building is failed because of ulgifyJsPlugin. When I removed uglifyJsPlugin in webpack.config.prod.js
, building is successful, but not working when there is UlgifyJsPlugin. I want to minimize my codes by webpack - like remove console.log codes and other unnecessary codes. Plus, I'm using webpack 1.
const webpack = require('webpack');
const path = require('path');
const nodeModulesPath = path.resolve(__dirname, 'node_modules');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const config = {
entry: [path.join(__dirname, '/src/index.js')],
devtool: 'source-map',
output: {
path: path.join(__dirname, 'dist'),
filename: 'bundle.js',
},
module: {
loaders: [
{
test: /\.jsx?$/,
loader: 'babel-loader',
exclude: [nodeModulesPath]
},
{
test: /\.css$/,
loaders: ['style', 'css']
}
]
},
resolve: {
root: [
path.resolve('./src'),
path.resolve('./style')
],
extensions: ['', '.js', '.jsx', '.css'],
packageAlias: 'browser'
},
plugins: [
new HtmlWebpackPlugin({
template: './public/index.html'
}),
new webpack.DefinePlugin({
'process.env':{
'NODE_ENV': JSON.stringify('production')
}
}),
new AppCachePlugin({
exclude: ['.htaccess']
}),
new webpack.optimize.UglifyJsPlugin({
compress: {
warnings: false,
}
})
],
};
module.exports = config;
Upvotes: 0
Views: 284
Reputation: 403012
Try modifying your plugins
section to include the plugin like this:
plugins: [
...,
new webpack.optimize.UglifyJsPlugin({
compress: {
warnings: false,
},
comments: false,
sourceMap: false,
mangle: true
})
]
This works for me.
Also, were you sure to do npm i --save
? Make sure you've added the plugin in your node_modules
.
Upvotes: 1