forked from Shopify/hydrogen
-
Notifications
You must be signed in to change notification settings - Fork 0
/
tsup.config.ts
32 lines (27 loc) · 962 Bytes
/
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
import path from 'path';
import fs from 'fs/promises';
import {defineConfig} from 'tsup';
export const entry = 'src/index.ts';
export const outDir = 'dist';
export const cjsEntryContent = `module.exports = process.env.NODE_ENV === 'development' ? require('./development/index.cjs') : require('./production/index.cjs');`;
export const cjsEntryFile = path.resolve(process.cwd(), outDir, 'index.cjs');
export const commonConfig = defineConfig({
entryPoints: [entry],
format: ['esm', 'cjs'],
treeshake: true,
sourcemap: true,
});
export const devConfig = defineConfig({
...commonConfig,
env: {NODE_ENV: 'development'},
outDir: path.join(outDir, 'development'),
});
export const prodConfig = defineConfig({
...commonConfig,
env: {NODE_ENV: 'production'},
dts: true,
outDir: path.join(outDir, 'production'),
minify: true,
onSuccess: () => fs.writeFile(cjsEntryFile, cjsEntryContent, 'utf-8'),
});
export default [devConfig, prodConfig];