默认情况下,Webpack 4使用UglifyJS来缩小代码。
在制作中,我收到一条不可用的错误消息指向已编译的javascript文件的列。
文档
https://webpack.js.org/guides/migrating/#uglifyjsplugin-sourcemap
声称应该能够通过在UglifyJS插件中将sourceMap设置为true来获取正确的行。我试过了,但那不行。
以下是相应的webpack配置文件:
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$/
]
})
]
});