forked from vercel/storage
-
Notifications
You must be signed in to change notification settings - Fork 0
/
tsup.config.js
49 lines (45 loc) · 1.48 KB
/
tsup.config.js
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
import fs from 'node:fs/promises';
import { defineConfig } from 'tsup';
// eslint-disable-next-line import/no-default-export
export default defineConfig({
entry: ['src/index.ts'],
format: ['esm', 'cjs'],
splitting: true,
sourcemap: false,
minify: true,
clean: true,
skipNodeModulesBundle: true,
dts: true,
external: ['node_modules'],
// We use the join() trick in index.ts to avoid this warning of the Edge Runtime
// A Node.js module is loaded ('fs/promises' at line 1) which is not supported in the Edge Runtime.
//
// However, this leads to a new warning, as the join() s a dynamic require:
// Critical dependency: the request of a dependency is an expression
//
// So we silence that warning by adding a /* webpackIgnore: true */
// comment onto the completed build output.
//
// This should now make the library usable without any warnings at all.
onSuccess: async () => {
// replace in esm bundle
const esmPath = './dist/index.js';
const cjsPath = './dist/index.cjs';
const [esmContent, cjsContent] = await Promise.all([
fs.readFile(esmPath, 'utf-8'),
fs.readFile(cjsPath, 'utf-8'),
]);
await Promise.all([
// replace in esm bundle
fs.writeFile(
esmPath,
esmContent.replace('import(', 'import(/* webpackIgnore: true */'),
),
// replace in cjs bundle
fs.writeFile(
cjsPath,
cjsContent.replace('require(', 'require(/* webpackIgnore: true */'),
),
]);
},
});