1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
const { defineConfig } = require('@vue/cli-service')
// js压缩插件
const TerserPlugin = require('terser-webpack-plugin')
// 动态引入vant组件
const { VantResolver } = require('@vant/auto-import-resolver')
const AutoImport = require('unplugin-auto-import/webpack')
const Components = require('unplugin-vue-components/webpack')
const path = require('path')
function resolve(dir) {
return path.join(__dirname, dir)
}
module.exports = defineConfig({
transpileDependencies: true,
indexPath: 'index.html',
publicPath: '/', // 设置打包文件相对路径
outputDir: 'dist',
productionSourceMap: false,
devServer: {
port: 8085,
// 设置代理
proxy: {
'/tumour-admin': {
// target: 'http://192.168.1.7:8081',
target: 'https://beta-tumour.zmnyjk.com',
changOrigin: true,
pathRewrite: {
'^/tumour-admin': '/tumour-admin'
}
},
'/chronic-admin': {
target: 'https://beta-tumour.zmnyjk.com',
// target: 'http://192.168.1.216:8900',
changOrigin: true,
pathRewrite: {
// '^/chronic-admin': '/'
'^/chronic-admin': '/chronic-admin'
}
},
'/chronic-resident': {
// target: 'http://192.168.1.142:8903',
target: 'https://beta-tumour.zmnyjk.com',
changOrigin: true,
pathRewrite: {
// '^/chronic-resident': '/',
'^/chronic-resident': '/chronic-resident'
}
}
},
},
chainWebpack: config => {
// 自定义svg图标设置
// 原svg规则排除 src/assets/icon 文件夹
config.module.rule('svg').exclude.add(resolve('src/assets/icons')).end()
// 新增svg加载规则
config.module
.rule('icon')
.test(/\.svg$/)
.include.add(resolve('src/assets/icons'))
.end()
.use('svg-sprite-loader')
.loader('svg-sprite-loader') // 加载解析svg 拼接为雪碧图
.options({
symbolId: 'icon-[name]'
})
.end()
config.plugins.delete('preload')
// 移除 prefetch 插件
config.plugins.delete('prefetch')
// 打包切分css
if (process.env.NODE_ENV === 'production') {
config.plugin('extract-css').tap(args => {
args[0].filename = `css/[name].[contenthash:8].css`
return args
})
}
// 浏览器页签标题
config.plugin('html').tap(args => {
args[0].title = '啄木鸟云健康'
return args
})
// https://cn.vuejs.org/api/compile-time-flag
config.plugin('define').tap((definitions) => {
Object.assign(definitions[0], {
__VUE_OPTIONS_API__: 'true',
__VUE_PROD_DEVTOOLS__: 'false',
__VUE_PROD_HYDRATION_MISMATCH_DETAILS__: 'false'
})
return definitions
})
},
configureWebpack: config => {
// 输出重构 打包编译后的 文件名称 【版本号】
config.output.filename = `js/[name].[chunkhash:8].js`
config.output.chunkFilename = `js/[name].[chunkhash:8].js`
// 压缩js
config.optimization.minimizer.unshift(
new TerserPlugin({
// 启用多线程
parallel: 4,
terserOptions: {
// 构建时去除注释
format: {
comments: false
},
compress: {
// 不调用console.*
drop_console: true,
// 移除debugger
drop_debugger: true,
// 移除console.log
// pure_funcs: ['console.log']
},
},
// 是否将注释剥离到单独的文件中
extractComments: false
})
)
config.plugins.push(
AutoImport.default({ resolvers: [VantResolver()] })
)
config.plugins.push(
Components.default({ resolvers: [VantResolver()] })
)
},
css: {
loaderOptions: {
less: {
lessOptions: {
// 允许less文件中运行js
javascriptEnabled: true
}
}
}
}
})