-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvue.config.js
73 lines (64 loc) · 2.47 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
const path = require('path');
const CompressionWebpackPlugin = require('compression-webpack-plugin');
const productionGzipExtensions = [ 'js', 'css' ];
const debug = process.env.NODE_ENV !== 'production';
const autoBuildIndex = require('./.2o3t/bin/autoBuildIndex');
const loadLibs = [
'components',
'designs',
'themes',
];
autoBuildIndex(loadLibs);
const aliasLibs = loadLibs.reduce((obj, item) => {
obj[`@${item}`] = path.resolve(__dirname, `./src/${item}`);
return obj;
}, {});
console.log(aliasLibs);
const customLoader = require('./.2o3t/loaders');
const PRODUCTION_BASE_URL = '2o3t-IconFont';
const vueConfig = {
baseUrl: debug ? '/' : PRODUCTION_BASE_URL,
outputDir: 'webs',
configureWebpack: config => {
// webpack配置,值位对象时会合并配置,为方法时会改写配置
if (debug) { // 开发环境配置
config.devtool = 'cheap-module-eval-source-map';
} else { // 生产环境配置
const externals = config.externals || {};
Object.assign(config, {
externals: Object.assign(externals, {
// 'highlight.js': 'hljs',
// 'markdown-it': 'markdownit',
// clipboard: 'clipboard-polyfill',
}),
});
// gzip
config.plugins.push(new CompressionWebpackPlugin({
algorithm: 'gzip',
test: new RegExp('\\.(' + productionGzipExtensions.join('|') + ')$'),
threshold: 10240,
minRatio: 0.8,
}));
}
const resolve = config.resolve || {};
const alias = resolve.alias || {};
Object.assign(config.resolve, { // 开发生产共同配置
alias: Object.assign(alias, {
'@font': path.resolve(__dirname, './assets'),
'@': path.resolve(__dirname, './src'),
'@data': path.resolve(__dirname, './src/data'),
'@router': path.resolve(__dirname, './src/router'),
'@assets': path.resolve(__dirname, './src/assets'),
'@views': path.resolve(__dirname, './src/views'),
'@libs': path.resolve(__dirname, './libs'),
vue$: 'vue/dist/vue.esm.js',
...aliasLibs,
}),
extensions: [ '.js', '.jsx', '.vue', '.json', '.css' ],
});
},
chainWebpack: config => {
customLoader(config);
},
};
module.exports = vueConfig;