-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathvue.config.js
99 lines (91 loc) · 2.29 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
const CleanWebpackPlugin = require('clean-webpack-plugin')
const CopyWebpackPlugin = require('copy-webpack-plugin')
const generateLoadingScript = require('./generate-loading-script')
const path = require('path')
const webpack = require('webpack')
const { toPairs, forEach } = require('lodash')
const svgIconPath = path.resolve('./src/assets/icons')
const info = generateLoadingScript()
process.env.VUE_APP_LOADING_SCRIPT_URL = `/js/${info.basename}`
const vendors = {
vue: 'vue|vue-router|vuex',
utils: 'marked|highlight.js',
apisauce: 'apisauce|axios',
jparticles: 'jparticles',
gitalk: 'gitalk',
}
const cacheGroups = {}
forEach(toPairs(vendors), ([key, value]) => {
cacheGroups[key] = {
test: new RegExp(`[\\/]node_modules[\\/](${value})[\\/]`),
name: key,
}
})
const config = {
outputDir: 'docs',
productionSourceMap: false,
lintOnSave: true,
css: {
extract: true,
sourceMap: process.env.NODE_ENV !== 'production',
loaderOptions: {
sass: {
data: `@import "@/assets/styles/_mixins.scss";`,
},
},
},
devServer: {
port: 8000,
disableHostCheck: true,
},
configureWebpack: {
optimization: {
runtimeChunk: 'single',
splitChunks: {
chunks: 'all',
maxInitialRequests: Infinity,
cacheGroups,
},
},
plugins: [
new webpack.HashedModuleIdsPlugin(),
new CopyWebpackPlugin([{ from: info.filePath, to: './js' }]),
],
module: {
rules: [
{
include: [svgIconPath],
test: /\.svg$/,
use: [
{ loader: 'raw-loader' },
{
loader: 'svgo-loader',
options: {
plugins: [
{ removeTitle: true },
{ removeViewBox: false },
{ removeDimensions: true },
],
},
},
],
},
],
},
},
chainWebpack: config => {
config.module
.rule('svg')
.exclude.add(svgIconPath)
.end()
},
}
if (process.env.NODE_ENV === 'production') {
config.configureWebpack.plugins.push(
new CleanWebpackPlugin({
cleanOnceBeforeBuildPatterns: ['**/*', '!CNAME', `!${info.basename}`],
cleanAfterEveryBuildPatterns: ['loading*.js'],
})
)
}
module.exports = config