我想知道如何指示我的webpack配置在开发和生产模式下运行不同的源映射。
目前,我只是注释掉我不想要的部分,这显然非常不方便,我希望根据我正在运行的npm脚本(生产服务器或webpack dev服务器)动态地做出这个决定。
我已经有一个对应于开发模式的变量(
以下是我的当前配置...
目前,我只是注释掉我不想要的部分,这显然非常不方便,我希望根据我正在运行的npm脚本(生产服务器或webpack dev服务器)动态地做出这个决定。
我已经有一个对应于开发模式的变量(
const debug
),但我不确定如何在我的配置中使用它来确定不同的源映射。以下是我的当前配置...
const debug = process.env.NODE_ENV !== "production";
const webpack = require('webpack');
const path = require('path');
module.exports = {
// devtool: 'eval-source-map',
devtool: 'source-map',
entry: path.join(__dirname, 'public', 'app-client.js'),
devServer: {
inline: true,
port: 3333,
contentBase: "public/static/",
historyApiFallback: {
index: '/index-static.html'
}
},
output: {
path: path.join(__dirname, 'public', 'static', 'js'),
publicPath: "/js/",
filename: 'bundle.js'
},
module: {
loaders: [
{
test: path.join(__dirname, 'public'),
loader: ['babel-loader'],
query: {
presets: debug ? ['react', 'es2015', 'react-hmre', 'stage-2'] : ['react', 'es2015', 'stage-2']
}
},
{
test: /\.(jpe?g|png|gif|svg)$/i,
loaders: [
'file?hash=sha512&digest=hex&name=[hash].[ext]',
'image-webpack?bypassOnDebug&optimizationLevel=7&interlaced=false'
]
}
]
},
plugins: debug ? [] : [
new webpack.DefinePlugin({
'process.env.NODE_ENV': JSON.stringify(process.env.NODE_ENV)
}),
new webpack.optimize.DedupePlugin(),
new webpack.optimize.OccurenceOrderPlugin(),
new webpack.optimize.UglifyJsPlugin({
compress: { warnings: false },
mangle: true,
sourcemap: false,
beautify: false,
dead_code: true
}),
]
}