-
Notifications
You must be signed in to change notification settings - Fork 357
/
vue.config.js
158 lines (140 loc) · 5.21 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
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
/** @format */
const path = require('path')
const SizePlugin = require('size-plugin')
const isProductionEnvFlag = process.env.NODE_ENV === 'production'
function resolveRealPath(dir) {
return path.join(__dirname, dir)
}
// https://github.com/vuejs/vue-docs-zh-cn/blob/master/vue-cli/config.md
module.exports = {
// Project deployment base
// By default we assume your app will be deployed at the root of a domain,
// e.g. https://www.my-app.com/
// If your app is deployed at a sub-path, you will need to specify that
// sub-path here. For example, if your app is deployed at
// https://www.foobar.com/my-app/
// then change this to '/my-app/'
publicPath: '/',
// where to output built files
outputDir: 'dist',
// whether to use eslint-loader for lint on save.
// valid values: true | false | 'error'
// when set to 'error', lint errors will cause compilation to fail.
lintOnSave: true,
// https://cli.vuejs.org/config/#runtimecompiler
runtimeCompiler: false,
// babel-loader skips `node_modules` deps by default.
// explicitly transpile a dependency with this option.
transpileDependencies: [
/* string or regex */
],
// generate sourceMap for production build?
productionSourceMap: process.env.NODE_ENV !== 'production',
// tweak internal webpack configuration.
// see https://github.com/vuejs/vue-cli/blob/dev/docs/webpack.md
chainWebpack: (config) => {
config.resolve.alias
.set('vue$', 'vue/dist/vue.esm.js')
.set('@helper', resolveRealPath('src/helper'))
.set('@config', resolveRealPath('src/config'))
.set('@pages', resolveRealPath('src/pages'))
.set('@assets', resolveRealPath('src/assets'))
.set('@router', resolveRealPath('src/router'))
.set('@mixins', resolveRealPath('src/mixins'))
.set('@components', resolveRealPath('src/components'))
// remove the old loader & add new one
config.module.rules.delete('svg')
config.module
.rule('svg')
.test(/\.svg$/)
.use('svg-sprite-loader')
.loader('svg-sprite-loader')
.options({
name: '[name]-[hash:7]',
prefixize: true,
})
const splitOptions = config.optimization.get('splitChunks')
config.optimization.splitChunks(
Object.assign({}, splitOptions, {
// (缺省值5)按需加载时的最大并行请求数
maxAsyncRequests: 16,
// (默认值3)入口点上的最大并行请求数
maxInitialRequests: 16,
// (默认值:1)分割前共享模块的最小块数
minChunks: 1,
// (默认值:30000)块的最小大小
minSize: 30000,
// webpack 将使用块的起源和名称来生成名称: `vendors~main.js`,如项目与"~"冲突,则可通过此值修改,Eg: '-'
automaticNameDelimiter: '~',
// cacheGroups is an object where keys are the cache group names.
name: true,
cacheGroups: {
default: false,
common: {
name: `chunk-common`,
minChunks: 2,
priority: -20,
chunks: 'initial',
reuseExistingChunk: true,
},
element: {
name: 'element',
test: /[\\/]node_modules[\\/]element-ui[\\/]/,
chunks: 'initial',
// 默认组的优先级为负数,以允许任何自定义缓存组具有更高的优先级(默认值为0)
priority: -30,
},
},
})
)
// https://github.com/webpack-contrib/webpack-bundle-analyzer
if (process.env.npm_config_report) {
config
.plugin('webpack-bundle-analyzer')
.use(require('webpack-bundle-analyzer').BundleAnalyzerPlugin)
}
},
configureWebpack: {
plugins: [isProductionEnvFlag ? new SizePlugin() : () => {}],
},
// use thread-loader for babel & TS in production build
// enabled by default if the machine has more than 1 cores
parallel: require('os').cpus().length > 1,
// options for the PWA plugin.
// see => https://github.com/vuejs/vue-cli/tree/dev/packages/%40vue/cli-plugin-pwa
// https://developers.google.com/web/tools/workbox/modules/workbox-webpack-plugin
pwa: {
name: 'Arya - 在线 Markdown 编辑器',
themeColor: '#4DBA87',
msTileColor: '#000000',
appleMobileWebAppCapable: 'yes',
appleMobileWebAppStatusBarStyle: 'black',
iconPaths: {
favicon32: 'img/icons/favicon-32x32.png',
favicon16: 'img/icons/favicon-16x16.png',
appleTouchIcon: 'img/icons/apple-touch-icon.png',
maskIcon: 'img/icons/safari-pinned-tab.svg',
msTileImage: 'img/icons/mstile-150x150.png',
},
// configure the workbox plugin (GenerateSW or InjectManifest)
workboxPluginMode: 'InjectManifest',
workboxOptions: {
// swSrc is required in InjectManifest mode.
swSrc: 'public/service-worker.js',
// ...other Workbox options...
},
},
// configure webpack-dev-server behavior
devServer: {
open: process.platform === 'darwin',
host: '0.0.0.0',
port: 8080,
https: false,
hotOnly: false,
// See https://github.com/vuejs/vue-cli/blob/dev/docs/cli-service.md#configuring-proxy
proxy: null, // string | Object
before: () => {},
},
// options for 3rd party plugins
pluginOptions: {},
}