/
add-swc-config.ts
44 lines (40 loc) · 1 KB
/
add-swc-config.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
// TODO(chau): change back to 2015 when https://github.com/swc-project/swc/issues/1108 is solved
// target: 'es2015'
import { Tree } from '@nrwl/devkit';
import { join } from 'path';
export const defaultExclude = [
'.*.spec.tsx?$',
'.*.test.tsx?$',
'./src/jest-setup.ts$',
'./**/jest-setup.ts$',
'.*.js$',
];
const swcOptionsString = () => `{
"jsc": {
"target": "es2017",
"parser": {
"syntax": "typescript",
"decorators": true,
"dynamicImport": true
},
"transform": {
"decoratorMetadata": true,
"legacyDecorator": true
},
"keepClassNames": true,
"externalHelpers": true,
"loose": true
},
"module": {
"type": "commonjs",
"strict": true,
"noInterop": true
},
"sourceMaps": true,
"exclude": ${JSON.stringify(defaultExclude)}
}`;
export function addSwcConfig(tree: Tree, projectDir: string) {
const swcrcPath = join(projectDir, '.lib.swcrc');
if (tree.exists(swcrcPath)) return;
tree.write(swcrcPath, swcOptionsString());
}