fix: 修复多页面 cdn 引用
This commit is contained in:
@@ -3,6 +3,7 @@ const VueFilenameInjector = require('@d2-projects/vue-filename-injector')
|
|||||||
const ThemeColorReplacer = require('webpack-theme-color-replacer')
|
const ThemeColorReplacer = require('webpack-theme-color-replacer')
|
||||||
const forElementUI = require('webpack-theme-color-replacer/forElementUI')
|
const forElementUI = require('webpack-theme-color-replacer/forElementUI')
|
||||||
const cdnDependencies = require('./dependencies-cdn')
|
const cdnDependencies = require('./dependencies-cdn')
|
||||||
|
const { chain, set, each } = require('lodash')
|
||||||
|
|
||||||
// 拼接路径
|
// 拼接路径
|
||||||
const resolve = dir => require('path').join(__dirname, dir)
|
const resolve = dir => require('path').join(__dirname, dir)
|
||||||
@@ -24,6 +25,13 @@ const cdn = {
|
|||||||
js: cdnDependencies.map(e => e.js).filter(e => e)
|
js: cdnDependencies.map(e => e.js).filter(e => e)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 多页配置,默认未开启,如需要请参考 https://cli.vuejs.org/zh/config/#pages
|
||||||
|
const pages = undefined
|
||||||
|
// const pages = {
|
||||||
|
// index: './src/main.js',
|
||||||
|
// subpage: './src/subpage.js'
|
||||||
|
// }
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
// 根据你的实际情况更改这里
|
// 根据你的实际情况更改这里
|
||||||
publicPath,
|
publicPath,
|
||||||
@@ -40,6 +48,7 @@ module.exports = {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
pages,
|
||||||
configureWebpack: config => {
|
configureWebpack: config => {
|
||||||
const configNew = {}
|
const configNew = {}
|
||||||
if (process.env.NODE_ENV === 'production') {
|
if (process.env.NODE_ENV === 'production') {
|
||||||
@@ -61,15 +70,17 @@ module.exports = {
|
|||||||
chainWebpack: config => {
|
chainWebpack: config => {
|
||||||
/**
|
/**
|
||||||
* 添加 CDN 参数到 htmlWebpackPlugin 配置中
|
* 添加 CDN 参数到 htmlWebpackPlugin 配置中
|
||||||
|
* 已适配多页
|
||||||
*/
|
*/
|
||||||
config.plugin('html').tap(args => {
|
const htmlPluginNames = chain(pages).keys().map(page => 'html-' + page).value()
|
||||||
if (process.env.NODE_ENV === 'production') {
|
const targetHtmlPluginNames = htmlPluginNames.length ? htmlPluginNames : ['html']
|
||||||
args[0].cdn = cdn
|
each(targetHtmlPluginNames, name => {
|
||||||
} else {
|
config.plugin(name).tap(options => {
|
||||||
args[0].cdn = []
|
set(options, '[0].cdn', process.env.NODE_ENV === 'production' ? cdn : [])
|
||||||
}
|
return options
|
||||||
return args
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 删除懒加载模块的 prefetch preload,降低带宽压力
|
* 删除懒加载模块的 prefetch preload,降低带宽压力
|
||||||
* https://cli.vuejs.org/zh/guide/html-and-static-assets.html#prefetch
|
* https://cli.vuejs.org/zh/guide/html-and-static-assets.html#prefetch
|
||||||
|
|||||||
Reference in New Issue
Block a user