-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathesbuild.importmap.js
More file actions
51 lines (44 loc) · 1.22 KB
/
esbuild.importmap.js
File metadata and controls
51 lines (44 loc) · 1.22 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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
const esbuild = require('esbuild')
const fs = require('fs')
const path = require('path')
// Get all component files
const srcDir = path.join(__dirname, 'src')
const distDir = path.join(__dirname, 'dist/importmap')
// Ensure dist/importmap directory exists
if (!fs.existsSync(distDir)) {
fs.mkdirSync(distDir, { recursive: true })
}
// Get all component files
const componentFiles = fs
.readdirSync(srcDir)
.filter(file => file.startsWith('railsui_') && file.endsWith('.js'))
// Build each component individually without bundling
const buildPromises = componentFiles.map(file => {
const inputPath = path.join(srcDir, file)
const outputPath = path.join(distDir, file)
return esbuild.build({
entryPoints: [inputPath],
format: 'esm',
target: 'es2020',
outfile: outputPath,
sourcemap: true,
})
})
// Also build the index file
buildPromises.push(
esbuild.build({
entryPoints: [path.join(srcDir, 'index.js')],
format: 'esm',
target: 'es2020',
outfile: path.join(distDir, 'index.js'),
sourcemap: true,
})
)
Promise.all(buildPromises)
.then(() => {
console.log('✅ Importmap build complete!')
})
.catch(err => {
console.error('❌ Build failed:', err)
process.exit(1)
})