vue项目使用webpack-bundle-analyzer通过npm run build生成的report.html打开后是空白的,但是生成的stats.json通过第三方分析网页显示没有问题,是哪里配置出错了吗?下面是vue.config.js配置
'use strict'
const path = require('path')
const CompressionPlugin = require('compression-webpack-plugin')
const productionGzipExtensions = ['js', 'css', 'html', 'woff', 'ttf', 'eot']
const webpack = require('webpack')
const BundleAnalyzerPlugin = require('webpack-bundle-analyzer').BundleAnalyzerPlugin
const LodashModuleReplacementPlugin = require('lodash-webpack-plugin')
function resolve(dir) {
return path.join(__dirname, dir)
}
const name = 'aaa'
const port = process.env.port || process.env.npm_config_port || 9528 // dev port
module.exports = {
publicPath: '/',
outputDir: 'dist',
assetsDir: 'static',
lintOnSave: process.env.NODE_ENV === 'development',
productionSourceMap: false,
devServer: {
port: port,
open: true,
overlay: {
warnings: false,
errors: true
}
},
configureWebpack: config => {
const webpackConfig = {
externals: {
three: 'THREE',
echarts: 'echarts',
'echarts-gl': 'echarts-gl',
'echarts-extension-amap': 'echarts-extension-amap',
xlsx: 'XLSX'
},
output: {
},
plugins: [
]
// module: {
}
if (process.env.NODE_ENV === 'production') {
webpackConfig.name = name
webpackConfig.output.filename = `[name].[hash:8].js`
webpackConfig.output.chunkFilename = `[name].[hash:8].js`
webpackConfig.plugins.push(new CompressionPlugin({
algorithm: 'gzip',
test: new RegExp('\\.(' + productionGzipExtensions.join('|') + ')$'),
threshold: 10240,
minRatio: 0.8,
deleteOriginalAssets: true
}))
webpackConfig.plugins.push(new webpack.optimize.MinChunkSizePlugin({
minChunkSize: 1000000
}))
webpackConfig.plugins.push(new BundleAnalyzerPlugin())
}
return webpackConfig
},
chainWebpack(config) {
config.plugin('preload').tap(() => [{
rel: 'preload',
fileBlacklist: [/\.map$/, /hot-update\.js$/, /runtime\..*\.js$/],
include: 'initial'
}])
config.plugins.delete('prefetch')
config.module
.rule('svg')
.exclude.add(resolve('src/icons'))
.end()
config.module
.rule('icons')
.test(/\.svg$/)
.include.add(resolve('src/icons'))
.end()
.use('svg-sprite-loader')
.loader('svg-sprite-loader')
.options({
symbolId: 'icon-[name]'
})
.end()
config
.when(process.env.NODE_ENV !== 'development',
config => {
config
.plugin('ScriptExtHtmlWebpackPlugin')
.after('html')
.use('script-ext-html-webpack-plugin', [{
// `runtime` must same as runtimeChunk name. default is `runtime`
inline: /runtime\..*\.js$/
}])
.end()
config
.optimization.splitChunks({
chunks: 'all',
cacheGroups: {
libs: {
name: 'chunk-libs',
test: /[\\/]node_modules[\\/]/,
priority: 10,
chunks: 'initial' // only package third parties that are initially dependent
},
elementUI: {
name: 'chunk-elementUI', // split elementUI into a single package
priority: 20, // the weight needs to be larger than libs and app or it will be packaged into libs or app
test: /[\\/]node_modules[\\/]_?element-ui(.*)/ // in order to adapt to cnpm
},
commons: {
name: 'chunk-commons',
test: resolve('src/components'), // can customize your rules
minChunks: 3, // minimum common number
priority: 5,
reuseExistingChunk: true
}
}
})
config.optimization.minimizer('terser').tap((args) => {
args[0].terserOptions.compress.drop_console = true
args[0].terserOptions.compress.drop_debugger = true
args[0].terserOptions.compress.pure_funcs = ['console.log']
args[0].terserOptions.output = {
comments: false
}
return args
})
// https:// webpack.js.org/configuration/optimization/#optimizationruntimechunk
config.optimization.runtimeChunk('single')
}
)
config
.plugin('loadshReplace')
.use(new LodashModuleReplacementPlugin())
}
}
chainWebpack: config => {
if (process.env.ANALAYZ_PORT && process.env.NODE_ENV === 'production') {
config
.plugin('webpack-bundle-analyzer')
.use(require('webpack-bundle-analyzer').BundleAnalyzerPlugin)
}
}