goindex-theme-r/vue.config.js

70 lines
1.7 KiB
JavaScript
Raw Normal View History

2020-04-28 02:16:41 +08:00
const path = require("path");
2020-04-28 19:02:48 +08:00
const cdnDependencies = require('./dependencies-cdn')
2020-04-24 19:43:00 +08:00
2020-04-28 02:16:41 +08:00
function resolve(dir) {
return path.join(__dirname, dir);
2020-04-24 19:43:00 +08:00
}
2020-04-28 19:02:48 +08:00
// 基础路径 注意发布之前要先修改这里
let publicPath = process.env.VUE_APP_PUBLIC_PATH || '/'
// 设置不参与构建的库
let externals = {}
cdnDependencies.forEach(item => { externals[item.name] = item.library })
// 引入文件的 cdn 链接
const cdn = {
css: cdnDependencies.map(e => e.css).filter(e => e),
js: cdnDependencies.map(e => e.js).filter(e => e)
}
2020-04-24 19:43:00 +08:00
module.exports = {
2020-04-28 19:02:48 +08:00
publicPath,
2020-04-28 02:16:41 +08:00
lintOnSave: true,
2020-04-28 19:02:48 +08:00
configureWebpack: config => {
const configNew = {}
if (process.env.NODE_ENV === 'production') {
configNew.externals = externals
}
return configNew
},
2020-04-28 02:16:41 +08:00
chainWebpack: (config) => {
2020-04-28 19:02:48 +08:00
/**
* 添加 CDN 参数到 htmlWebpackPlugin 配置中
*/
config.plugin('html').tap(args => {
if (process.env.NODE_ENV === 'production') {
args[0].cdn = cdn
} else {
args[0].cdn = []
}
return args
})
2020-04-28 02:16:41 +08:00
config.resolve.alias
.set("@", resolve("src"))
.set("@assets", resolve("src/assets"))
.set("@utils", resolve("src/utils"))
.set("@node_modules", resolve("node_modules"));
2020-04-28 19:02:48 +08:00
// 分析工具
if (process.env.npm_config_report) {
config
.plugin('webpack-bundle-analyzer')
.use(require('webpack-bundle-analyzer').BundleAnalyzerPlugin)
}
2020-04-28 02:16:41 +08:00
},
2020-04-28 19:02:48 +08:00
// 不输出 map 文件
productionSourceMap: false,
2020-04-28 02:16:41 +08:00
devServer: {
2020-04-28 19:02:48 +08:00
publicPath,
2020-04-28 02:16:41 +08:00
proxy: {
"/api": {
target: "https://ossdev.achirou.workers.dev/",
ws: true,
changeOrigin: true,
pathRewrite: {
"^/api": "",
},
},
2020-04-24 19:43:00 +08:00
},
2020-04-28 02:16:41 +08:00
},
2020-04-29 09:45:06 +08:00
};