-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvue.config.js
104 lines (95 loc) · 3.55 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
const path = require('path');
const projectConfig = require('./project.config.js');
const JsCss2JsonPlugin = require('./JsCss2JsonPlugin');
const chalk = require('chalk');
console.log(chalk.green('项目配置:'));
console.log(chalk.green(JSON.stringify(projectConfig, null, 4)));
const resolve = dir => path.join(__dirname, './', dir);
const isProd = process.env.NODE_ENV === 'production';
const execSync = require('child_process').execSync;
const gitUserName = execSync('git config --global user.name', {
encoding: 'utf8'
}).trim();
console.log(chalk.green('git用户名:', gitUserName));
process.env.VUE_APP_STORAGE_PREFIX = projectConfig.storagePrefix;
const genPlugins = () => {
const plugins = [];
isProd && plugins.push(new JsCss2JsonPlugin());
return plugins;
};
module.exports = {
publicPath: (isProd && projectConfig.outputToSvn) ? projectConfig.cdnUrl : '/',
outputDir: projectConfig.outputToSvn ? projectConfig.svnDir[gitUserName] : 'dist/',
assetsDir: 'static',
filenameHashing: true,
// eslint-loader 是否在保存的时候检查
lintOnSave: true,
// 生产环境是否生成 sourceMap 文件
productionSourceMap: !isProd,
// use thread-loader for babel & TS in production build
// enabled by default if the machine has more than 1 cores
parallel: require('os').cpus().length > 1,
// css相关配置
css: {
// 是否使用css分离插件 ExtractTextPlugin
// 提取 CSS 在开发环境模式下是默认不开启的,因为它和 CSS 热重载不兼容。
extract: isProd,
// 开启 CSS source maps?
sourceMap: !isProd,
// 启用 CSS modules for all css / pre-processor files.
modules: false
},
// webpack配置
// 简单的配置方式
configureWebpack: () => ({
name: `${projectConfig.projectName}`,
resolve: {
alias: {
'@': resolve('src'),
'@imgs': resolve('src/assets/imgs'),
'@audios': resolve('src/assets/audios'),
'@less': resolve('src/assets/less'),
'@utils': resolve('src/utils'),
'@views': resolve('src/views'),
'@styles': resolve('src/styles'),
'@mixin': resolve('src/mixin'),
'@c': resolve('src/components'),
'@directive': resolve('src/directive'),
'@game': resolve('src/game'),
'@pip': resolve('src/assets/pip'),
}
},
plugins: genPlugins()
}),
// 链式操作
chainWebpack: config => {
// webpack-html-plugin
config.plugin('html')
.tap(args => {
// 定义html文件中需要用到的一些数据
const htmlParams = {
production: isProd,
title: projectConfig.title,
baiduUrl: projectConfig.baiduUrl,
forceHttps: projectConfig.forceHttps
};
Object.assign(args[0], htmlParams);
// 不注入js和css,调试模式需要注入
args[0].inject = !isProd;
return args;
});
config.module.rule('images')
.use('url-loader')
.loader('url-loader')
.tap(options => Object.assign(options, { limit: 1 }));
},
// 第三方插件配置
pluginOptions: {
'style-resources-loader': {
preProcessor: 'less',
patterns: [
'./src/styles/less/*.less',
]
}
}
};