-
Notifications
You must be signed in to change notification settings - Fork 0
/
tsup.config.ts
46 lines (42 loc) · 1.17 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
import { Options, defineConfig } from 'tsup';
import fs from 'fs';
import path from 'path';
import childProcess from 'child_process';
const common: Options = {
treeshake: false,
sourcemap: 'inline',
minify: true,
clean: true,
dts: true,
splitting: false,
format: ['cjs', 'esm'],
external: ['react'],
injectStyle: false,
};
// eslint-disable-next-line @typescript-eslint/no-unused-vars
const addUseStatement = (basePath: string, type: 'server' | 'client') => {
const fullPath = path.join(__dirname, basePath);
const files = fs.readdirSync(fullPath);
files.forEach((file) => {
if (file.endsWith('.js') || file.endsWith('.mjs')) {
const filePath = path.join(fullPath, file);
let content = fs.readFileSync(filePath, 'utf-8');
content = `"use ${type}";\n${content}`;
fs.writeFileSync(filePath, content, 'utf-8');
}
});
};
export default defineConfig({
entry: [
'src/index.ts',
'src/server/index.ts',
'src/react/index.ts',
'src/styles.css',
],
async onSuccess() {
addUseStatement('dist/react', 'client');
childProcess.execSync('pnpm link:self');
console.log('🖇️ Linked package');
},
...common,
});