generated from ui-javascript/tpl-mpa-vuecli3-vue2
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvue.config.js
142 lines (120 loc) · 3.36 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
const path = require("path")
// 构建工具类
const utils = require("./utils")
// 配置
const CONFIG = require("./config")
// 几个辅助函数
function resolve(dir) {
return path.join(__dirname, dir)
}
const isEnvProd = (process.env.NODE_ENV === 'production')
const isEnvDev = (process.env.NODE_ENV === 'development')
const currentOutsidePath = CONFIG.entry.split('/')[1];
console.log('-------当前工程最外层目录-------')
console.log(currentOutsidePath)
// 获取多页面信息
let pages = utils.getEntry(CONFIG.entry)
// 给html添加参数, 用于生成多页面路径的导航
// @fix 2019-11-16 pages是对象类型 不是数组 改为Object.keys().length
const entries = pages.entries
if (!isEnvProd && Object.keys(entries).length > 1 && CONFIG.showNav) {
for (let index in entries) {
Object.assign(entries[index], {
_browserPage: pages.browserPages,
})
}
}
module.exports = {
// 基本配置
// 1) / 绝对路径
// 2) ./ 相对路径
publicPath: './',
outputDir: 'docs',
assetsDir: 'static',
lintOnSave: isEnvDev,
// 设为false打包时不生成.map文件
productionSourceMap: false,
devServer: {
disableHostCheck: true,
port: CONFIG.port,
// open: true,
overlay: {
warnings: false,
errors: true
},
// vue-element-admin的mock环境 =============
proxy: {
// change xxx-api/login => mock/login
// detail: https://cli.vuejs.org/config/#devserver-proxy
[process.env.VUE_APP_BASE_API]: {
target: `http://127.0.0.1:${CONFIG.port}/mock`,
changeOrigin: true,
pathRewrite: {
['^' + process.env.VUE_APP_BASE_API]: ''
}
}
},
after: require('./mock/mock-server.js')
},
css: {
loaderOptions: {
less: {
modifyVars: {
// less vars,customize ant design theme
// 'primary-color': '#F5222D',
// 'link-color': '#F5222D',
// 'border-radius-base': '4px'
},
// do not remove this line
javascriptEnabled: true
}
}
},
// 全局样式
pluginOptions: {
'style-resources-loader': {
preProcessor: 'scss',
// patterns: [
// path.resolve(__dirname, 'src/styles/_variables.scss'),
// path.resolve(__dirname, 'src/styles/_mixins.scss')
// ]
}
},
// vue-cli 多页面
pages: entries,
configureWebpack: {
// plugins: [],
resolve: {
alias: {
'@': resolve('src'),
// @TODO 目前这个变量仅仅给vue-element-admin使用
// --> 所以src内使用到^/store的地方代码都有耦合
// 当前项目最外层路径
'^': resolve(currentOutsidePath || 'src'),
// @fix runtime -> compiler模式
// https://blog.csdn.net/wxl1555/article/details/83187647
'vue$': 'vue/dist/vue.esm.js'
}
}
},
chainWebpack: config => {
// TODO: need test
config.plugins.delete('preload')
// TODO: need test
config.plugins.delete('prefetch')
// set svg-sprite-loader
config.module
.rule('vue')
.use('vue-loader')
.loader('vue-loader')
.tap(options => {
options.compilerOptions.preserveWhitespace = true
return options;
});
// 开发环境 cheap-source-map
config
.when(isEnvDev,
config => config.devtool('cheap-source-map')
)
},
}