-
-
Notifications
You must be signed in to change notification settings - Fork 601
/
Copy pathmodule.ts
45 lines (38 loc) · 999 Bytes
/
module.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
import type { Plugin } from 'rollup';
import { createFilter } from '@rollup/pluginutils';
import type { Options as SWCOptions } from '@swc/core';
import { transform } from '@swc/core';
import { merge } from 'smob';
import type { Options } from './type';
export function swc(input: Options = {}): Plugin {
const filter = createFilter(input.include, input.exclude);
const defaults: SWCOptions = {
jsc: {
target: 'es2020',
parser: {
syntax: 'typescript',
decorators: true
},
transform: {
decoratorMetadata: true,
legacyDecorator: true
},
loose: true
}
};
if (input.swc && input.swc.env) {
delete defaults.jsc?.target;
}
const swcOptions: SWCOptions = merge({}, input.swc || {}, defaults);
return {
name: 'swc',
transform(code, id) {
if (!filter(id)) return null;
return transform(code, {
...swcOptions,
sourceMaps: true,
filename: id
});
}
};
}