forked from yuntijs/lowcode-materials
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathplugin.ts
84 lines (78 loc) · 2.5 KB
/
plugin.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
import type { IApi } from 'dumi';
const isProd = process.env.UMI_ENV === 'prod';
const REACT_SCRTPS = {
prod: [
'https://g.alicdn.com/code/lib/react/17.0.2/umd/react.production.min.js',
'https://g.alicdn.com/code/lib/react-dom/17.0.2/umd/react-dom.production.min.js',
],
dev: [
'https://g.alicdn.com/code/lib/react/17.0.2/umd/react.development.js',
'https://g.alicdn.com/code/lib/react-dom/17.0.2/umd/react-dom.development.js',
],
};
const LOW_CODE_HEAD_SCRIPTS = [
'https://g.alicdn.com/mylib/moment/2.24.0/min/moment.min.js',
'https://g.alicdn.com/code/lib/alifd__next/1.26.8/next.min.js',
'https://alifd.alicdn.com/npm/@alilc/[email protected]/dist/js/engine-core.js',
'https://alifd.alicdn.com/npm/@alilc/[email protected]/dist/js/engine-ext.js',
];
const LOW_CODE_LINKS = [
{
href: 'http://dev-unpkg.tenxcloud.net/@tenx-ui/[email protected]/dist/@tenx-ui/icon.css',
rel: 'stylesheet',
},
{
href: 'https://alifd.alicdn.com/npm/@alifd/[email protected]/variables.css',
rel: 'stylesheet',
},
{
href: 'https://alifd.alicdn.com/npm/@alifd/[email protected]/dist/next.var.min.css',
rel: 'stylesheet',
},
{
href: 'https://alifd.alicdn.com/npm/@alilc/[email protected]/dist/css/engine-core.css',
rel: 'stylesheet',
},
{
href: 'https://alifd.alicdn.com/npm/@alilc/[email protected]/dist/css/engine-ext.css',
rel: 'stylesheet',
},
];
const ProjectPlugin = (api: IApi) => {
api.modifyHTML(($, { path }) => {
const scripts = REACT_SCRTPS[isProd ? 'prod' : 'dev'].map(
src => `<script src="${src}"></script>`
);
const lowCodeScripts = [...REACT_SCRTPS.prod, ...LOW_CODE_HEAD_SCRIPTS].map(
src => `<script type="text/javascript" src="${src}"></script>`
);
const lowCodeLinks = LOW_CODE_LINKS.map(
({ href, rel }) => `<link href="${href}" rel="${rel}">`
);
if (isProd) {
// 生产环境中通过 yunti-server ejs render 在不同的页面引入不同的依赖
$('head').append(
`[? if (LOW_CODE) { ?]
${lowCodeLinks.join('\n')}
${lowCodeScripts.join('\n')}
[? } else { ?]
${scripts.join('\n')}
[? } ?]`
);
} else {
// 仅为设计页面增加 LowCode 相关资源文件
if (path.startsWith('/~demos/')) {
$('head').append(
`${lowCodeLinks.join('\n')}
${lowCodeScripts.join('\n')}`
);
} else {
$('head').append(`
${scripts.join('\n')}
`);
}
}
return $;
});
};
export default ProjectPlugin;