-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathtsup.config.ts
More file actions
55 lines (51 loc) · 1.82 KB
/
Copy pathtsup.config.ts
File metadata and controls
55 lines (51 loc) · 1.82 KB
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
import type {Plugin} from 'esbuild';
import {defineConfig} from 'tsup';
// Modules whose code paths are unreachable in our usage. Resolving them to
// an empty module saves ~700KB:
// - `@babel/preset-typescript`: loaded by @babel/core for `.cts` configs
// (we always pass configFile: false).
// - `esprima`: recast's tokenizer fallback when AST has no `tokens`; our
// `@babel/parser`-based recast parser always provides them.
// - `browserslist`: required by @babel/helper-compilation-targets; never
// invoked since we set `browserslistConfigFile: false`.
const namespace = 'stub-unreachable-modules';
const pattern = /^@babel\/preset-typescript(\/.*)?$|^esprima$|^browserslist$/;
const stubUnreachableModules: Plugin = {
name: namespace,
setup(build) {
build.onResolve(
{filter: pattern},
args => ({path: args.path, namespace}),
);
build.onLoad(
{filter: /.*/, namespace},
() => ({contents: 'module.exports = {};', loader: 'js'}),
);
},
};
export default defineConfig({
entry: {
index: 'src/program.ts',
},
format: 'esm',
target: 'esnext',
platform: 'node',
clean: true,
sourcemap: false,
minify: true,
outDir: 'build',
treeshake: true,
// Bundle every dependency into the output so consumers don't get
// anything installed transitively (avoids version conflicts in host projects).
noExternal: [/.*/],
esbuildPlugins: [stubUnreachableModules],
banner: ({format}) => {
if (format === 'esm') {
return ({
// Shim for the `require` function in ESM to fix commander.js import
js: 'import { createRequire } from \'module\'; const require = createRequire(import.meta.url);',
});
}
return {};
},
});