forked from ant-design/ant-design
-
Notifications
You must be signed in to change notification settings - Fork 0
/
.dumirc.ts
170 lines (166 loc) · 4.96 KB
/
.dumirc.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
import { defineConfig } from 'dumi';
import path from 'path';
import rehypeAntd from './.dumi/rehypeAntd';
import remarkAntd from './.dumi/remarkAntd';
import { version } from './package.json';
import * as fs from 'fs-extra';
export default defineConfig({
plugins: ['dumi-plugin-color-chunk'],
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,
mfsu: false,
live: true,
crossorigin: {},
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'),
},
extraRehypePlugins: [rehypeAntd],
extraRemarkPlugins: [remarkAntd],
metas: [{ name: 'theme-color', content: '#1677ff' }],
analytics: {
ga_v2: 'UA-72788897-1',
},
analyze: {
analyzerPort: 'auto',
},
links: [
{
rel: 'prefetch',
as: 'font',
href: '//at.alicdn.com/t/webfont_6e11e43nfj.woff2',
type: 'font/woff2',
crossorigin: true,
},
{
rel: 'prefetch',
as: 'font',
href: '//at.alicdn.com/t/webfont_6e11e43nfj.woff',
type: 'font/woff',
crossorigin: true,
},
{
rel: 'prefetch',
as: 'font',
href: '//at.alicdn.com/t/webfont_6e11e43nfj.ttf',
type: 'font/ttf',
crossorigin: true,
},
{
rel: 'prefetch',
as: 'font',
href: '//at.alicdn.com/t/webfont_exesdog9toj.woff2',
type: 'font/woff2',
crossorigin: true,
},
{
rel: 'prefetch',
as: 'font',
href: '//at.alicdn.com/t/webfont_exesdog9toj.woff',
type: 'font/woff',
crossorigin: true,
},
{
rel: 'prefetch',
as: 'font',
href: '//at.alicdn.com/t/webfont_exesdog9toj.ttf',
type: 'font/ttf',
crossorigin: true,
},
{
rel: 'preload',
as: 'font',
href: '//at.alicdn.com/wf/webfont/exMpJIukiCms/Gsw2PSKrftc1yNWMNlXgw.woff2',
type: 'font/woff2',
crossorigin: true,
},
{
rel: 'preload',
as: 'font',
href: '//at.alicdn.com/wf/webfont/exMpJIukiCms/vtu73by4O2gEBcvBuLgeu.woff',
type: 'font/woff2',
crossorigin: true,
},
],
headScripts: [
`
(function () {
function isLocalStorageNameSupported() {
const testKey = 'test';
const storage = window.localStorage;
try {
storage.setItem(testKey, '1');
storage.removeItem(testKey);
return true;
} catch (error) {
return false;
}
}
// 优先级提高到所有静态资源的前面,语言不对,加载其他静态资源没意义
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
if (isLocalStorageNameSupported() && (pathname === '/' || pathname === '/index-cn')) {
const lang =
(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';
})();
`,
],
scripts: [
{
async: true,
content: fs.readFileSync(path.join(__dirname, '.dumi', 'mirror-modal.js')).toString(),
},
],
});