1
1
'use strict'
2
- require ( '@babel/register' )
3
2
const path = require ( 'path' )
4
- const bodyParser = require ( 'body-parser' )
5
3
6
4
function resolve ( dir ) {
7
5
return path . join ( __dirname , dir )
8
6
}
9
7
8
+ const port = 9527 // TODO: change to Settings
9
+
10
+ // Explanation of each configuration item You can find it in https://cli.vuejs.org/config/
10
11
module . exports = {
12
+ /**
13
+ * You can set by yourself according to actual condition
14
+ * You will need to set this if you plan to deploy your site under a sub path,
15
+ * for example GitHub pages. If you plan to deploy your site to https://foo.github.io/bar/,
16
+ * then assetsPublicPath should be set to "/bar/".
17
+ * In most cases please use '/' !!!
18
+ * Detail https://cli.vuejs.org/config/#baseurl
19
+ */
20
+ baseUrl : '/' ,
21
+ outputDir : 'dist' ,
22
+ assetsDir : 'static' ,
23
+ lintOnSave : process . env . NODE_ENV !== 'production' ,
24
+ productionSourceMap : false ,
11
25
devServer : {
26
+ port : port ,
12
27
open : true ,
28
+ overlay : {
29
+ warnings : false ,
30
+ errors : true
31
+ } ,
13
32
proxy : {
14
33
'/api' : {
15
- target : ' http://localhost:8080 /mock' ,
34
+ target : ` http://localhost:${ port } /mock` ,
16
35
changeOrigin : true ,
17
36
pathRewrite : {
18
37
'^/api' : ''
19
38
}
20
39
}
21
40
} ,
22
41
after ( app ) {
42
+ console . log ( 'apple' )
43
+ const bodyParser = require ( 'body-parser' )
44
+ require ( '@babel/register' )
23
45
// parse app.body
24
46
// http://expressjs.com/en/4x/api.html#req.body
25
47
app . use ( bodyParser . json ( ) )
@@ -33,28 +55,74 @@ module.exports = {
33
55
}
34
56
} ,
35
57
configureWebpack : {
58
+ // We provide the app's title in Webpack's name field, so that
59
+ // it can be accessed in index.html to inject the correct title.
60
+ name : 'vue-element-admin' , // TODO: change to Settings
36
61
resolve : {
37
62
alias : {
38
- '$ @' : resolve ( 'src/components ' )
63
+ '@' : resolve ( 'src' )
39
64
}
40
- } ,
41
- module : {
42
- rules : [
43
- {
44
- test : / \. s v g $ / ,
45
- loader : 'svg-sprite-loader' ,
46
- include : [ resolve ( 'src/icons' ) ] ,
47
- options : {
48
- symbolId : 'icon-[name]'
49
- }
50
- }
51
- ]
52
65
}
53
66
} ,
54
67
chainWebpack ( config ) {
68
+ config . plugins . delete ( 'preload' ) // TODO: need test
69
+ config . plugins . delete ( 'prefetch' ) // TODO: need test
55
70
config . module
56
71
. rule ( 'svg' )
57
72
. exclude . add ( resolve ( 'src/icons' ) )
58
73
. end ( )
74
+ config . module
75
+ . rule ( 'icons' )
76
+ . test ( / \. s v g $ / )
77
+ . include . add ( resolve ( 'src/icons' ) )
78
+ . end ( )
79
+ . use ( 'svg-sprite-loader' )
80
+ . loader ( 'svg-sprite-loader' )
81
+ . options ( {
82
+ symbolId : 'icon-[name]'
83
+ } )
84
+ . end ( )
85
+
86
+ config
87
+ . when ( process . env . NODE_ENV === 'development' ,
88
+ config => config . devtool ( 'cheap-source-map' )
89
+ )
90
+
91
+ config
92
+ . when ( process . env . NODE_ENV !== 'development' ,
93
+ config => {
94
+ config
95
+ . plugin ( 'ScriptExtHtmlWebpackPlugin' )
96
+ . use ( 'script-ext-html-webpack-plugin' , [ {
97
+ // `runtime` must same as runtimeChunk name. default is `runtime`
98
+ inline : / r u n t i m e \. .* \. j s $ /
99
+ } ] )
100
+ config
101
+ . optimization . splitChunks ( {
102
+ chunks : 'all' ,
103
+ cacheGroups : {
104
+ libs : {
105
+ name : 'chunk-libs' ,
106
+ test : / [ \\ / ] n o d e _ m o d u l e s [ \\ / ] / ,
107
+ priority : 10 ,
108
+ chunks : 'initial' // 只打包初始时依赖的第三方
109
+ } ,
110
+ elementUI : {
111
+ name : 'chunk-elementUI' , // 单独将 elementUI 拆包
112
+ priority : 20 , // 权重要大于 libs 和 app 不然会被打包进 libs 或者 app
113
+ test : / [ \\ / ] n o d e _ m o d u l e s [ \\ / ] e l e m e n t - u i [ \\ / ] /
114
+ } ,
115
+ commons : {
116
+ name : 'chunk-commons' ,
117
+ test : resolve ( 'src/components' ) , // 可自定义拓展你的规则
118
+ minChunks : 3 , // 最小公用次数
119
+ priority : 5 ,
120
+ reuseExistingChunk : true
121
+ }
122
+ }
123
+ } )
124
+ config . optimization . runtimeChunk ( 'single' )
125
+ }
126
+ )
59
127
}
60
128
}
0 commit comments