-
Notifications
You must be signed in to change notification settings - Fork 73
/
tsup.config.ts
67 lines (65 loc) · 2.11 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
import { defineConfig, Options } from 'tsup'
import { esbuildPluginFilePathExtensions } from 'esbuild-plugin-file-path-extensions'
// Inspired by https://github.com/immerjs/immer/pull/1032/files
export default defineConfig((options) => {
const commonOptions: Partial<Options> = {
entry: ['src/**/*.[jt]s', '!./src/**/*.d.ts', '!./src/**/*.spec.[jt]s'],
platform: 'node',
target: 'node16',
// `splitting` should be false, it ensures we are not getting any `chunk-*` files in the output.
splitting: false,
// `bundle` should be false, it ensures we are not getting the entire bundle in EVERY file of the output.
bundle: false,
// `sourcemap` should be true, we want to be able to point users back to the original source.
sourcemap: true,
clean: true,
...options,
}
const productionOptions = {
minify: true,
define: {
'process.env.NODE_ENV': JSON.stringify('production'),
},
}
return [
// ESM, standard bundler dev, embedded `process` references.
// (this is consumed by ["exports" > "." > "import"] and ["exports > "." > "types"] in package.json)
{
...commonOptions,
format: ['esm'],
clean: true,
outDir: './dist/esm/',
esbuildPlugins: [esbuildPluginFilePathExtensions({ filter: /^\./ })],
// Yes, bundle: true => https://github.com/favware/esbuild-plugin-file-path-extensions?tab=readme-ov-file#usage
bundle: true,
dts: {
compilerOptions: {
resolveJsonModule: false,
outDir: './dist',
},
},
},
// ESM for use in browsers. Minified, with `process` compiled away
{
...commonOptions,
...productionOptions,
// `splitting` should be true (revert to the default)
splitting: true,
// `bundle` should be true, so we get everything in one file.
bundle: true,
entry: {
'mappersmith.production.min': 'src/index.ts',
},
platform: 'browser',
format: ['esm'],
outDir: './dist/browser/',
},
// CJS
{
...commonOptions,
clean: true,
format: ['cjs'],
outDir: './dist/',
},
]
})