|
|
@@ -19,34 +19,37 @@ module.exports = {
|
|
|
// 让 Babel 处理 quill 模块
|
|
|
'quill'
|
|
|
],
|
|
|
- // 部署生产环境和开发环境下的URL。
|
|
|
- // 默认情况下,Vue CLI 会假设你的应用是被部署在一个域名的根路径上
|
|
|
- // 例如 https://www.jianke.vip/。如果应用被部署在一个子路径上,你就需要用这个选项指定这个子路径。例如,如果你的应用被部署在 https://www.jianke.vip/admin/,则设置 baseUrl 为 /admin/。
|
|
|
+ // 部署生产环境和开发环境下的URL
|
|
|
publicPath: process.env.NODE_ENV === "production" ? "/" : "/",
|
|
|
- // 在npm run build 或 yarn build 时 ,生成文件的目录名称(要和baseUrl的生产环境路径一致)(默认dist)
|
|
|
+ // 在 npm run build 或 yarn build 时,生成文件的目录名称(要和baseUrl的生产环境路径一致,默认dist)
|
|
|
outputDir: 'dist',
|
|
|
- // 用于放置生成的静态资源 (js、css、img、fonts) 的;(项目打包之后,静态资源会放在这个文件夹下)
|
|
|
+ // 用于放置生成的静态资源(js、css、img、fonts)的目录(项目打包之后,静态资源会放在这个文件夹下)
|
|
|
assetsDir: 'static',
|
|
|
- // 是否开启eslint保存检测,有效值:ture | false | 'error'
|
|
|
lintOnSave: process.env.NODE_ENV === 'development',
|
|
|
- // 如果你不需要生产环境的 source map,可以将其设置为 false 以加速生产环境构建。
|
|
|
productionSourceMap: false,
|
|
|
// webpack-dev-server 相关配置
|
|
|
devServer: {
|
|
|
host: '0.0.0.0',
|
|
|
port: port,
|
|
|
open: true,
|
|
|
+
|
|
|
+ // 安全修复:使用环境变量替代硬编码IP
|
|
|
proxy: {
|
|
|
- // detail: https://cli.vuejs.org/config/#devserver-proxy
|
|
|
[process.env.VUE_APP_BASE_API]: {
|
|
|
- target: `http://60.204.184.98:8091`,
|
|
|
+ target: process.env.VUE_APP_PROXY_TARGET || 'http://localhost:8090',
|
|
|
changeOrigin: true,
|
|
|
pathRewrite: {
|
|
|
['^' + process.env.VUE_APP_BASE_API]: ''
|
|
|
}
|
|
|
}
|
|
|
},
|
|
|
- disableHostCheck: true
|
|
|
+
|
|
|
+ allowedHosts: [
|
|
|
+ 'localhost',
|
|
|
+ '127.0.0.1',
|
|
|
+ '.local' // 允许 .local 域名
|
|
|
+ // 如需添加其他域名,请在此处添加
|
|
|
+ ]
|
|
|
},
|
|
|
css: {
|
|
|
loaderOptions: {
|
|
|
@@ -63,21 +66,21 @@ module.exports = {
|
|
|
}
|
|
|
},
|
|
|
plugins: [
|
|
|
- // http://doc.jianke.vip/jianke-vue/other/faq.html#使用gzip解压缩静态文件
|
|
|
+ // 使用 gzip 解压缩静态文件
|
|
|
new CompressionPlugin({
|
|
|
cache: false, // 不启用文件缓存
|
|
|
test: /\.(js|css|html)?$/i, // 压缩文件格式
|
|
|
filename: '[path].gz[query]', // 压缩后的文件名
|
|
|
- algorithm: 'gzip', // 使用gzip压缩
|
|
|
- minRatio: 0.8 // 压缩率小于1才会压缩
|
|
|
+ algorithm: 'gzip', // 使用 gzip 压缩
|
|
|
+ minRatio: 0.8 // 压缩率小于 1 才会压缩
|
|
|
})
|
|
|
],
|
|
|
},
|
|
|
chainWebpack(config) {
|
|
|
- config.plugins.delete('preload') // TODO: need test
|
|
|
- config.plugins.delete('prefetch') // TODO: need test
|
|
|
+ config.plugins.delete('preload') // 删除预加载插件
|
|
|
+ config.plugins.delete('prefetch') // 删除预获取插件
|
|
|
|
|
|
- // set svg-sprite-loader
|
|
|
+ // 设置 svg-sprite-loader
|
|
|
config.module
|
|
|
.rule('svg')
|
|
|
.exclude.add(resolve('src/assets/icons'))
|
|
|
@@ -94,45 +97,52 @@ module.exports = {
|
|
|
})
|
|
|
.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()
|
|
|
+ // 安全修复:生产环境自动移除 console.log
|
|
|
+ config.when(process.env.NODE_ENV === 'production', config => {
|
|
|
+ // 移除 console 和 debugger
|
|
|
+ config.optimization.minimizer('terser').tap(args => {
|
|
|
+ Object.assign(args[0].terserOptions.compress, {
|
|
|
+ drop_console: true, // 移除所有 console
|
|
|
+ drop_debugger: true, // 移除 debugger
|
|
|
+ pure_funcs: ['console.log'] // 移除 console.log
|
|
|
+ })
|
|
|
+ return args
|
|
|
+ })
|
|
|
+
|
|
|
+ config
|
|
|
+ .plugin('ScriptExtHtmlWebpackPlugin')
|
|
|
+ .after('html')
|
|
|
+ .use('script-ext-html-webpack-plugin', [{
|
|
|
+ // runtime 必须与 runtimeChunk 名称相同,默认为 runtime
|
|
|
+ inline: /runtime\..*\.js$/
|
|
|
+ }])
|
|
|
+ .end()
|
|
|
|
|
|
- config.optimization.splitChunks({
|
|
|
+ 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
|
|
|
+ chunks: 'initial' // 仅打包初始依赖的第三方库
|
|
|
},
|
|
|
elementUI: {
|
|
|
- name: 'chunk-elementUI', // split elementUI into a single package
|
|
|
- test: /[\\/]node_modules[\\/]_?element-ui(.*)/, // in order to adapt to cnpm
|
|
|
- priority: 20 // the weight needs to be larger than libs and app or it will be packaged into libs or app
|
|
|
+ name: 'chunk-elementUI', // 将 elementUI 拆分成单独的包
|
|
|
+ test: /[\\/]node_modules[\\/]_?element-ui(.*)/, // 为了适配 cnpm
|
|
|
+ priority: 20 // 权重需要大于 libs 和 app,否则会被打包进 libs 或 app
|
|
|
},
|
|
|
commons: {
|
|
|
name: 'chunk-commons',
|
|
|
- test: resolve('src/components'), // can customize your rules
|
|
|
- minChunks: 3, // minimum common number
|
|
|
+ test: resolve('src/components'), // 可以自定义规则
|
|
|
+ minChunks: 3, // 最小公共数量
|
|
|
priority: 5,
|
|
|
- reuseExistingChunk: true
|
|
|
+ reuseExistingChunk: true // 重用已存在的块
|
|
|
}
|
|
|
}
|
|
|
})
|
|
|
|
|
|
- config.optimization.runtimeChunk('single'),
|
|
|
- {
|
|
|
- from: path.resolve(__dirname, './public/robots.txt'), //防爬虫文件
|
|
|
- to: './' //到根目录下
|
|
|
- }
|
|
|
+ config.optimization.runtimeChunk('single')
|
|
|
})
|
|
|
}
|
|
|
}
|