forked from ant-design/ant-design-mobile-rn
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbisheng.common.config.js
131 lines (119 loc) · 3.68 KB
/
bisheng.common.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
const path = require('path');
const webpack = require('webpack');
const CSSSplitWebpackPlugin = require('css-split-webpack-plugin').default;
const replaceLib = require('antd-tools/lib/replaceLib');
const useReact = process.env.DEMO_ENV === 'react';
const isDev = process.env.NODE_ENV === 'development';
function alertBabelConfig(rules) {
rules.forEach((rule) => {
if (rule.loader && rule.loader === 'babel-loader') {
rule.options.plugins.push(replaceLib);
} else if (rule.use) {
alertBabelConfig(rule.use);
}
});
}
const reactExternals = {
react: 'React',
'react-dom': 'ReactDOM',
'react-router': 'ReactRouter',
};
const preactExternals = {
preact: 'preact',
};
const preactAlias = {
react: 'preact-compat',
'react-dom': 'preact-compat',
'create-react-class': 'preact-compat/lib/create-react-class',
preact$: 'preact/dist/preact.js', // https://github.com/developit/preact/issues/924
};
const prodExternals = useReact ? reactExternals : preactExternals;
module.exports = {
filePathMapper(filePath) {
if (filePath === '/index.html') {
return ['/index.html', '/index-cn.html'];
}
if (filePath.endsWith('/index.html')) {
return [filePath, filePath.replace(/\/index\.html$/, '-cn/index.html')];
}
if (filePath !== '/404.html' && filePath !== '/index-cn.html') {
return [filePath, filePath.replace(/\.html$/, '-cn.html')];
}
return filePath;
},
webpackConfig(config) {
config.externals = {
history: 'History',
'babel-polyfill': 'this', // hack babel-polyfill has no exports
};
// dev 环境下统一不 external
// 因为 preact/devtools 未提供 umd
if (!isDev) {
config.externals = Object.assign(config.externals, prodExternals);
} else {
config.devtool = 'source-map';
}
alertBabelConfig(config.module.rules);
config.plugins.push(new CSSSplitWebpackPlugin({ size: 4000 }));
config.resolve.alias = {
'@ant-design/react-native/lib': path.join(process.cwd(), 'components'),
'@ant-design/react-native': process.cwd(),
site: path.join(process.cwd(), 'site'),
};
if (!useReact) {
config.resolve.alias = Object.assign(config.resolve.alias, preactAlias);
}
config.plugins.push(new webpack.DefinePlugin({
PREACT_DEVTOOLS: isDev && !useReact,
'process.env': {
NODE_ENV: JSON.stringify(process.env.NODE_ENV),
},
}));
// fix webpack-dev-server "SyntaxError: Use of const in strict mode." ref https://github.com/mrdulin/blog/issues/35
// https://github.com/webpack/webpack/issues/2031#issuecomment-339336830
config.module.rules.push({
test: /webpack-dev-server|to-fast-properties/,
loader: 'babel-loader',
});
return config;
},
htmlTemplateExtraData: {
isDev,
useReact,
// useHD: process.env.HD_ENV === 'hd',
},
themeConfig: {
siteTitle: 'Ant Design Mobile RN',
siteSubTitle: '支付宝移动端 React Native 组件库',
categoryOrder: [
'Layout',
'Navigation',
'Data Entry',
'Data Display',
'Feedback',
'Gesture',
'Combination',
'Other',
],
cateChinese: {
Layout: '布局',
Navigation: '导航',
'Data Entry': '数据录入',
'Data Display': '数据展示',
Feedback: '操作反馈',
Gesture: '手势',
Combination: '组合组件',
Other: '其他',
},
docVersions: {
'0.7.x': 'http://07x.mobile.ant.design',
'0.8.x': 'http://08x.mobile.ant.design',
'0.9.x': 'http://09x.mobile.ant.design',
'1.x': 'http://1x.mobile.ant.design',
'2.x': 'http://2x.rn.mobile.ant.design',
},
},
devServerConfig: {
disableHostCheck: true,
},
};