-
Notifications
You must be signed in to change notification settings - Fork 372
/
index.ts
58 lines (48 loc) · 1.58 KB
/
index.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
import type { Context, HookList } from '../../types';
import { getProjectTsconfig } from '../../utils/dts';
import { asset } from './asset';
import { formatCjs } from './format-cjs';
import { css } from './style';
import { minify } from './terser';
export async function getInternalList(context: Context): Promise<HookList> {
const internal = [];
const { config } = context;
internal.push(asset, css);
if (
config.buildType === 'bundle' &&
config.format === 'cjs' &&
config.splitting
) {
internal.push(formatCjs);
}
if (config.buildType === 'bundleless') {
const { redirect } = await import('./redirect');
const { json } = await import('./json');
internal.push(redirect, json);
}
const userTsconfig = await getProjectTsconfig(context.config.tsconfig);
const emitDecoratorMetadata =
userTsconfig?.compilerOptions?.emitDecoratorMetadata ?? false;
const { transformImport, transformLodash, externalHelpers, format, target } =
context.config;
const enbaleSwcTransform =
transformImport.length > 0 ||
transformLodash ||
externalHelpers ||
emitDecoratorMetadata;
const enableSwcRenderChunk = enbaleSwcTransform
? format === 'umd'
: format === 'umd' || target === 'es5';
if (enbaleSwcTransform) {
const { swcTransform } = await import('./swc');
internal.push(swcTransform(userTsconfig));
}
if (enableSwcRenderChunk) {
const { swcRenderChunk } = await import('./swc');
internal.push(swcRenderChunk);
}
if (config.minify && config.minify !== 'esbuild') {
internal.push(minify);
}
return internal;
}