webpack 4.2 – how can I obtain the original source file name and line line number, where the error was thrown?

≡放荡痞女 提交于 2019-12-11 13:25:20

问题


By default Webpack 4 is using UglifyJS for minifying the code.

In the production I am getting an unusable error message point to the column of the compiled javascript file.

The documentation

https://webpack.js.org/guides/migrating/#uglifyjsplugin-sourcemap

claims that one should be able to obtain the correct line by setting sourceMap to true in the UglifyJS Plugin. I've tried it, but that's not working.

Here's the respective webpack config file:

const webpack = require('webpack');
const CompressionPlugin = require('compression-webpack-plugin');
const UglifyJsPlugin = require('uglifyjs-webpack-plugin');
const webpackMerge = require('webpack-merge');
const ssrClientConfig = require('./wp4-ssr-client-config');
const SWPrecachePlugin = require('sw-precache-webpack-plugin');

module.exports = webpackMerge(ssrClientConfig, {
  mode: 'production',
  // entry is set in ssrClientConfig 
  output: {
    filename: '[name]-[hash:8].js'//,
  },
  devtool: 'source-map',
  plugins: [
    // trying to get a proper source map according to
    // https://webpack.js.org/guides/migrating/#uglifyjsplugin-sourcemap 
    new UglifyJsPlugin({
      sourceMap: true, 
    }),

    // setting for Vue according to:
    // https://vuejs.org/v2/guide/deployment.html
    new webpack.DefinePlugin({
      'process.env.NODE_ENV': '"production"',
      'process.env.VUE_ENV': '"client"'
    }),

    new SWPrecachePlugin({
      cacheId: 'vue-hn',
      filename: 'service-worker.js',
      minify: true,
      dontCacheBustUrlsMatching: /./,
      staticFileGlobsIgnorePatterns: [
        /\.map$/, /\.json$/
      ]
    })  
  ]
});

来源:https://stackoverflow.com/questions/49477274/webpack-4-2-how-can-i-obtain-the-original-source-file-name-and-line-line-numbe

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!