|
|
|
const path = require('path');
|
|
|
|
const replaceLib = require('@ant-design/tools/lib/replaceLib');
|
|
|
|
const getWebpackConfig = require('@ant-design/tools/lib/getWebpackConfig');
|
|
|
|
const { ESBuildMinifyPlugin } = require('esbuild-loader');
|
|
|
|
const { version } = require('../package.json');
|
|
|
|
const themeConfig = require('./themeConfig');
|
|
|
|
|
|
|
|
const { webpack } = getWebpackConfig;
|
|
|
|
|
|
|
|
const isDev = process.env.NODE_ENV === 'development';
|
|
|
|
const { ANT_THEME, DEV_THEME } = process.env;
|
|
|
|
|
|
|
|
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,
|
|
|
|
);
|
|
|
|
// Add babel-plugin-add-react-displayname
|
|
|
|
rule.options.plugins.push(require.resolve('babel-plugin-add-react-displayname'));
|
|
|
|
} else if (rule.use) {
|
|
|
|
alertBabelConfig(rule.use);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
module.exports = {
|
|
|
|
port: 8001,
|
|
|
|
hash: true,
|
|
|
|
source: {
|
|
|
|
components: './components',
|
|
|
|
docs: './docs',
|
|
|
|
changelog: ['CHANGELOG.zh-CN.md', 'CHANGELOG.en-US.md'],
|
|
|
|
'components/form/v3': ['components/form/v3.zh-CN.md', 'components/form/v3.en-US.md'],
|
|
|
|
'docs/resources': ['./docs/resources.zh-CN.md', './docs/resources.en-US.md'],
|
|
|
|
},
|
|
|
|
theme: ANT_THEME ? './site/theme/index-css-only.js' : './site/theme',
|
|
|
|
htmlTemplate: './site/theme/static/template.html',
|
|
|
|
themeConfig,
|
|
|
|
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,
|
|
|
|
},
|
|
|
|
lessConfig: {
|
|
|
|
javascriptEnabled: true,
|
|
|
|
modifyVars: {
|
|
|
|
'root-entry-name': ANT_THEME || DEV_THEME || 'variable',
|
|
|
|
},
|
|
|
|
},
|
|
|
|
webpackConfig(config) {
|
|
|
|
config.resolve.alias = {
|
|
|
|
'antd/lib': path.join(process.cwd(), 'components'),
|
|
|
|
'antd/es': path.join(process.cwd(), 'components'),
|
|
|
|
// Change antd from `index.js` to `site/antd.js` to remove deps of root style
|
|
|
|
antd: path.join(process.cwd(), 'site', 'antd'),
|
|
|
|
site: path.join(process.cwd(), 'site'),
|
|
|
|
'react-router': 'react-router/umd/ReactRouter',
|
|
|
|
};
|
|
|
|
|
|
|
|
config.externals = {
|
|
|
|
'react-router-dom': 'ReactRouterDOM',
|
|
|
|
};
|
|
|
|
|
|
|