2016-05-27 11:48:08 +08:00
|
|
|
const path = require('path');
|
2019-08-01 15:28:16 +08:00
|
|
|
const replaceLib = require('@ant-design/tools/lib/replaceLib');
|
2022-05-03 21:34:30 +08:00
|
|
|
const { extractStyle } = require('@ant-design/cssinjs');
|
2019-12-13 15:49:52 +08:00
|
|
|
const getWebpackConfig = require('@ant-design/tools/lib/getWebpackConfig');
|
2021-05-07 15:29:08 +08:00
|
|
|
const { ESBuildMinifyPlugin } = require('esbuild-loader');
|
2022-05-03 21:34:30 +08:00
|
|
|
const fs = require('fs-extra');
|
2019-12-13 15:49:52 +08:00
|
|
|
const { version } = require('../package.json');
|
2020-05-31 11:48:34 +08:00
|
|
|
const themeConfig = require('./themeConfig');
|
2019-12-13 15:49:52 +08:00
|
|
|
|
|
|
|
const { webpack } = getWebpackConfig;
|
2016-05-27 11:48:08 +08:00
|
|
|
|
2017-09-06 09:19:35 +08:00
|
|
|
const isDev = process.env.NODE_ENV === 'development';
|
|
|
|
|
2017-11-27 18:28:52 +08:00
|
|
|
function alertBabelConfig(rules) {
|
2018-12-07 16:17:45 +08:00
|
|
|
rules.forEach(rule => {
|
2017-11-27 18:28:52 +08:00
|
|
|
if (rule.loader && rule.loader === 'babel-loader') {
|
2018-01-13 19:11:53 +08:00
|
|
|
if (rule.options.plugins.indexOf(replaceLib) === -1) {
|
|
|
|
rule.options.plugins.push(replaceLib);
|
|
|
|
}
|
2018-12-07 16:17:45 +08:00
|
|
|
rule.options.plugins = rule.options.plugins.filter(
|
|
|
|
plugin => !plugin.indexOf || plugin.indexOf('babel-plugin-add-module-exports') === -1,
|
|
|
|
);
|
2019-02-26 16:16:23 +08:00
|
|
|
// Add babel-plugin-add-react-displayname
|
|
|
|
rule.options.plugins.push(require.resolve('babel-plugin-add-react-displayname'));
|
2017-11-27 18:28:52 +08:00
|
|
|
} else if (rule.use) {
|
|
|
|
alertBabelConfig(rule.use);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2022-05-03 21:34:30 +08:00
|
|
|
const ssrCssFileName = `ssr-${Date.now()}.css`;
|
2022-06-24 16:40:48 +08:00
|
|
|
const port = process.env.DEV_PORT || 8001;
|
2022-05-03 21:34:30 +08:00
|
|
|
|
2016-05-27 11:48:08 +08:00
|
|
|
module.exports = {
|
2022-06-24 16:40:48 +08:00
|
|
|
port,
|
2019-04-09 17:29:11 +08:00
|
|
|
hash: true,
|
2017-02-09 16:55:29 +08:00
|
|
|
source: {
|
|
|
|
components: './components',
|
|
|
|
docs: './docs',
|
2018-12-07 16:17:45 +08:00
|
|
|
changelog: ['CHANGELOG.zh-CN.md', 'CHANGELOG.en-US.md'],
|
2019-07-03 20:14:39 +08:00
|
|
|
'components/form/v3': ['components/form/v3.zh-CN.md', 'components/form/v3.en-US.md'],
|
2020-02-27 10:53:30 +08:00
|
|
|
'docs/resources': ['./docs/resources.zh-CN.md', './docs/resources.en-US.md'],
|
2017-02-09 16:55:29 +08:00
|
|
|
},
|
2022-09-28 15:23:02 +08:00
|
|
|
theme: './site/theme',
|
2017-01-20 11:47:08 +08:00
|
|
|
htmlTemplate: './site/theme/static/template.html',
|
2020-05-31 11:48:34 +08:00
|
|
|
themeConfig,
|
2016-12-09 13:02:16 +08:00
|
|
|
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;
|
|
|
|
},
|
2016-06-16 09:59:14 +08:00
|
|
|
doraConfig: {
|
|
|
|
verbose: true,
|
|
|
|
},
|
2018-12-11 17:42:45 +08:00
|
|
|
lessConfig: {
|
|
|
|
javascriptEnabled: true,
|
2021-09-01 10:56:50 +08:00
|
|
|
modifyVars: {
|
2022-09-28 15:23:02 +08:00
|
|
|
'root-entry-name': 'variable',
|
2021-09-01 10:56:50 +08:00
|
|
|
},
|
2018-12-11 17:42:45 +08:00
|
|
|
},
|
2016-05-27 11:48:08 +08:00
|
|
|
webpackConfig(config) {
|
|
|
|
config.resolve.alias = {
|
2016-07-24 14:53:09 +08:00
|
|
|
'antd/lib': path.join(process.cwd(), 'components'),
|
2018-05-18 11:34:26 +08:00
|
|
|
'antd/es': path.join(process.cwd(), 'components'),
|
2021-09-01 10:56:50 +08:00
|
|
|
// Change antd from `index.js` to `site/antd.js` to remove deps of root style
|
|
|
|
antd: path.join(process.cwd(), 'site', 'antd'),
|
2016-05-27 11:48:08 +08:00
|
|
|
site: path.join(process.cwd(), 'site'),
|
2016-07-27 15:24:43 +08:00
|
|
|
'react-router': 'react-router/umd/ReactRouter',
|
2016-05-27 11:48:08 +08:00
|
|
|
};
|
|
|
|
|
2017-06-16 10:56:56 +08:00
|
|
|
config.externals = {
|
|
|
|
'react-router-dom': 'ReactRouterDOM',
|
|
|
|
};
|
2017-09-20 14:57:48 +08:00
|
|
|
|
2022-04-01 17:00:12 +08:00
|
|
|
config.plugins.push(
|
|
|
|
new webpack.DefinePlugin({
|
|
|
|
CSSINJS_STATISTIC: JSON.stringify(true),
|
|
|
|
}),
|
|
|
|
);
|
|
|
|
|
2017-11-17 17:23:48 +08:00
|
|
|
if (isDev) {
|
|
|
|
config.devtool = 'source-map';
|
2020-03-23 15:17:10 +08:00
|
|
|
|
2020-03-23 15:16:02 +08:00
|
|
|
// Resolve use react hook fail when yarn link or npm link
|
|
|
|
// https://github.com/webpack/webpack/issues/8607#issuecomment-453068938
|
2021-02-23 10:45:11 +08:00
|
|
|
config.resolve.alias = {
|
|
|
|
...config.resolve.alias,
|
|
|
|
'react/jsx-runtime': require.resolve('react/jsx-runtime'),
|
|
|
|
react: require.resolve('react'),
|
|
|
|
};
|
2020-05-08 15:48:21 +08:00
|
|
|
} else if (process.env.ESBUILD) {
|
|
|
|
// use esbuild
|
2022-04-01 14:29:06 +08:00
|
|
|
config.optimization.minimize = true;
|
2020-08-24 11:46:21 +08:00
|
|
|
config.optimization.minimizer = [
|
2021-01-14 15:32:16 +08:00
|
|
|
new ESBuildMinifyPlugin({
|
|
|
|
target: 'es2015',
|
2021-06-01 10:11:24 +08:00
|
|
|
css: true,
|
2020-08-24 11:46:21 +08:00
|
|
|
}),
|
|
|
|
];
|
2017-11-17 17:23:48 +08:00
|
|
|
}
|
|
|
|
|
2017-11-27 18:28:52 +08:00
|
|
|
alertBabelConfig(config.module.rules);
|
|
|
|
|
2019-08-08 12:35:48 +08:00
|
|
|
config.module.rules.push({
|
|
|
|
test: /\.mjs$/,
|
|
|
|
include: /node_modules/,
|
|
|
|
type: 'javascript/auto',
|
|
|
|
});
|
|
|
|
|
2019-12-13 15:49:52 +08:00
|
|
|
config.plugins.push(
|
|
|
|
new webpack.DefinePlugin({
|
2020-02-28 18:47:38 +08:00
|
|
|
antdReproduceVersion: JSON.stringify(version),
|
2019-12-13 15:49:52 +08:00
|
|
|
}),
|
|
|
|
);
|
2017-03-29 15:31:01 +08:00
|
|
|
|
2019-12-11 23:32:19 +08:00
|
|
|
delete config.module.noParse;
|
|
|
|
|
2021-11-26 14:42:27 +08:00
|
|
|
// Use dev mod to speed up site preview build
|
|
|
|
// This is used for CI preview build in `preview-build.yml`
|
|
|
|
if (process.env.SITE_ENV === 'development') {
|
2021-12-04 17:06:36 +08:00
|
|
|
// eslint-disable-next-line no-console
|
2021-11-26 14:42:27 +08:00
|
|
|
console.log('Site build with development mode...');
|
|
|
|
config.mode = 'development';
|
|
|
|
}
|
|
|
|
|
2022-05-08 09:48:30 +08:00
|
|
|
// Split chunks
|
2022-05-09 20:54:42 +08:00
|
|
|
if (config.mode === 'production') {
|
|
|
|
config.optimization.splitChunks = {
|
|
|
|
...config.optimization.splitChunks,
|
|
|
|
cacheGroups: {
|
|
|
|
vendors: {
|
|
|
|
test: /[/\\]node_modules[/\\]@ant-design[/\\]icon/,
|
|
|
|
name: 'anticon',
|
|
|
|
chunks: 'initial',
|
|
|
|
maxSize: 1024 * 1024,
|
|
|
|
},
|
|
|
|
components: {
|
|
|
|
test(module) {
|
|
|
|
return (
|
|
|
|
module.resource &&
|
|
|
|
module.resource.includes('ant-design/components') &&
|
|
|
|
!module.resource.includes('demo') &&
|
|
|
|
!module.resource.endsWith('md')
|
|
|
|
);
|
|
|
|
},
|
|
|
|
name: 'components',
|
|
|
|
chunks: 'initial',
|
2022-05-08 09:48:30 +08:00
|
|
|
},
|
|
|
|
},
|
2022-05-09 20:54:42 +08:00
|
|
|
};
|
|
|
|
}
|
2022-05-08 09:48:30 +08:00
|
|
|
|
2016-05-27 11:48:08 +08:00
|
|
|
return config;
|
|
|
|
},
|
2017-09-20 14:57:48 +08:00
|
|
|
|
2019-02-08 10:01:01 +08:00
|
|
|
devServerConfig: {
|
2022-06-24 16:40:48 +08:00
|
|
|
public: `${process.env.DEV_HOST || 'localhost'}:${port}`,
|
2019-02-08 10:01:01 +08:00
|
|
|
disableHostCheck: !!process.env.DEV_HOST,
|
|
|
|
},
|
|
|
|
|
2022-05-03 21:34:30 +08:00
|
|
|
postManifest: origin => {
|
|
|
|
const clone = {
|
|
|
|
...origin,
|
|
|
|
css: [...origin.css, ssrCssFileName],
|
|
|
|
};
|
|
|
|
|
|
|
|
return clone;
|
|
|
|
},
|
|
|
|
|
|
|
|
postBuild: () => {
|
|
|
|
const styleText = extractStyle(global.styleCache);
|
|
|
|
const styleTextWithoutStyleTag = styleText
|
|
|
|
.replace(/<style\s[^>]*>/g, '')
|
|
|
|
.replace(/<\/style>/g, '');
|
|
|
|
|
|
|
|
fs.writeFileSync(`./_site/${ssrCssFileName}`, styleTextWithoutStyleTag, 'utf8');
|
|
|
|
},
|
|
|
|
|
2017-09-06 09:19:35 +08:00
|
|
|
htmlTemplateExtraData: {
|
|
|
|
isDev,
|
|
|
|
},
|
2016-05-27 11:48:08 +08:00
|
|
|
};
|