forked from ant-design/ant-design
-
Notifications
You must be signed in to change notification settings - Fork 0
/
bisheng.config.js
144 lines (134 loc) · 3.88 KB
/
bisheng.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
138
139
140
141
142
143
144
const path = require('path');
const CSSSplitWebpackPlugin = require('css-split-webpack-plugin').default;
const OfflinePlugin = require('@yesmeck/offline-plugin');
const replaceLib = require('antd-tools/lib/replaceLib');
const getExternalResources = require('./getExternalResources');
const isDev = process.env.NODE_ENV === 'development';
const usePreact = process.env.REACT_ENV === 'preact';
function alertBabelConfig(rules) {
rules.forEach((rule) => {
if (rule.loader && rule.loader === 'babel-loader') {
if (rule.options.plugins.indexOf(replaceLib) === -1) {
rule.options.plugins.push(replaceLib);
}
rule.options.plugins = rule.options.plugins.filter(plugin => (
!plugin.indexOf || plugin.indexOf('babel-plugin-add-module-exports') === -1
));
} else if (rule.use) {
alertBabelConfig(rule.use);
}
});
}
module.exports = {
port: 8001,
source: {
components: './components',
docs: './docs',
changelog: [
'CHANGELOG.zh-CN.md',
'CHANGELOG.en-US.md',
],
},
theme: './site/theme',
htmlTemplate: './site/theme/static/template.html',
themeConfig: {
categoryOrder: {
'Ant Design': 0,
原则: 1,
Principles: 1,
视觉: 2,
Visual: 2,
模式: 3,
Patterns: 3,
其他: 6,
Other: 6,
Components: 100,
},
typeOrder: {
General: 0,
Layout: 1,
Navigation: 2,
'Data Entry': 3,
'Data Display': 4,
Feedback: 5,
Localization: 6,
Other: 7,
},
docVersions: {
'0.9.x': 'http://09x.ant.design',
'0.10.x': 'http://010x.ant.design',
'0.11.x': 'http://011x.ant.design',
'0.12.x': 'http://012x.ant.design',
'1.x': 'http://1x.ant.design',
'2.x': 'http://2x.ant.design',
},
},
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;
},
doraConfig: {
verbose: true,
plugins: ['dora-plugin-upload'],
},
webpackConfig(config) {
config.resolve.alias = {
'antd/lib': path.join(process.cwd(), 'components'),
'antd/es': path.join(process.cwd(), 'components'),
antd: path.join(process.cwd(), 'index'),
site: path.join(process.cwd(), 'site'),
'react-router': 'react-router/umd/ReactRouter',
};
config.externals = {
'react-router-dom': 'ReactRouterDOM',
};
if (usePreact) {
config.resolve.alias = Object.assign({}, config.resolve.alias, {
react: 'preact-compat',
'react-dom': 'preact-compat',
'create-react-class': 'preact-compat/lib/create-react-class',
'react-router': 'react-router',
});
}
if (isDev) {
config.devtool = 'source-map';
}
alertBabelConfig(config.module.rules);
config.plugins.push(
new CSSSplitWebpackPlugin({ size: 4000 }),
new OfflinePlugin({
appShell: '/app-shell',
caches: {
main: [':rest:'],
additional: [':externals:'],
},
externals: [
'/app-shell',
'https://at.alicdn.com/t/font_148784_v4ggb6wrjmkotj4i.woff',
'https://at.alicdn.com/t/font_148784_v4ggb6wrjmkotj4i.eot',
'https://at.alicdn.com/t/font_148784_v4ggb6wrjmkotj4i.svg',
'https://at.alicdn.com/t/font_148784_v4ggb6wrjmkotj4i.ttf',
].concat(getExternalResources()),
responseStrategy: 'network-first',
safeToUseOptionalCaches: true,
ServiceWorker: {
events: true,
},
AppCache: false,
}),
);
return config;
},
htmlTemplateExtraData: {
isDev,
usePreact,
},
};