[英]webpack build failed because of uglifyJsPlguin
I try building webpack.config.js
file. 我尝试构建
webpack.config.js
文件。 My command is webpack --config webpack.config.prod.js --progress --colors
. 我的命令是
webpack --config webpack.config.prod.js --progress --colors
。 But my building is failed because of ulgifyJsPlugin. 但是由于ulgifyJsPlugin,我的建筑失败了。 When I removed uglifyJsPlugin in
webpack.config.prod.js
, building is successful, but not working when there is UlgifyJsPlugin. 当我在
webpack.config.prod.js
删除uglifyJsPlugin时,构建成功,但是在存在UlgifyJsPlugin时无法正常工作。 I want to minimize my codes by webpack - like remove console.log codes and other unnecessary codes. 我想通过webpack最小化我的代码-例如删除console.log代码和其他不必要的代码。 Plus, I'm using webpack 1.
另外,我正在使用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;
Try modifying your plugins
section to include the plugin like this: 尝试修改您的
plugins
部分,以包括如下所示的插件:
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
? 另外,您确定要执行
npm i --save
吗? Make sure you've added the plugin in your node_modules
. 确保已将插件添加到
node_modules
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.