-
-
Notifications
You must be signed in to change notification settings - Fork 53
Expand file tree
/
Copy pathbuild-components.cjs
More file actions
33 lines (29 loc) · 1.02 KB
/
build-components.cjs
File metadata and controls
33 lines (29 loc) · 1.02 KB
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
// build-components.js
const esbuild = require('esbuild');
const fs = require('fs');
const path = require('path');
const componentsPath = path.resolve(__dirname, 'src/components/ui');
const outDir = path.resolve(__dirname, 'dist/temp-cleanup');
if (!fs.existsSync(outDir)) fs.mkdirSync(outDir, { recursive: true });
const components = fs.readdirSync(componentsPath)
.filter((file) => fs.statSync(path.join(componentsPath, file)).isDirectory());
Promise.all(components.map(component => {
const entry = path.join(componentsPath, component, `${component}.tsx`);
const outfile = path.join(outDir, `${component}.js`);
return esbuild.build({
entryPoints: [entry],
outfile,
bundle: true,
format: 'esm',
minify: true,
external: ['react', 'react-dom', 'react/jsx-runtime'],
banner: { js: `'use client';` },
sourcemap: false,
// Add more esbuild options as needed
});
})).then(() => {
console.log('All components built with esbuild!');
}).catch((err) => {
console.error(err);
process.exit(1);
});