Skip to content
This repository was archived by the owner on Jan 15, 2025. It is now read-only.

Commit 8b901bb

Browse files
committed
feat: optimizing performance (wip)
1 parent 86721dd commit 8b901bb

File tree

2 files changed

+38
-0
lines changed

2 files changed

+38
-0
lines changed

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
],
88
"scripts": {
99
"build": "turbo run build",
10+
"build:packages": "turbo run build --filter='./packages/*'",
1011
"changeset": "changeset",
1112
"clean": "turbo run clean",
1213
"dev": "turbo run dev",

packages/ui/tsup.config.ts

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,49 @@
1+
import * as fs from 'node:fs/promises';
2+
import * as path from 'node:path';
13
import type { Options } from 'tsup';
24
import { defineConfig } from 'tsup';
35

6+
const DIST_PATH = './dist';
7+
8+
async function addDirectivesToChunkFiles(distPath = DIST_PATH): Promise<void> {
9+
try {
10+
const files = await fs.readdir(distPath);
11+
12+
for (const file of files) {
13+
if (
14+
file.startsWith('chunk-') &&
15+
(file.endsWith('.mjs') || file.endsWith('.js'))
16+
) {
17+
const filePath = path.join(distPath, file);
18+
19+
// eslint-disable-next-line no-await-in-loop -- We need to wait for each file to be read
20+
const data = await fs.readFile(filePath, 'utf8');
21+
22+
const updatedContent = `'use client';\n${data}`;
23+
24+
// eslint-disable-next-line no-await-in-loop -- We need to wait for each file to be written
25+
await fs.writeFile(filePath, updatedContent, 'utf8');
26+
27+
// eslint-disable-next-line no-console -- We need to log the result
28+
console.log(`Directive has been added to ${file}`);
29+
}
30+
}
31+
} catch (err) {
32+
// eslint-disable-next-line no-console -- We need to log the error
33+
console.error('Error:', err);
34+
}
35+
}
36+
437
export default defineConfig((options: Options) => ({
538
clean: !options.watch,
639
dts: true,
740
entry: ['src/**/*.tsx'],
841
external: ['react'],
942
format: ['esm', 'cjs'],
43+
async onSuccess() {
44+
await addDirectivesToChunkFiles();
45+
},
46+
outDir: DIST_PATH,
1047
sourcemap: true,
1148
splitting: true,
1249
target: 'esnext',

0 commit comments

Comments
 (0)