0
我嘗試編譯webpack.config.js
文件。我的命令是webpack --config webpack.config.prod.js --progress --colors
。但是我的建築因ulgifyJsPlugin而失敗。當我移除webpack.config.prod.js
中的uglifyJsPlugin時,構建成功,但在UlgifyJsPlugin時無法工作。我想通過webpack最小化我的代碼 - 就像刪除console.log代碼和其他不必要的代碼。另外,我使用的WebPack 1webpack編譯失敗,因爲uglifyJsPlguin
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;
請確保你已安裝[UglifyJS](https://github.com/mishoo/UglifyJS2)...正如[此處]所述(https://webpack.js.org/plugins/uglifyjs-webpack-plugin /),UglifyJS是這個插件的一個peer-dependency –