![](/img/trans.png)
[英]Gatsby Build failed because of "Unknown Word' Error from CSS minimzer on postcss and css-minimizer-webpack-plugin
[英]webpack build failed because of uglifyJsPlguin
我嘗試構建webpack.config.js
文件。 我的命令是webpack --config webpack.config.prod.js --progress --colors
。 但是由於ulgifyJsPlugin,我的建築失敗了。 當我在webpack.config.prod.js
刪除uglifyJsPlugin時,構建成功,但是在存在UlgifyJsPlugin時無法正常工作。 我想通過webpack最小化我的代碼-例如刪除console.log代碼和其他不必要的代碼。 另外,我正在使用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;
嘗試修改您的plugins
部分,以包括如下所示的插件:
plugins: [
...,
new webpack.optimize.UglifyJsPlugin({
compress: {
warnings: false,
},
comments: false,
sourceMap: false,
mangle: true
})
]
這對我有用。
另外,您確定要執行npm i --save
嗎? 確保已將插件添加到node_modules
。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.