-
Notifications
You must be signed in to change notification settings - Fork 0
/
tsup.config.ts
91 lines (86 loc) · 1.88 KB
/
tsup.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
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
85
86
87
88
89
90
91
import { globSync } from 'glob';
// import { print } from 'q-i';
import { defineConfig, type Options } from 'tsup';
interface MyOptions extends Options {
d?: string
dtsOnly?: boolean
}
const TS_FILES_WITHOUT_TESTS = globSync(`./**/*.ts`, {
absolute: false,
ignore: [
'build/**',
'docs/**',
'node_modules/**',
'test/**',
'**/*.d.ts',
'tsup.config.ts'
]
}).map(dir => dir.replace(/\\/g,'/'));
export default defineConfig((options: MyOptions) => {
// print(options, { maxItems: Infinity });
if (options.dtsOnly) {
return {
entry: ['index.ts'],
outDir: '.'
};
} else if (options.d === 'build/tsup') {
return {
entry: TS_FILES_WITHOUT_TESTS,
minify: false,
platform: 'node',
sourcemap: false,
target: 'esnext',
tsconfig: 'tsconfig.json'
};
} else if (options.d === 'build/tsup/test') {
const TESTS = globSync(`./test/**/*.ts`, {
absolute: false,
ignore: [
'**/*.d.ts',
]
}).map(dir => dir.replace(/\\/g,'/'));
// print(TESTS, { maxItems: Infinity });
return {
entry: TESTS,
minify: false,
d: 'build/tsup/test',
// external: [
// '@enonic/js-utils'
// ],
outDir: 'build/tsup/test',
paths: {
"@enonic/js-utils": ["build/tsup"],
"@enonic/js-utils/*": ["build/tsup/*"],
},
platform: 'node',
sourcemap: false,
target: 'esnext',
tsconfig: 'test/tsconfig.json'
};
} else if (options.d === 'dist/cjs') {
return {
entry: TS_FILES_WITHOUT_TESTS,
format: 'cjs',
minify: false,
platform: 'neutral',
target: 'es5',
sourcemap: false,
};
} else if (options.d === 'dist/esm') {
return {
entry: TS_FILES_WITHOUT_TESTS,
format: 'esm',
minify: false,
outExtension() {
return {
js: '.mjs'
}
},
platform: 'neutral',
target: 'es2015',
splitting: false, // avoid chunk files
sourcemap: false,
};
}
throw new Error(`Unconfigured directory:${options.d}!`)
});