mirror of
http://112.124.100.131/happyinsurance_eco/ebiz-sunful-eco-web.git
synced 2025-12-06 17:36:50 +08:00
134 lines
3.2 KiB
JavaScript
134 lines
3.2 KiB
JavaScript
'use strict'
|
|
const path = require('path')
|
|
const defaultSettings = require('./src/assets/js/utils/settings.js')
|
|
const CompressionPlugin = require('compression-webpack-plugin')
|
|
|
|
function resolve(dir) {
|
|
return path.join(__dirname, dir)
|
|
}
|
|
const name = defaultSettings.title || 'basic-pc' // 页面标题
|
|
const port = process.env.port || process.env.npm_config_port || 7006 // 开发端口
|
|
|
|
module.exports = {
|
|
runtimeCompiler: true,
|
|
|
|
// 设置打包资源的基础路径
|
|
publicPath: '.',
|
|
outputDir: 'dist',
|
|
assetsDir: 'static',
|
|
lintOnSave: process.env.NODE_ENV === 'development',
|
|
productionSourceMap: false,
|
|
devServer: {
|
|
port: port,
|
|
host: '0.0.0.0',
|
|
open: true,
|
|
overlay: {
|
|
warnings: false,
|
|
errors: true
|
|
}
|
|
},
|
|
proxy: {
|
|
'/backmanage': {
|
|
target: process.env.VUE_APP_ADMIN,
|
|
changeOrigin: true,
|
|
pathRewrite: {
|
|
'^/backmanage': '/'
|
|
}
|
|
}
|
|
},
|
|
configureWebpack: {
|
|
name: name,
|
|
resolve: {
|
|
alias: {
|
|
'@': resolve('src')
|
|
}
|
|
},
|
|
plugins: [
|
|
new CompressionPlugin({
|
|
filename: '[path][base].gz',
|
|
algorithm: 'gzip',
|
|
test: /\.(js|css|html|svg)$/,
|
|
threshold: 10240,
|
|
minRatio: 0.8
|
|
})
|
|
]
|
|
},
|
|
chainWebpack(config) {
|
|
config.plugins.delete('preload')
|
|
config.plugins.delete('prefetch')
|
|
|
|
// SVG Sprite Loader 配置
|
|
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]'
|
|
})
|
|
|
|
// Vue preserveWhitespace 设置
|
|
config.module
|
|
.rule('vue')
|
|
.use('vue-loader')
|
|
.loader('vue-loader')
|
|
.tap(options => {
|
|
options.compilerOptions.preserveWhitespace = true
|
|
return options
|
|
})
|
|
|
|
// Source Map 设置(开发环境)
|
|
config.when(process.env.NODE_ENV === 'development', config => config.devtool('cheap-source-map'))
|
|
|
|
// 生产环境优化
|
|
config.when(process.env.NODE_ENV !== 'development', config => {
|
|
config
|
|
.plugin('ScriptExtHtmlWebpackPlugin')
|
|
.after('html')
|
|
.use('script-ext-html-webpack-plugin', [
|
|
{
|
|
inline: /runtime\..*\.js$/
|
|
}
|
|
])
|
|
|
|
// 分包策略
|
|
config.optimization.splitChunks({
|
|
chunks: 'all',
|
|
minSize: 3000,
|
|
maxSize: 6000,
|
|
maxInitialRequests: 3,
|
|
cacheGroups: {
|
|
libs: {
|
|
name: 'chunk-libs',
|
|
test: /[\\/]node_modules[\\/]/,
|
|
priority: 10,
|
|
chunks: 'initial'
|
|
},
|
|
elementUI: {
|
|
name: 'chunk-elementUI',
|
|
priority: 20,
|
|
test: /[\\/]node_modules[\\/]_?element-ui(.*)/
|
|
},
|
|
commons: {
|
|
name: 'chunk-commons',
|
|
test: resolve('src/components'),
|
|
minChunks: 3,
|
|
priority: 5,
|
|
reuseExistingChunk: true
|
|
}
|
|
}
|
|
})
|
|
config.optimization.runtimeChunk('single')
|
|
})
|
|
|
|
// 添加时间戳到文件名中
|
|
config.output.filename(`js/[name].[hash:8].js`).chunkFilename(`js/[name].[hash:8].js`)
|
|
}
|
|
}
|