-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathvue.config.js
More file actions
69 lines (67 loc) · 2.24 KB
/
vue.config.js
File metadata and controls
69 lines (67 loc) · 2.24 KB
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
const { defineConfig } = require('@vue/cli-service')
// 需要排除的包对象
let externals = {}
let CDN = { css: [], js: [] }
// 判断是否是生产环境
const isProduction = process.env.NODE_ENV === 'production'
// 如何是生产环境,需要执行以下逻辑
if (isProduction) {
externals = {
/**
* externals 对象属性解析:
* '包名': '在项目中引入的名字'
* 以 element-ui 举例 我再 main.js 里是以
* import ELEMENT from 'element-ui'
* Vue.use(ELEMENT)
* 这样引入的,所以我的 externals 的属性值应该是 ELEMENT
* 一定要去main.js设置
*/
echarts: 'echarts',
vue: 'Vue',
'vue-router': 'VueRouter',
vuex: 'Vuex',
axios: 'axios',
dayjs: 'dayjs',
'element-ui': 'ELEMENT',
'vue-quill-editor': 'VueQuillEditor',
'vuex-persistedstate': 'createPersistedState'
}
CDN = {
css: [
'https://unpkg.com/element-ui@2.15.9/lib/theme-chalk/index.css',
'https://unpkg.com/quill@1.3.7/dist/quill.core.css',
'https://unpkg.com/quill@1.3.7/dist/quill.snow.css',
'https://unpkg.com/quill@1.3.7/dist/quill.bubble.css'
// ……
],
js: [
// vue must at first!
'https://unpkg.com/echarts@5.3.3/dist/echarts.min.js',
'https://unpkg.com/vue@2.6.14/dist/vue.js',
'https://unpkg.com/vue-router@3.5.1/dist/vue-router.js',
'https://unpkg.com/vuex@3.6.2/dist/vuex.js',
'https://unpkg.com/axios@0.27.2/dist/axios.min.js',
'https://unpkg.com/dayjs@1.11.3/dayjs.min.js',
'https://unpkg.com/element-ui@2.15.8/lib/index.js',
'https://unpkg.com/quill@1.3.7/dist/quill.js',
'https://unpkg.com/vue-quill-editor@3.0.6/dist/vue-quill-editor.js',
'https://unpkg.com/vuex-persistedstate@3.2.1/dist/vuex-persistedstate.umd.js'
// ……
]
}
}
module.exports = defineConfig({
transpileDependencies: true,
publicPath: process.env.NODE_ENV === 'production' ? './' : '/',
configureWebpack: {
// provide the app's title in webpack's name field, so that
// it can be accessed in index.html to inject the correct title.
externals: externals
},
chainWebpack(config) {
config.plugin('html').tap(args => {
args[0].cdn = CDN
return args
})
}
})