-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathwebpack.config.js
66 lines (56 loc) · 1.75 KB
/
webpack.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
'use strict';
// 得到 webpack
const webpack = require('atool-build/lib/webpack');
module.exports = function(webpackConfig) {
// 开发环节添加source-map
if (process.env.NODE_ENV === 'development') {
webpackConfig.devtool = 'source-map';
}
// atpl loader
webpackConfig.module.loaders.push({test: /\.atpl$/, loader: 'atpl'});
// HTML 中可以使用 ejs 语法,一些通用占位符可以定义在这里
webpackConfig.module.loaders.push({test: /\.html?$/, loader: 'ejs-html'});
webpackConfig.ejsHtml = {
antBridgeVersion: '1.1.1'
};
const define = {
"default": {
'GET_JSON_MOCK': false
},
"test": {
'GET_JSON_MOCK': false
},
"prod": {
"GET_JSON_MOCK": false
},
"mock": {
'GET_JSON_MOCK': true
}
};
let definePluginOptionKey = define[process.env.NODE_ENV] ? process.env.NODE_ENV : define['default'] ? 'default' : '';
let defineContent;
if (definePluginOptionKey) {
defineContent = define[definePluginOptionKey];
if (typeof defineContent === 'object') {
for (let i in defineContent) {
if (typeof defineContent[i] === 'string' || typeof defineContent[i] === 'object') {
defineContent[i] = JSON.stringify(defineContent[i]);
}
}
}
webpackConfig.plugins.push(
new webpack.DefinePlugin(defineContent)
)
}
webpackConfig.plugins.some(function (plugin, i) {
if (plugin instanceof webpack.optimize.CommonsChunkPlugin) {
webpackConfig.plugins.splice(i, 1, new webpack.optimize.CommonsChunkPlugin({
name: 'common',
// minChunks: 2 如果对项目的common提取需要精确,可以控制设置这个值
}));
return true;
}
});
// 返回 webpack 配置对象
return webpackConfig;
};