我尝试从webpack 1转换为2但webpack似乎没有使用devtool: 'source-map'生成源地图文件。如果我使用以下配置运行webpack,bundle.js
文件在/public
中按预期创建,但没有bundle.js.map
文件,也没有错误。使用webpack 1,它按预期工作:
const webpack = require('webpack')
module.exports = {
entry: ['babel-polyfill', './src/index.js'],
output: {
path: './public',
filename: 'bundle.js'
},
module: {
rules: [
{
test: /\.js$/,
exclude: /node_modules/,
loader: 'babel-loader'
}
]
},
devtool: 'source-map',
plugins: [
new webpack.DefinePlugin({
'process.env': {
NODE_ENV: '"production"'
API_BASE_URL: `"${process.env.API_BASE_URL || '/api/v1'}"`
}
}),
new webpack.optimize.UglifyJsPlugin()
]
}
CLI输出:
> cross-env NODE_ENV=production webpack
Hash: 738da5a3824ffac20236
Version: webpack 2.2.0
Time: 13819ms
Asset Size Chunks Chunk Names
bundle.js 611 kB 0 [emitted] [big] main
[2] ./~/react/react.js 56 bytes {0} [built]
答案 0 :(得分:7)
看起来如果你正在使用UglifyJSPlugin源代码地图会被静默禁用,除非你在那里重新启用它们:
plugins: [
new webpack.optimize.UglifyJsPlugin({sourceMap: true})
]