-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathvue.config.js
137 lines (130 loc) · 3.83 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
const CompressionPlugin = require('compression-webpack-plugin');
/** @type {} */
module.exports = {
// https://cli.vuejs.org/config/#publicpath
publicPath: './',
outputDir: 'dist',
assetsDir: 'assets',
lintOnSave: true,
/**https://www.jianshu.com/p/303c220e213d */
css: {
// 是否使用css分离插件 ExtractTextPlugin
extract: false,
modules: false,
sourceMap: process.env.NODE_ENV !== 'production',
loaderOptions: {
less: {},
},
},
devServer: {
port: 4141,
host: '0.0.0.0',
open: true,
overlay: {
warnings: true,
errors: true,
},
// proxy: {
// // '/baidufanyi': {
// // target: 'http://api.fanyi.baidu.com',
// // changeOrigin: true,
// // pathRewrite: {
// // '^/baidufanyi': '/api/trans/vip/translate',
// // },
// // },
// },
},
transpileDependencies: [
// './node_modules/[email protected]@aos/src/js/helpers/elements.js',
],
configureWebpack: {
resolve: {
alias: {
src: '@',
assets: '@/assets',
components: '@/components',
pages: '@/components/pages',
utils: '@/utils',
api: '@/apis',
services: '@/services',
models: '@/models',
},
},
},
chainWebpack: config => {
// #region 忽略生成环境打包的文件
if (process.env.NODE_ENV === 'production') {
// #region 启用GZip压缩
config
.plugin('compression')
.use(CompressionPlugin, {
asset: '[path].gz[query]',
algorithm: 'gzip',
test: new RegExp('\\.(' + ['js', 'css'].join('|') + ')$'),
threshold: 10240,
minRatio: 0.8,
cache: true,
})
.tap(args => {});
// #endregion
// #region 启用第三方cdn加速
var externals = {
vue: 'Vue',
axios: 'axios',
'element-ui': 'ELEMENT',
'vue-router': 'VueRouter',
'vue-i18n': 'VueI18n',
aos: 'AOS',
// vuex: 'Vuex',
};
// https://webpack.docschina.org/configuration/externals/#src/components/Sidebar/Sidebar.jsx
config.externals([
externals,
function(context, request, callback) {
// 所有 ol 包里的内容
if (/^ol\/?/.test(request)) {
// console.log(request);
// https://segmentfault.com/q/1010000021965610?_ea=33440450
// https://blog.meathill.com/fe-tool-chain/webpack-4-notes.html
/** 先关闭webgl */
// if (request === 'ol/layer/WebGLPoints') return callback();
return callback(null, request.replace(/\//g, '.'));
}
// @ts-ignore
callback();
},
]);
const cdn = {
css: [
// element-ui css
'//unpkg.com/element-ui/lib/theme-chalk/index.css',
'//unpkg.com/element-ui/lib/theme-chalk/display.css',
'//unpkg.com/[email protected]/dist/aos.css',
'//cdn.jsdelivr.net/gh/openlayers/openlayers.github.io@master/en/v6.2.1/css/ol.css',
],
js: [
// vue
'//unpkg.com/[email protected]/dist/vue.min.js',
// vue-router
'//unpkg.com/[email protected]/dist/vue-router.min.js',
// vuex
// '//cdn.staticfile.org/vuex/3.1.0/vuex.min.js',
// axios
'//unpkg.com/[email protected]/dist/axios.min.js',
// element-ui js
'//unpkg.com/element-ui/lib/index.js',
'//unpkg.com/[email protected]/dist/vue-i18n.min.js',
'//unpkg.com/[email protected]/dist/aos.js',
'//cdn.jsdelivr.net/gh/openlayers/openlayers.github.io@master/en/v6.2.1/build/ol.min.js',
],
};
config.plugin('html').tap(args => {
args[0].cdn = cdn;
return args;
});
// #endregion
}
// #endregion
},
productionSourceMap: false,
};