为什么在使用UglifyJs时源地图无效?

时间:2019-06-01 07:54:35

标签: reactjs webpack uglifyjs

在我的应用程序中运行npm run build时,会收到以下警告:static/js/widget.js contains invalid source map

当我在Webpack配置中删除UglifyJs设置时,构建过程将顺利进行,而不会发出任何警告。

我的Webpack配置(仅与源映射有关的部分):

// Source maps are resource heavy and can cause out of memory issue for large source files.
const shouldUseSourceMap = process.env.GENERATE_SOURCEMAP !== 'false';

module.exports = {
  // Don't attempt to continue if there are any errors.
  bail: true,
  mode: 'production',
  // We generate sourcemaps in production. This is slow but gives good results.
  // You can exclude the *.map files from the build during deployment.
  devtool: shouldUseSourceMap ? 'source-map' : false,

...


plugins: [
    new UglifyJsPlugin({
      uglifyOptions: {
        sourceMap: shouldUseSourceMap,
        warnings: false,
        compress: {
          comparisons: false
        },
        output: {
          comments: false,
          ascii_only: true
        },
      }
    }),
]


0 个答案:

没有答案