2022-11-09 12:28:04 +08:00
|
|
|
|
import path from 'path';
|
2023-12-27 13:57:51 +08:00
|
|
|
|
import { defineConfig } from 'dumi';
|
|
|
|
|
import * as fs from 'fs-extra';
|
|
|
|
|
|
2022-11-09 12:28:04 +08:00
|
|
|
|
import rehypeAntd from './.dumi/rehypeAntd';
|
2023-03-14 20:34:36 +08:00
|
|
|
|
import remarkAntd from './.dumi/remarkAntd';
|
2022-11-09 12:28:04 +08:00
|
|
|
|
import { version } from './package.json';
|
|
|
|
|
|
|
|
|
|
export default defineConfig({
|
2023-09-20 16:59:56 +08:00
|
|
|
|
plugins: ['dumi-plugin-color-chunk'],
|
2022-11-09 12:28:04 +08:00
|
|
|
|
conventionRoutes: {
|
|
|
|
|
// to avoid generate routes for .dumi/pages/index/components/xx
|
|
|
|
|
exclude: [new RegExp('index/components/')],
|
|
|
|
|
},
|
|
|
|
|
ssr: process.env.NODE_ENV === 'production' ? {} : false,
|
|
|
|
|
hash: true,
|
2023-08-11 19:37:53 +08:00
|
|
|
|
mfsu: false,
|
2023-01-12 11:17:04 +08:00
|
|
|
|
crossorigin: {},
|
2022-11-09 12:28:04 +08:00
|
|
|
|
outputPath: '_site',
|
|
|
|
|
favicons: ['https://gw.alipayobjects.com/zos/rmsportal/rlpTLlbMzTNYuZGGCVYM.png'],
|
|
|
|
|
resolve: {
|
|
|
|
|
docDirs: [{ type: 'doc', dir: 'docs' }],
|
|
|
|
|
atomDirs: [{ type: 'component', dir: 'components' }],
|
|
|
|
|
codeBlockMode: 'passive',
|
|
|
|
|
},
|
|
|
|
|
locales: [
|
|
|
|
|
{ id: 'en-US', name: 'English', suffix: '' },
|
|
|
|
|
{ id: 'zh-CN', name: '中文', suffix: '-cn' },
|
|
|
|
|
],
|
|
|
|
|
define: {
|
|
|
|
|
antdReproduceVersion: version,
|
|
|
|
|
},
|
|
|
|
|
alias: {
|
|
|
|
|
'antd/lib': path.join(__dirname, 'components'),
|
|
|
|
|
'antd/es': path.join(__dirname, 'components'),
|
|
|
|
|
'antd/locale': path.join(__dirname, 'components/locale'),
|
2023-07-25 11:53:28 +08:00
|
|
|
|
antd: path.join(__dirname, 'components'),
|
2023-12-27 13:57:51 +08:00
|
|
|
|
// https://github.com/ant-design/ant-design/issues/46628
|
|
|
|
|
'@ant-design/icons$': '@ant-design/icons/lib',
|
2022-11-09 12:28:04 +08:00
|
|
|
|
},
|
|
|
|
|
extraRehypePlugins: [rehypeAntd],
|
2023-03-14 20:34:36 +08:00
|
|
|
|
extraRemarkPlugins: [remarkAntd],
|
2022-11-16 14:07:57 +08:00
|
|
|
|
metas: [{ name: 'theme-color', content: '#1677ff' }],
|
|
|
|
|
analytics: {
|
|
|
|
|
ga_v2: 'UA-72788897-1',
|
|
|
|
|
},
|
2023-07-25 09:31:44 +08:00
|
|
|
|
analyze: {
|
|
|
|
|
analyzerPort: 'auto',
|
|
|
|
|
},
|
2023-07-21 17:14:54 +08:00
|
|
|
|
links: [
|
|
|
|
|
{
|
2023-08-21 19:48:50 +08:00
|
|
|
|
rel: 'prefetch',
|
2023-07-21 17:14:54 +08:00
|
|
|
|
as: 'font',
|
|
|
|
|
href: '//at.alicdn.com/t/webfont_6e11e43nfj.woff2',
|
|
|
|
|
type: 'font/woff2',
|
|
|
|
|
crossorigin: true,
|
|
|
|
|
},
|
|
|
|
|
{
|
2023-08-21 19:48:50 +08:00
|
|
|
|
rel: 'prefetch',
|
2023-07-21 17:14:54 +08:00
|
|
|
|
as: 'font',
|
|
|
|
|
href: '//at.alicdn.com/t/webfont_6e11e43nfj.woff',
|
|
|
|
|
type: 'font/woff',
|
|
|
|
|
crossorigin: true,
|
|
|
|
|
},
|
|
|
|
|
{
|
2023-08-21 19:48:50 +08:00
|
|
|
|
rel: 'prefetch',
|
2023-07-21 17:14:54 +08:00
|
|
|
|
as: 'font',
|
|
|
|
|
href: '//at.alicdn.com/t/webfont_6e11e43nfj.ttf',
|
|
|
|
|
type: 'font/ttf',
|
|
|
|
|
crossorigin: true,
|
|
|
|
|
},
|
|
|
|
|
{
|
2023-08-21 19:48:50 +08:00
|
|
|
|
rel: 'prefetch',
|
2023-07-21 17:14:54 +08:00
|
|
|
|
as: 'font',
|
|
|
|
|
href: '//at.alicdn.com/t/webfont_exesdog9toj.woff2',
|
|
|
|
|
type: 'font/woff2',
|
|
|
|
|
crossorigin: true,
|
|
|
|
|
},
|
|
|
|
|
{
|
2023-08-21 19:48:50 +08:00
|
|
|
|
rel: 'prefetch',
|
2023-07-21 17:14:54 +08:00
|
|
|
|
as: 'font',
|
|
|
|
|
href: '//at.alicdn.com/t/webfont_exesdog9toj.woff',
|
|
|
|
|
type: 'font/woff',
|
|
|
|
|
crossorigin: true,
|
|
|
|
|
},
|
|
|
|
|
{
|
2023-08-21 19:48:50 +08:00
|
|
|
|
rel: 'prefetch',
|
2023-07-21 17:14:54 +08:00
|
|
|
|
as: 'font',
|
|
|
|
|
href: '//at.alicdn.com/t/webfont_exesdog9toj.ttf',
|
|
|
|
|
type: 'font/ttf',
|
|
|
|
|
crossorigin: true,
|
|
|
|
|
},
|
|
|
|
|
{
|
2023-08-22 11:31:49 +08:00
|
|
|
|
rel: 'preload',
|
2023-07-21 17:14:54 +08:00
|
|
|
|
as: 'font',
|
|
|
|
|
href: '//at.alicdn.com/wf/webfont/exMpJIukiCms/Gsw2PSKrftc1yNWMNlXgw.woff2',
|
|
|
|
|
type: 'font/woff2',
|
|
|
|
|
crossorigin: true,
|
|
|
|
|
},
|
|
|
|
|
{
|
2023-08-22 11:31:49 +08:00
|
|
|
|
rel: 'preload',
|
2023-07-21 17:14:54 +08:00
|
|
|
|
as: 'font',
|
|
|
|
|
href: '//at.alicdn.com/wf/webfont/exMpJIukiCms/vtu73by4O2gEBcvBuLgeu.woff',
|
|
|
|
|
type: 'font/woff2',
|
|
|
|
|
crossorigin: true,
|
|
|
|
|
},
|
|
|
|
|
],
|
2022-11-09 12:28:04 +08:00
|
|
|
|
headScripts: [
|
|
|
|
|
`
|
|
|
|
|
(function () {
|
|
|
|
|
function isLocalStorageNameSupported() {
|
2022-12-19 10:07:52 +08:00
|
|
|
|
const testKey = 'test';
|
|
|
|
|
const storage = window.localStorage;
|
2022-11-09 12:28:04 +08:00
|
|
|
|
try {
|
|
|
|
|
storage.setItem(testKey, '1');
|
|
|
|
|
storage.removeItem(testKey);
|
|
|
|
|
return true;
|
|
|
|
|
} catch (error) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
// 优先级提高到所有静态资源的前面,语言不对,加载其他静态资源没意义
|
2022-12-19 10:07:52 +08:00
|
|
|
|
const pathname = location.pathname;
|
2022-11-09 12:28:04 +08:00
|
|
|
|
|
|
|
|
|
function isZhCN(pathname) {
|
|
|
|
|
return /-cn\\/?$/.test(pathname);
|
|
|
|
|
}
|
|
|
|
|
function getLocalizedPathname(path, zhCN) {
|
2022-12-19 10:07:52 +08:00
|
|
|
|
const pathname = path.indexOf('/') === 0 ? path : '/' + path;
|
2022-11-09 12:28:04 +08:00
|
|
|
|
if (!zhCN) {
|
|
|
|
|
// to enUS
|
|
|
|
|
return /\\/?index(-cn)?/.test(pathname) ? '/' : pathname.replace('-cn', '');
|
|
|
|
|
} else if (pathname === '/') {
|
|
|
|
|
return '/index-cn';
|
|
|
|
|
} else if (pathname.indexOf('/') === pathname.length - 1) {
|
|
|
|
|
return pathname.replace(/\\/$/, '-cn/');
|
|
|
|
|
}
|
|
|
|
|
return pathname + '-cn';
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 兼容旧的 URL, \`?locale=...\`
|
2022-12-19 10:07:52 +08:00
|
|
|
|
const queryString = location.search;
|
2022-11-09 12:28:04 +08:00
|
|
|
|
if (queryString) {
|
2022-12-19 10:07:52 +08:00
|
|
|
|
const isZhCNConfig = queryString.indexOf('zh-CN') > -1;
|
2022-11-09 12:28:04 +08:00
|
|
|
|
if (isZhCNConfig && !isZhCN(pathname)) {
|
|
|
|
|
location.pathname = getLocalizedPathname(pathname, isZhCNConfig);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 首页无视链接里面的语言设置 https://github.com/ant-design/ant-design/issues/4552
|
|
|
|
|
if (isLocalStorageNameSupported() && (pathname === '/' || pathname === '/index-cn')) {
|
2022-12-19 10:07:52 +08:00
|
|
|
|
const lang =
|
2022-11-09 12:28:04 +08:00
|
|
|
|
(window.localStorage && localStorage.getItem('locale')) ||
|
|
|
|
|
((navigator.language || navigator.browserLanguage).toLowerCase() === 'zh-cn'
|
|
|
|
|
? 'zh-CN'
|
|
|
|
|
: 'en-US');
|
|
|
|
|
// safari is 'zh-cn', while other browser is 'zh-CN';
|
|
|
|
|
if ((lang === 'zh-CN') !== isZhCN(pathname)) {
|
|
|
|
|
location.pathname = getLocalizedPathname(pathname, lang === 'zh-CN');
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
document.documentElement.className += isZhCN(pathname) ? 'zh-cn' : 'en-us';
|
|
|
|
|
})();
|
|
|
|
|
`,
|
|
|
|
|
],
|
2023-08-21 19:51:47 +08:00
|
|
|
|
scripts: [
|
|
|
|
|
{
|
|
|
|
|
async: true,
|
|
|
|
|
content: fs.readFileSync(path.join(__dirname, '.dumi', 'mirror-modal.js')).toString(),
|
|
|
|
|
},
|
|
|
|
|
],
|
2022-11-09 12:28:04 +08:00
|
|
|
|
});
|