-
Notifications
You must be signed in to change notification settings - Fork 34
/
runtimeEntry.ts
38 lines (35 loc) · 1.07 KB
/
runtimeEntry.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
import {build, BuildOptions} from 'esbuild';
// @ts-expect-error
import dedent from 'dedent';
import {dirFromImportMeta} from '@reskript/core';
const content = (appName: string) => dedent`
import {registerMicroApps, start} from 'qiankun';
const apps = [
{
name: '${appName}',
entry: '/assets/index.html',
container: '#apps',
activeRule: '/',
},
];
registerMicroApps(apps);
start();
`;
export default async (appName: string) => {
const options: BuildOptions = {
stdin: {
contents: content(appName),
resolveDir: dirFromImportMeta(import.meta.url),
},
bundle: true,
format: 'iife',
write: false,
sourcemap: false,
define: {
// 为了避免在UT的时候被`vitest`给替换成`"test": '"development"'`这样子,增加一些动态计算
['0process.env.NODE_ENV0'.slice(1, -1)]: '"development"',
},
};
const bundle = await build(options);
return bundle.outputFiles?.[0].text;
};