Skip to content

Commit 576d884

Browse files
committed
chore: add multi-target build system with run-all helper
Introduces a complete multi-target build system across the template and packages, simplifying and standardizing builds with multiple outputs. Changes include: - Updated `create` template: - Added `.build.config.js` defining the default build and instructions for adding new targets. - `vite.config.lib.js` and `vite.config.umd.js` now dynamically import the current build target from `.build.config.js` via the `BUILD_TARGET` environment variable. - The template now ships with multi-output builds by default. - Added `run-all` helper script: - Runs multiple npm scripts sharing the same prefix sequentially. - Deletes `dist` before starting builds. - Centralizes multi-script execution, removing the need to manually aggregate scripts. - Simplifies the workflow and reduces boilerplate in `package.json`. - Updated packages to use the new system: - `pillarbox-playlist` plugin now supports multi-output builds. - All package `build` scripts now leverage `run-all` to ensure consistent, simplified builds.
1 parent dc46202 commit 576d884

File tree

24 files changed

+891
-573
lines changed

24 files changed

+891
-573
lines changed

package-lock.json

Lines changed: 702 additions & 453 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/airplay-button/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
"player"
3434
],
3535
"scripts": {
36-
"build": "npm run build:lib && npm run build:umd && npm run build:css",
36+
"build": "node ../../scripts/run-all.js build",
3737
"build:css": "sass ./scss/airplay-button.scss:dist/airplay-button.min.css --style compressed --source-map --load-path node_modules",
3838
"build:lib": "vite build --config vite.config.lib.js",
3939
"build:umd": "vite build --config vite.config.umd.js",

packages/big-replay-button/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
"player"
3333
],
3434
"scripts": {
35-
"build": "npm run build:lib && npm run build:umd && npm run build:css",
35+
"build": "node ../../scripts/run-all.js build",
3636
"build:css": "sass ./scss/big-replay-button.scss:dist/big-replay-button.min.css --style compressed --source-map --load-path node_modules",
3737
"build:lib": "vite build --config vite.config.lib.js",
3838
"build:umd": "vite build --config vite.config.umd.js",

packages/brand-button/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
"player"
3333
],
3434
"scripts": {
35-
"build": "npm run build:lib && npm run build:umd && npm run build:css",
35+
"build": "node ../../scripts/run-all.js build",
3636
"build:css": "sass ./scss/brand-button.scss:dist/brand-button.min.css --style compressed --source-map --load-path node_modules",
3737
"build:lib": "vite build --config vite.config.lib.js",
3838
"build:umd": "vite build --config vite.config.umd.js",

packages/card/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
"player"
3333
],
3434
"scripts": {
35-
"build": "npm run build:lib && npm run build:umd && npm run build:css",
35+
"build": "node ../../scripts/run-all.js build",
3636
"build:css": "sass ./scss/card.scss:dist/card.min.css --style compressed --source-map --load-path node_modules",
3737
"build:lib": "vite build --config vite.config.lib.js",
3838
"build:umd": "vite build --config vite.config.umd.js",

packages/chapters-bar/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
"pillarbox"
3434
],
3535
"scripts": {
36-
"build": "npm run build:lib && npm run build:umd && npm run build:css",
36+
"build": "node ../../scripts/run-all.js build",
3737
"build:css": "sass ./scss/chapters-bar.scss:dist/chapters-bar.min.css --style compressed --source-map --load-path node_modules",
3838
"build:lib": "vite build --config vite.config.lib.js",
3939
"build:umd": "vite build --config vite.config.umd.js",

packages/google-cast-sender/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@
3838
"TV"
3939
],
4040
"scripts": {
41-
"build": "npm run build:lib && npm run build:umd && npm run build:css",
41+
"build": "node ../../scripts/run-all.js build",
4242
"build:css": "sass ./scss/google-cast-sender.scss:dist/google-cast-sender.min.css --style compressed --source-map --load-path node_modules",
4343
"build:lib": "vite build --config vite.config.lib.js",
4444
"build:umd": "vite build --config vite.config.umd.js",

packages/pillarbox-debug-panel/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
"player"
3333
],
3434
"scripts": {
35-
"build": "npm run build:lib && npm run build:umd && npm run build:css",
35+
"build": "node ../../scripts/run-all.js build",
3636
"build:css": "sass ./scss/pillarbox-debug-panel.scss:dist/pillarbox-debug-panel.min.css --style compressed --source-map --load-path node_modules",
3737
"build:lib": "vite build --config vite.config.lib.js",
3838
"build:umd": "vite build --config vite.config.umd.js",
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
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+

packages/pillarbox-playlist/package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,12 +40,12 @@
4040
"playlist"
4141
],
4242
"scripts": {
43-
"build": "npm run build:lib && npm run build:ui && npm run build:umd && npm run build:umd:ui && npm run build:css",
43+
"build": "node ../../scripts/run-all.js build",
4444
"build:css": "sass ./scss/pillarbox-playlist.scss:dist/pillarbox-playlist.min.css --style compressed --source-map --load-path node_modules",
4545
"build:lib": "vite build --config vite.config.lib.js",
4646
"build:umd": "vite build --config vite.config.umd.js",
47-
"build:umd:ui": "vite build --config vite.config.umd.ui.js",
48-
"build:ui": "vite build --config vite.config.ui.js",
47+
"build:ui": "BUILD_TARGET=ui vite build --config vite.config.lib.js",
48+
"build:umd:ui": "BUILD_TARGET=ui vite build --config vite.config.umd.js",
4949
"github:page": "vite build",
5050
"release:ci": "semantic-release",
5151
"start": " vite --port 4200 --open",

0 commit comments

Comments
 (0)