| 47 | } |
| 48 | |
| 49 | async function buildTarget(targetName) { |
| 50 | const { entry, output, staticDir, styleLayers } = TARGETS[targetName]; |
| 51 | const outputPath = path.join(projectRoot, output); |
| 52 | const outputDir = path.dirname(outputPath); |
| 53 | |
| 54 | await fs.mkdir(outputDir, { recursive: true }); |
| 55 | |
| 56 | for (const fileName of STATIC_FILES) { |
| 57 | await fs.copyFile( |
| 58 | path.join(projectRoot, staticDir, fileName), |
| 59 | path.join(outputDir, fileName) |
| 60 | ); |
| 61 | } |
| 62 | |
| 63 | const styles = await Promise.all( |
| 64 | styleLayers.map((layerPath) => fs.readFile(path.join(projectRoot, layerPath), 'utf8')) |
| 65 | ); |
| 66 | await fs.writeFile(path.join(outputDir, 'styles.css'), `${styles.join('\n\n')}\n`, 'utf8'); |
| 67 | |
| 68 | await build({ |
| 69 | entryPoints: [path.join(projectRoot, entry)], |
| 70 | bundle: true, |
| 71 | format: 'iife', |
| 72 | platform: 'browser', |
| 73 | target: ['es2020'], |
| 74 | outfile: outputPath, |
| 75 | minify: true, |
| 76 | sourcemap: false |
| 77 | }); |
| 78 | } |
| 79 | |
| 80 | async function main() { |
| 81 | for (const targetName of selectedTargets) { |