这是我的生产环境的webpack配置。
var path = require('path');
var webpack = require('webpack');
var precss = require('precss');
var autoprefixer = require('autoprefixer');
var SaveAssetsJson = require('assets-webpack-plugin');
...
console.log('Build optimized for production\n');
config.output.filename = '[hash].plan.js';
config.module.loaders.push({
test: /\.js$/,
loaders: ['babel'],
exclude: /node_modules/,
include: path.join(__dirname, 'app'),
});
通过npm / package.json消耗。在package.json
scripts
部分,这里是build
目标:
"build": "NODE_ENV=production webpack -p --config webpack.config.js",
现在我想关闭某个环境的输出脚本uglification主要用于调试目的。
这是我新添加的webpack配置:
switch (process.env.NODE_ENV) {
case 'staging':
console.log(`Build optimized for ${process.env.NODE_ENV}\n`);
config.output.filename = '[hash].plan.js';
config.module.loaders.push({
test: /\.js$/,
loaders: ['babel'],
exclude: /node_modules/,
include: path.join(__dirname, 'app'),
});
config.plugins = [
new webpack.LoaderOptionsPlugin({
minimize: true,
debug: false
}),
new webpack.optimize.UglifyJsPlugin({
beautify: false,
comments: false
})
]
break;
...
package.json中的相关依赖
assets-webpack-plugin": "3.5.0",
"webpack": "1.13.3",
我从webpack文档https://webpack.js.org/guides/production-build/
复制插件配置然而,当我运行npm run build:staging
时,我收到了这个错误:
> plan@1.0.0 build:staging /Users/antkong/project
> NODE_ENV=staging webpack --config webpack.config.js
Build optimized for staging
/Users/antkong/project/webpack.config.js:82
new webpack.LoaderOptionsPlugin({
^
package.json中的相应命令:
"build:staging": "NODE_ENV=staging webpack --config webpack.config.js",
我错过了什么?我应该安装任何dev依赖吗?
答案 0 :(得分:4)
LoaderOptionsPlugin
,它已被添加到webpack 2中以简化转换。
您可以升级到此时推荐的webpack 2,或者如果您想要或必须继续使用webpack 1,则需要从插件列表中删除LoaderOptionsPlugin
。