提交 | 用户 | age
|
2a61f6
|
1 |
'use strict' |
L |
2 |
const path = require('path') |
|
3 |
const defaultSettings = require('./src/settings.js') |
|
4 |
|
|
5 |
function resolve(dir) { |
|
6 |
return path.join(__dirname, dir) |
|
7 |
} |
|
8 |
|
|
9 |
const name = defaultSettings.title || 'vue Admin Template' // page title |
|
10 |
|
|
11 |
// If your port is set to 80, |
|
12 |
// use administrator privileges to execute the command line. |
|
13 |
// For example, Mac: sudo npm run |
|
14 |
// You can change the port by the following methods: |
|
15 |
// port = 9528 npm run dev OR npm run dev --port = 9528 |
|
16 |
const port = process.env.port || process.env.npm_config_port || 9528 // dev port |
|
17 |
|
|
18 |
// All configuration item explanations can be find in https://cli.vuejs.org/config/ |
|
19 |
module.exports = { |
|
20 |
/** |
|
21 |
* You will need to set publicPath if you plan to deploy your site under a sub path, |
|
22 |
* for example GitHub Pages. If you plan to deploy your site to https://foo.github.io/bar/, |
|
23 |
* then publicPath should be set to "/bar/". |
|
24 |
* In most cases please use '/' !!! |
|
25 |
* Detail: https://cli.vuejs.org/config/#publicpath |
|
26 |
*/ |
|
27 |
publicPath: './', |
|
28 |
outputDir: 'dist', |
|
29 |
assetsDir: 'static', |
|
30 |
lintOnSave: process.env.NODE_ENV === 'development', |
|
31 |
productionSourceMap: false, |
|
32 |
devServer: { |
|
33 |
proxy: { |
|
34 |
'/api_test': { |
|
35 |
target: 'http://192.168.31.22:8080/', |
|
36 |
// target: 'http://192.168.1.163:8080/', |
|
37 |
// target: 'http://192.168.31.143:8080/', // 和 |
|
38 |
// target: 'http://192.168.31.143:8888/', // 和 |
|
39 |
changeOrigin: true, |
|
40 |
ws: true, |
|
41 |
pathRewrite: { |
|
42 |
'^/api_test': '' |
|
43 |
} |
|
44 |
}, |
|
45 |
'/api_online': { |
|
46 |
target: 'https://线上请求路径/', |
|
47 |
changeOrigin: true, |
|
48 |
ws: true, |
|
49 |
pathRewrite: { |
|
50 |
'^/api_online': '' |
|
51 |
} |
|
52 |
} |
|
53 |
} |
|
54 |
}, |
|
55 |
configureWebpack: { |
|
56 |
// provide the app's title in webpack's name field, so that |
|
57 |
// it can be accessed in index.html to inject the correct title. |
|
58 |
name: name, |
|
59 |
resolve: { |
|
60 |
alias: { |
|
61 |
'@': resolve('src') |
|
62 |
} |
|
63 |
} |
|
64 |
}, |
|
65 |
chainWebpack(config) { |
|
66 |
// it can improve the speed of the first screen, it is recommended to turn on preload |
|
67 |
config.plugin('preload').tap(() => [ |
|
68 |
{ |
|
69 |
rel: 'preload', |
|
70 |
// to ignore runtime.js |
|
71 |
// https://github.com/vuejs/vue-cli/blob/dev/packages/@vue/cli-service/lib/config/app.js#L171 |
|
72 |
fileBlacklist: [/\.map$/, /hot-update\.js$/, /runtime\..*\.js$/], |
|
73 |
include: 'initial' |
|
74 |
} |
|
75 |
]) |
|
76 |
|
|
77 |
// when there are many pages, it will cause too many meaningless requests |
|
78 |
config.plugins.delete('prefetch') |
|
79 |
|
|
80 |
// set svg-sprite-loader |
|
81 |
config.module |
|
82 |
.rule('svg') |
|
83 |
.exclude.add(resolve('src/icons')) |
|
84 |
.end() |
|
85 |
config.module |
|
86 |
.rule('icons') |
|
87 |
.test(/\.svg$/) |
|
88 |
.include.add(resolve('src/icons')) |
|
89 |
.end() |
|
90 |
.use('svg-sprite-loader') |
|
91 |
.loader('svg-sprite-loader') |
|
92 |
.options({ |
|
93 |
symbolId: 'icon-[name]' |
|
94 |
}) |
|
95 |
.end() |
|
96 |
|
|
97 |
config |
|
98 |
.when(process.env.NODE_ENV !== 'development', |
|
99 |
config => { |
|
100 |
config |
|
101 |
.plugin('ScriptExtHtmlWebpackPlugin') |
|
102 |
.after('html') |
|
103 |
.use('script-ext-html-webpack-plugin', [{ |
|
104 |
// `runtime` must same as runtimeChunk name. default is `runtime` |
|
105 |
inline: /runtime\..*\.js$/ |
|
106 |
}]) |
|
107 |
.end() |
|
108 |
config |
|
109 |
.optimization.splitChunks({ |
|
110 |
chunks: 'all', |
|
111 |
cacheGroups: { |
|
112 |
libs: { |
|
113 |
name: 'chunk-libs', |
|
114 |
test: /[\\/]node_modules[\\/]/, |
|
115 |
priority: 10, |
|
116 |
chunks: 'initial' // only package third parties that are initially dependent |
|
117 |
}, |
|
118 |
elementUI: { |
|
119 |
name: 'chunk-elementUI', // split elementUI into a single package |
|
120 |
priority: 20, // the weight needs to be larger than libs and app or it will be packaged into libs or app |
|
121 |
test: /[\\/]node_modules[\\/]_?element-ui(.*)/ // in order to adapt to cnpm |
|
122 |
}, |
|
123 |
commons: { |
|
124 |
name: 'chunk-commons', |
|
125 |
test: resolve('src/components'), // can customize your rules |
|
126 |
minChunks: 3, // minimum common number |
|
127 |
priority: 5, |
|
128 |
reuseExistingChunk: true |
|
129 |
} |
|
130 |
} |
|
131 |
}) |
|
132 |
// https:// webpack.js.org/configuration/optimization/#optimizationruntimechunk |
|
133 |
config.optimization.runtimeChunk('single') |
|
134 |
} |
|
135 |
) |
|
136 |
} |
|
137 |
} |