-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvue.config.js
166 lines (161 loc) · 4.86 KB
/
vue.config.js
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
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
const { defineConfig } = require('@vue/cli-service')
const path = require('path')
const isStaging = !!process.env.VUE_APP_STAGINE
const NODE_ENV = process.env.NODE_ENV
const isProduction = NODE_ENV === 'production'
const CompressionWebpackPlugin = require('compression-webpack-plugin')
const SpeedMeasurePlugin = require('speed-measure-webpack-plugin')
const { BundleAnalyzerPlugin } = require('webpack-bundle-analyzer')
const { IgnorePlugin } = require('webpack')
const mode = process.VUE_CLI_SERVICE.mode
module.exports = defineConfig({
parallel: true,
publicPath: isProduction && !isStaging ? '/' : '/',
transpileDependencies: true,
productionSourceMap: false,
chainWebpack: (config) => {
const jsRule = config.module.rule('js')
// // 清理自带的 babel-loader
jsRule.uses.clear()
// 添加 esbuild-loader
jsRule
.use('esbuild-loader')
.loader('esbuild-loader')
.options({
loader: 'ts', // 如果使用了 ts, 或者 vue 的 class 装饰器,则需要加上这个 option 配置, 否则会报错: ERROR: Unexpected "@"
target: 'esnext',
...(isProduction && {
minify: true,
minifyWhitespace: true,
minifyIdentifiers: true,
minifySyntax: true,
treeShaking: true,
}),
tsconfigRaw: require('./tsconfig.json'),
})
if (isProduction) {
config.plugin('html').tap((args) => {
return [
{
...args[0],
ignoreOrder: true,
},
]
})
}
// 用cdn方式引入
config.plugins.delete('prefetch')
config.plugins.delete('preload')
config.externals({
// vue: 'Vue',
// 'vue-router': 'VueRouter',
// vuex: 'Vuex',
// axios: 'axios',
// vuedraggable: 'vuedraggable',
// cropperjs: 'Cropper',
// 'ant-design-vue': 'antd',
})
config.plugin('html').tap((args) => {
args[0].title = '分享乐'
args[0].desc = '一键生成海报'
return args
})
},
configureWebpack: (config) => {
config.entry = './src/main.ts'
config.performance = {
hints: false,
//入口起点的最大体积
maxEntrypointSize: 300 * 1024 * 1024,
//生成文件的最大体积
maxAssetSize: 300 * 1024 * 1024,
//只给出 js 文件的性能提示
assetFilter: function (assetFilename) {
return assetFilename.endsWith('.js')
},
}
config.cache = {
// 将缓存类型设置为文件系统
type: 'filesystem',
buildDependencies: {
/* 将你的 config 添加为 buildDependency,以便在改变 config 时获得缓存无效*/
config: [__filename],
/* 如果有其他的东西被构建依赖,你可以在这里添加它们*/
/* 注意,webpack.config,加载器和所有从你的配置中引用的模块都会被自动添加*/
},
// cacheDirectory: path.resolve(__dirname, './node_modules/.cache_temp'),
// name: 'share-craft',
cacheLocation: path.resolve(
__dirname,
'./node_modules/.cache_temp',
'share-craft'
),
// 指定缓存的版本
version: '1.0',
}
config.plugins.push(
new IgnorePlugin({
resourceRegExp: /^\.\/locale$/,
contextRegExp: /dayjs$/,
})
)
config.optimization.splitChunks = {
maxInitialRequests: Infinity,
chunks: 'all',
minSize: 50 * 1024,
name: 'common',
cacheGroups: {
antVendor: {
name: 'chunk-antd',
test: /[\\/]ant-design-vue/,
priority: 10,
},
antIconVendor: {
name: 'chunk-ant-icon',
test: /[\\/]@ant-design/,
priority: 10,
},
lodash: {
name: 'chunk-lodash',
test: /[\\/]lodash-es/,
minSize: 30 * 1024,
priority: -5,
},
vuedraggable: {
name: 'chunk-vuedraggable',
test: /[\\/]vuedraggable/,
minSize: 30 * 1024,
priority: -5,
},
},
}
if (isProduction) {
// 长效缓存
config.optimization.moduleIds = 'named'
config.optimization.chunkIds = 'named'
config.plugins.push(
new CompressionWebpackPlugin({
algorithm: 'gzip',
test: /\.js$|\.html$|\.json$|\.css/,
threshold: 1024 * 10,
})
)
}
if (mode === 'analyze') {
config.plugins = config.plugins.concat([
new BundleAnalyzerPlugin({
// 生成静态文件
analyzerMode: 'static',
}),
new SpeedMeasurePlugin(),
])
}
},
devServer: {
proxy: {
'/api': {
target: process.env.VUE_APP_BASE_URL_PROXY,
},
},
},
})