@@ -3,6 +3,7 @@ const VueFilenameInjector = require('@d2-projects/vue-filename-injector')
3
3
const ThemeColorReplacer = require ( 'webpack-theme-color-replacer' )
4
4
const forElementUI = require ( 'webpack-theme-color-replacer/forElementUI' )
5
5
const cdnDependencies = require ( './dependencies-cdn' )
6
+ const { chain, set, each } = require ( 'lodash' )
6
7
7
8
// 拼接路径
8
9
const resolve = dir => require ( 'path' ) . join ( __dirname , dir )
@@ -24,6 +25,13 @@ const cdn = {
24
25
js : cdnDependencies . map ( e => e . js ) . filter ( e => e )
25
26
}
26
27
28
+ // 多页配置,默认未开启,如需要请参考 https://cli.vuejs.org/zh/config/#pages
29
+ const pages = undefined
30
+ // const pages = {
31
+ // index: './src/main.js',
32
+ // subpage: './src/subpage.js'
33
+ // }
34
+
27
35
module . exports = {
28
36
// 根据你的实际情况更改这里
29
37
publicPath,
@@ -40,6 +48,7 @@ module.exports = {
40
48
}
41
49
}
42
50
} ,
51
+ pages,
43
52
configureWebpack : config => {
44
53
const configNew = { }
45
54
if ( process . env . NODE_ENV === 'production' ) {
@@ -61,15 +70,17 @@ module.exports = {
61
70
chainWebpack : config => {
62
71
/**
63
72
* 添加 CDN 参数到 htmlWebpackPlugin 配置中
73
+ * 已适配多页
64
74
*/
65
- config . plugin ( 'html' ) . tap ( args => {
66
- if ( process . env . NODE_ENV === 'production' ) {
67
- args [ 0 ] . cdn = cdn
68
- } else {
69
- args [ 0 ] . cdn = [ ]
70
- }
71
- return args
75
+ const htmlPluginNames = chain ( pages ) . keys ( ) . map ( page => 'html-' + page ) . value ( )
76
+ const targetHtmlPluginNames = htmlPluginNames . length ? htmlPluginNames : [ 'html' ]
77
+ each ( targetHtmlPluginNames , name => {
78
+ config . plugin ( name ) . tap ( options => {
79
+ set ( options , ' [0].cdn' , process . env . NODE_ENV === 'production' ? cdn : [ ] )
80
+ return options
81
+ } )
72
82
} )
83
+
73
84
/**
74
85
* 删除懒加载模块的 prefetch preload,降低带宽压力
75
86
* https://cli.vuejs.org/zh/guide/html-and-static-assets.html#prefetch
0 commit comments