You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
147 lines
3.6 KiB
147 lines
3.6 KiB
const path = require('path');
|
|
const CSSSplitWebpackPlugin = require('css-split-webpack-plugin').default;
|
|
const replaceLib = require('antd-tools/lib/replaceLib');
|
|
const webpack = require('webpack');
|
|
const WebpackBar = require('webpackbar');
|
|
|
|
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);
|
|
}
|
|
});
|
|
}
|
|
|
|
function usePrettyWebpackBar(config) {
|
|
// remove old progress plugin.
|
|
config.plugins = config.plugins
|
|
.filter((plugin) => {
|
|
return !(plugin instanceof webpack.ProgressPlugin)
|
|
&& !(plugin instanceof WebpackBar);
|
|
});
|
|
|
|
// use brand new progress bar.
|
|
config.plugins.push(
|
|
new WebpackBar({
|
|
name: '📦 Site',
|
|
minimal: false,
|
|
})
|
|
);
|
|
}
|
|
|
|
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,
|
|
Other: 6,
|
|
通用: 0,
|
|
布局: 1,
|
|
导航: 2,
|
|
数据录入: 3,
|
|
数据展示: 4,
|
|
反馈: 5,
|
|
其他: 6,
|
|
},
|
|
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,
|
|
},
|
|
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);
|
|
usePrettyWebpackBar(config);
|
|
|
|
config.plugins.push(
|
|
new CSSSplitWebpackPlugin({ size: 4000 }),
|
|
);
|
|
|
|
return config;
|
|
},
|
|
|
|
htmlTemplateExtraData: {
|
|
isDev,
|
|
usePreact,
|
|
},
|
|
};
|
|
|