-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtsup.config.ts
63 lines (55 loc) · 1.51 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
import { Options, defineConfig } from 'tsup';
import postcss from 'esbuild-postcss';
import { solidPlugin } from 'esbuild-plugin-solid';
let watching = false;
function generateConfig({ ssr, jsx }: { ssr: boolean; jsx: boolean }): Options {
const plugins = [postcss()];
if (!jsx) {
plugins.push(solidPlugin({ solid: { generate: ssr ? 'ssr' : 'dom' } }));
}
const format = 'esm';
return {
target: ssr ? 'node18' : 'esnext',
platform: ssr ? 'node' : 'browser',
clean: !watching,
dts: format === 'esm' && !jsx,
sourcemap: true,
format: ['esm', 'cjs'],
entry: ssr
? {
server: 'src/index.tsx'
}
: {
browser: 'src/index.tsx'
},
esbuildOptions(options) {
if (jsx) {
options.jsx = 'preserve';
}
},
outExtension: (context) => {
const result: ReturnType<Exclude<Options['outExtension'], undefined>> =
{};
if (jsx) {
result['js'] = '.jsx';
} else if (context.format === 'cjs') {
result['js'] = '.cjs';
}
return result;
},
external: [/solid-js(\/.*)?/],
outDir: 'dist/',
treeshake: { preset: 'smallest' },
replaceNodeEnv: true,
esbuildPlugins: plugins
};
}
export default defineConfig((opts) => {
watching = typeof opts.watch !== 'undefined';
return [
generateConfig({ ssr: false, jsx: false }),
generateConfig({ ssr: false, jsx: true }),
generateConfig({ ssr: true, jsx: false }),
generateConfig({ ssr: true, jsx: true })
];
});