-
-
Notifications
You must be signed in to change notification settings - Fork 3
/
tsup.config.ts
92 lines (88 loc) · 2.19 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
92
import { writeFile } from 'fs/promises';
import type { Options } from 'tsup';
import { defineConfig } from 'tsup';
export default defineConfig(options => {
const commonOptions: Options = {
entry: {
'numeric-quantity': 'src/index.ts',
},
sourcemap: true,
dts: true,
...options,
};
const productionOptions: Options = {
minify: true,
replaceNodeEnv: true,
};
const opts: Options[] = [
// ESM, standard bundler dev, embedded `process` references
{
...commonOptions,
clean: true,
format: 'esm',
},
// ESM, Webpack 4 support. Target ES2017 syntax to compile away optional chaining and spreads
{
...commonOptions,
entry: {
'numeric-quantity.legacy-esm': 'src/index.ts',
},
// ESBuild outputs `'.mjs'` by default for the 'esm' format. Force '.js'
outExtension: () => ({ js: '.js' }),
format: 'esm',
target: 'es2017',
},
// ESM for use in browsers. Minified, with `process` compiled away
{
...commonOptions,
...productionOptions,
entry: {
'numeric-quantity.production': 'src/index.ts',
},
format: 'esm',
outExtension: () => ({ js: '.mjs' }),
},
// CJS development
{
...commonOptions,
entry: {
'numeric-quantity.cjs.development': 'src/index.ts',
},
format: 'cjs',
outDir: './dist/cjs/',
},
// CJS production
{
...commonOptions,
...productionOptions,
entry: {
'numeric-quantity.cjs.production': 'src/index.ts',
},
format: 'cjs',
outDir: './dist/cjs/',
onSuccess: async () => {
// Write the CJS index file
await writeFile(
'dist/cjs/index.js',
`'use strict';
if (process.env.NODE_ENV === 'production') {
module.exports = require('./numeric-quantity.cjs.production.js');
} else {
module.exports = require('./numeric-quantity.cjs.development.js');
}
`
);
},
},
// UMD (ish)
{
...commonOptions,
...productionOptions,
dts: false,
format: 'iife',
globalName: 'NumericQuantity',
outExtension: () => ({ js: '.umd.min.js' }),
},
];
return opts;
});