Files
ant-design/.dumirc.ts
QdabuliuQ 4dc35000b1 docs: improve site locale detection (#56618)
* fix(Site): improve changelog header styles and locale detection

* style: fix link and button style conflicts in typography

* style: modify style file

* style: reset typography mixins.ts file

---------

Co-authored-by: 遇见同学 <1875694521@qq.com>
2026-01-16 09:37:26 +08:00

209 lines
6.4 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import os from 'node:os';
import path from 'path';
import { defineConfig } from 'dumi';
import * as fs from 'fs-extra';
import rehypeAntd from './.dumi/rehypeAntd';
import rehypeChangelog from './.dumi/rehypeChangelog';
import remarkAnchor from './.dumi/remarkAnchor';
import remarkAntd from './.dumi/remarkAntd';
import { version } from './package.json';
export default defineConfig({
plugins: ['dumi-plugin-color-chunk'],
// For <Link prefetch />
routePrefetch: {},
manifest: {},
conventionRoutes: {
// to avoid generate routes for .dumi/pages/index/components/xx
exclude: [/index\/components\//],
},
ssr:
process.env.NODE_ENV === 'production'
? {
builder: 'mako',
}
: false,
hash: true,
mfsu: false,
mako: ['Darwin', 'Linux'].includes(os.type()) ? {} : false,
crossorigin: {},
runtimePublicPath: {},
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'),
antd: path.join(__dirname, 'components'),
// https://github.com/ant-design/ant-design/issues/46628
'@ant-design/icons$': '@ant-design/icons/lib',
},
extraRehypePlugins: [rehypeAntd, rehypeChangelog],
extraRemarkPlugins: [remarkAntd, remarkAnchor],
metas: [
{ name: 'theme-color', content: '#1677ff' },
{ name: 'build-time', content: Date.now().toString() },
// https://docs.github.com/en/actions/learn-github-actions/variables#default-environment-variables
{ name: 'build-hash', content: process.env.GITHUB_SHA ?? 'unknown' },
],
analytics: {
ga_v2: 'UA-72788897-1',
},
analyze:
process.env.NODE_ENV === 'production'
? false
: {
analyzerPort: 'auto',
},
links: [
{
rel: 'prefetch',
as: 'font',
href: '//at.alicdn.com/t/webfont_6e11e43nfj.woff2',
type: 'font/woff2',
crossorigin: 'anonymous',
},
{
rel: 'prefetch',
as: 'font',
href: '//at.alicdn.com/t/webfont_6e11e43nfj.woff',
type: 'font/woff',
crossorigin: 'anonymous',
},
{
rel: 'prefetch',
as: 'font',
href: '//at.alicdn.com/t/webfont_6e11e43nfj.ttf',
type: 'font/ttf',
crossorigin: 'anonymous',
},
{
rel: 'prefetch',
as: 'font',
href: '//at.alicdn.com/t/webfont_exesdog9toj.woff2',
type: 'font/woff2',
crossorigin: 'anonymous',
},
{
rel: 'prefetch',
as: 'font',
href: '//at.alicdn.com/t/webfont_exesdog9toj.woff',
type: 'font/woff',
crossorigin: 'anonymous',
},
{
rel: 'prefetch',
as: 'font',
href: '//at.alicdn.com/t/webfont_exesdog9toj.ttf',
type: 'font/ttf',
crossorigin: 'anonymous',
},
{
rel: 'preload',
as: 'font',
href: '//at.alicdn.com/wf/webfont/exMpJIukiCms/Gsw2PSKrftc1yNWMNlXgw.woff2',
type: 'font/woff2',
crossorigin: 'anonymous',
},
{
rel: 'preload',
as: 'font',
href: '//at.alicdn.com/wf/webfont/exMpJIukiCms/vtu73by4O2gEBcvBuLgeu.woff',
type: 'font/woff2',
crossorigin: 'anonymous',
},
],
headScripts: [
`
(function () {
// 优先级提高到所有静态资源的前面,语言不对,加载其他静态资源没意义
const pathname = location.pathname;
function isZhCN(pathname) {
return /-cn\\/?$/.test(pathname);
}
function getLocalizedPathname(path, zhCN) {
const pathname = path.indexOf('/') === 0 ? path : '/' + path;
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=...\`
const queryString = location.search;
if (queryString) {
const isZhCNConfig = queryString.indexOf('zh-CN') > -1;
if (isZhCNConfig && !isZhCN(pathname)) {
location.pathname = getLocalizedPathname(pathname, isZhCNConfig);
}
}
// 首页无视链接里面的语言设置 https://github.com/ant-design/ant-design/issues/4552
const normalizedPathname = pathname || '/';
if (normalizedPathname === '/' || normalizedPathname === '/index-cn') {
let lang;
if (window.localStorage) {
const antLocale = localStorage.getItem('ANT_LOCAL_TYPE_KEY');
// 尝试解析 JSON因为可能是被序列化后存储的 "en-US" / en-US https://github.com/ant-design/ant-design/issues/56606
try {
lang = antLocale ? JSON.parse(antLocale) : localStorage.getItem('locale');
} catch (e) {
lang = antLocale ? antLocale : localStorage.getItem('locale');
}
}
lang = lang || ((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(normalizedPathname)) {
location.pathname = getLocalizedPathname(normalizedPathname, lang === 'zh-CN');
}
}
document.documentElement.className += isZhCN(normalizedPathname) ? 'zh-cn' : 'en-us';
})();
`,
],
scripts: [
{
src: 'https://cdn.jsdelivr.net/npm/@tailwindcss/browser@4',
async: true,
},
{
async: true,
content: fs
.readFileSync(path.join(__dirname, '.dumi', 'scripts', 'mirror-notify.js'))
.toString(),
},
// Only enable clarity in production environment
process.env.NODE_ENV === 'production'
? {
async: true,
content: fs
.readFileSync(path.join(__dirname, '.dumi', 'scripts', 'clarity.js'))
.toString(),
}
: null,
].filter((script) => !!script),
});