由于 uglifyJsPlguin,webpack 构建失败
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
.
我尝试构建 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
.