|
| 1 | +/** |
| 2 | + * Build configuration resolver |
| 3 | + * |
| 4 | + * Resolves a build entry from `targetMap` based on `BUILD_TARGET`, |
| 5 | + * defaulting to "default". Each entry defines `entry`, `output`, |
| 6 | + * `outDir`, and UMD/global `name`. Unknown targets throw an error. |
| 7 | + * |
| 8 | + * Usage: |
| 9 | + * import { entry, output, outDir, name } from './build.config.js'; |
| 10 | + */ |
| 11 | +import { env } from 'node:process'; |
| 12 | + |
| 13 | +/** |
| 14 | + * Adding a new build target: |
| 15 | + * 1. Add an entry to `targetMap` with the desired configuration. |
| 16 | + * 2. Define the npm scripts prefixed with `build:` in your `package.json` |
| 17 | + * for building the new target. |
| 18 | + * ``` |
| 19 | + * BUILD_TARGET=${target_name} vite build --config vite.config.lib.js |
| 20 | + * BUILD_TARGET=${target_name} vite build --config vite.config.lib.js |
| 21 | + * ``` |
| 22 | + * 3. Run all build targets automatically using the helper script: `npm run build`. |
| 23 | + * The script discovers all `build:*` scripts in your package.json and runs |
| 24 | + * them sequentially, no manual aggregation is needed. |
| 25 | + */ |
| 26 | +const targetMap = { |
| 27 | + default: { |
| 28 | + entry: 'src/pillarbox-playlist.js', |
| 29 | + output: 'pillarbox-playlist', |
| 30 | + outDir: 'dist', |
| 31 | + name: 'PillarboxPlaylist' |
| 32 | + }, |
| 33 | + ui: { |
| 34 | + entry: 'src/pillarbox-playlist-ui.js', |
| 35 | + output: 'pillarbox-playlist-ui', |
| 36 | + outDir: 'dist/ui', |
| 37 | + name: 'PillarboxPlaylistUI' |
| 38 | + } |
| 39 | +}; |
| 40 | + |
| 41 | +const target = env.BUILD_TARGET ?? 'default'; |
| 42 | + |
| 43 | +if (!(target in targetMap)) { |
| 44 | + throw new Error(`Unknown build target: "${target}". Valid options are: ${Object.keys(targetMap).join(', ')}`); |
| 45 | +} |
| 46 | + |
| 47 | +export const { entry, output, outDir, name } = targetMap[target]; |
| 48 | + |
0 commit comments