-
Notifications
You must be signed in to change notification settings - Fork 248
/
tsup.config.ts
66 lines (62 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
/**
* This configuration ensures that the prebuilt Yoga (asm.js) is not included in
* the WASM bundle.
*/
import { defineConfig } from 'tsup'
import { join } from 'path'
import { replace } from 'esbuild-plugin-replace'
export default defineConfig({
entry: ['src/index.ts'],
splitting: false,
sourcemap: true,
target: 'node16',
dts: process.env.NODE_ENV !== 'development' && {
resolve: ['twrnc', './tw-config', './types'],
},
minify: process.env.NODE_ENV !== 'development',
format: ['esm', 'cjs'],
noExternal: ['twrnc', 'emoji-regex'],
esbuildOptions(options) {
if (process.env.WASM) {
options.outExtension = {
'.js': `.wasm.${options.format === 'cjs' ? 'cjs' : 'js'}`,
}
}
options.tsconfig = process.env.WASM ? 'tsconfig.wasm.json' : 'tsconfig.json'
options.legalComments = 'external'
},
esbuildPlugins: [
{
name: 'optimize tailwind',
setup(build) {
// Get rid of chalk
// https://github.com/tailwindlabs/tailwindcss/blob/b8cda161dd0993083dcef1e2a03988c70be0ce93/src/util/log.js
build.onResolve({ filter: /\/log$/ }, (args) => {
if (args.importer.includes('/tailwindcss/')) {
return {
path: join(__dirname, 'src', 'vendor', 'twrnc', 'log.js'),
}
}
})
// Get rid of picocolors
// https://github.com/tailwindlabs/tailwindcss/blob/bf4494104953b13a5f326b250d7028074815e77e/src/featureFlags.js
build.onResolve({ filter: /^picocolors$/ }, () => {
return {
path: join(__dirname, 'src', 'vendor', 'twrnc', 'picocolors.js'),
}
})
// Get rid of util-deprecate/node.js
build.onResolve({ filter: /util-deprecate/ }, () => {
return {
path: join(__dirname, 'src', 'vendor', 'twrnc', 'deprecate.js'),
}
})
},
},
// We don't like `Function`.
// https://github.com/tailwindlabs/tailwindcss/blob/bf4494104953b13a5f326b250d7028074815e77e/src/util/getAllConfigs.js#L8
replace({
'preset instanceof Function': 'typeof preset === "function"',
}),
],
})