forked from CyberAgentHack/web-speed-hackathon-2024
/
tsup.config.ts
67 lines (62 loc) · 1.8 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
67
import fs from 'node:fs';
import path from 'node:path';
import { pnpmWorkspaceRoot as findWorkspaceDir } from '@node-kit/pnpm-workspace-root';
import { polyfillNode } from 'esbuild-plugin-polyfill-node';
import findPackageDir from 'pkg-dir';
import { defineConfig } from 'tsup';
import type { Options } from 'tsup';
export default defineConfig(async (): Promise<Options[]> => {
const PACKAGE_DIR = (await findPackageDir(process.cwd()))!;
const WORKSPACE_DIR = (await findWorkspaceDir(process.cwd()))!;
const OUTPUT_DIR = path.resolve(PACKAGE_DIR, './dist');
const SEED_IMAGE_DIR = path.resolve(WORKSPACE_DIR, './workspaces/server/seeds/images');
const IMAGE_PATH_LIST = fs.readdirSync(SEED_IMAGE_DIR).map((file) => `/images/${file}`);
return [
{
bundle: true,
clean: true,
entry: {
client: path.resolve(PACKAGE_DIR, './src/index.tsx'),
serviceworker: path.resolve(PACKAGE_DIR, './src/serviceworker/index.ts'),
},
env: {
API_URL: '',
NODE_ENV: 'production',
PATH_LIST: IMAGE_PATH_LIST.join(',') || '',
},
esbuildOptions(options) {
options.define = {
...options.define,
global: 'globalThis',
};
options.publicPath = '/';
},
esbuildPlugins: [
polyfillNode({
globals: {
process: false,
},
polyfills: {
events: true,
fs: true,
path: true,
},
}),
],
format: 'iife',
loader: {
'.json?file': 'file',
'.wasm': 'binary',
},
metafile: true,
minify: true,
outDir: OUTPUT_DIR,
platform: 'browser',
shims: false,
sourcemap: false,
splitting: true,
target: ['chrome124'],
treeshake: false,
},
];
});