我正在使用Windows 10版本,并想知道为什么这段代码不起作用:
"build": "npm run clean && set NODE_ENV=production && webpack && gulp prod"
如果我在console.log中调用webpack,它说node_env正在生产中,但它没有运行生产代码。
我尝试在&&
之前没有webpack
的情况下执行命令,但是在这种情况下它甚至没有运行webpack,所以我不确定我能做到这一点。我尝试使用名为npm-run-all
的软件包并分离命令,然后将parallel
标记与npm-run-all
一起运行,但这也不起作用。
这是webpack:
var webpack = require('webpack');
var path = require('path');
var CommonsChunkPlugin = new require('webpack/lib/optimize/CommonsChunkPlugin');
var chunks = ['app'];
var config = require('./package.json');
module.exports = {
entry: {
app: './src/index.js'
},
output: {
path: __dirname + '/public/dist',
filename: 'bundle/[name].js',
sourceMapFilename: 'bundle/[name].map'
},
node: {
fs: 'empty'
},
devtool: '#source-map',
plugins:
process.env.NODE_ENV === 'production'
? [
new CommonsChunkPlugin({
name: 'commons',
chunks: chunks
}),
new webpack.DefinePlugin({
'process.env': {
NODE_ENV: JSON.stringify('production')
}
}),
new webpack.optimize.UglifyJsPlugin({
minimize: true,
compress: {
warnings: false,
drop_console: true
}
})
]
: [
new CommonsChunkPlugin({
name: 'commons',
chunks: chunks
})
],
module: {
loaders: [
{
test: /\.jsx?$/,
exclude: /(node_modules|bower_components)/,
loader: 'babel-loader',
query: {
presets: ['react', 'es2015']
}
},
{
test: /\.json$/,
loader: 'json-loader'
},
{
test: /\.(jpg|png|svg)$/,
loader: 'file-loader',
query: {
name: '[name].[ext]',
outputPath: 'images/',
publicPath: config.server ? '/' : 'public/dist/',
useRelativePath: false
}
}
]
}
};