-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtsup.config.ts
39 lines (35 loc) · 1.02 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
import { defineConfig } from 'tsup'
import {buildSync, Plugin} from "esbuild";
import path from "path";
const filter = /\?raw/
const namespace = '_' + Math.random().toString(36).substring(2, 9)
const raw: Plugin = {
name: 'inline-plugin',
setup(build) {
build.onResolve({ filter }, args => {
const realPath = args.path.replace(filter, '');
return {
path: path.resolve(args.resolveDir, realPath),
namespace,
};
});
build.onLoad({ filter: /.*/, namespace }, async args => {
const [result] = buildSync({
write: false,
entryPoints: [args.path],
bundle: true,
splitting: false,
}).outputFiles;
return {
contents: result.text,
loader: 'text'
};
});
}
};
export default defineConfig({
esbuildPlugins: [raw],
entry: ['src/index.ts'],
dts: true,
format: ['cjs', 'esm'],
})