Skip to content

Commit 9d49ead

Browse files
committed
feat(build): unify export strategy across ESM, UMD, and CJS builds
Resolves #310 by aligning UMD and CJS builds with the ESM export strategy. All core classes are now exported consistently across all formats. Additionally, all CJS output files suffixes are now `.cjs` for better compatibility. The UMD build now exposes a unified namespace (`srgssr`) on the global scope, making all business classes accessible via CDN through a single file. To integrate it, simply import the script: ```html <script src="https://cdn.jsdelivr.net/npm/@srgssr/pillarbox-web@1.23.0/dist/pillarbox.umd.min.js"> </script> <script> const { DataProvider, MediaComposition, PillarboxMonitoring, Player, SRGAnalytics, SrgSsr } = window.srgssr; // Use Pillarbox as needed </script> ``` `window.pillarbox` and `window.videojs` are also exposed through this bundle allowing extensions to be integrated easily.
1 parent 3f3098c commit 9d49ead

10 files changed

+175
-137
lines changed

README.md

Lines changed: 35 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,12 +38,43 @@ Import the CSS file in your HTML to apply Pillarbox default theme:
3838
Finally, import Pillarbox and set up the player:
3939

4040
```javascript
41-
import Pillarbox from '@srgssr/pillarbox-web';
41+
import pillarbox from '@srgssr/pillarbox-web';
4242

43-
const player = new Pillarbox('my-player', {/* options... */ });
43+
const player = pillarbox('my-player', {/* options... */ });
4444
player.src({ src: 'urn:swi:video:48115940', type: 'srgssr/urn' });
4545
```
4646

47+
## CDN Integration
48+
49+
Pillarbox is an open-source project published as a public NPM package. You can easily include it in
50+
your website using a public CDN that proxies NPM packages—such as [jsDelivr][js-deliver].
51+
52+
To integrate Pillarbox Web via CDN, you can include it in your HTML like this:
53+
54+
```html
55+
<!-- It's recommended to specify an exact version in production.
56+
For example: https://cdn.jsdelivr.net/npm/@srgssr/pillarbox-web@{version}/dist/pillarbox.umd.min.js
57+
In this example, we use the latest version for simplicity. -->
58+
<script src="https://cdn.jsdelivr.net/npm/@srgssr/pillarbox-web/dist/pillarbox.umd.min.js"></script>
59+
<!-- Load additional plugins or extensions after Pillarbox -->
60+
<script>
61+
// Example usage:
62+
const player = pillarbox('my-player', {/* options... */ });
63+
player.src({ src: 'urn:swi:video:48115940', type: 'srgssr/urn' });
64+
65+
// Other classes and utilities available under `window.srgssr`:
66+
// DataProvider, MediaComposition, PillarboxMonitoring, Player, SRGAnalytics, SrgSsr
67+
</script>
68+
```
69+
70+
You can also use a different CDN or host the file yourself.
71+
72+
> [!NOTE]
73+
> When using the UMD build via CDN, video.js is already bundled with Pillarbox.
74+
> You should not include it separately.
75+
> The UMD bundle also exposes `video.js` as a global variable, allowing you to use both and internal
76+
> extensions as needed.
77+
4778
## Documentation
4879

4980
For detailed information on how to use the Pillarbox Web Player, checkout
@@ -122,3 +153,5 @@ See the [LICENSE](LICENSE) file for more information.
122153
[token-settings]: https://github.com/settings/tokens
123154

124155
[token-guide]: https://docs.github.com/en/packages/working-with-a-github-packages-registry/working-with-the-npm-registry#authenticating-with-a-personal-access-token
156+
157+
[js-deliver]: https://www.jsdelivr.com/package/npm/@srgssr/pillarbox-web
File renamed without changes.

build.umd.js

Lines changed: 0 additions & 5 deletions
This file was deleted.

package-lock.json

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

package.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,17 @@
44
"version": "1.22.0",
55
"type": "module",
66
"module": "dist/pillarbox.es.js",
7-
"main": "dist/pillarbox.cjs.js",
7+
"main": "dist/pillarbox.cjs",
88
"style": "./dist/pillarbox.min.css",
9-
"types": "./dist/types/build.es.d.ts",
9+
"types": "./dist/types/build.d.ts",
1010
"exports": {
1111
".": {
1212
"import": "./dist/pillarbox.es.js",
13-
"require": "./dist/pillarbox.cjs.js"
13+
"require": "./dist/pillarbox.cjs"
1414
},
1515
"./core": {
1616
"import": "./dist/pillarbox-core.es.js",
17-
"require": "./dist/pillarbox-core.cjs.js"
17+
"require": "./dist/pillarbox-core.cjs"
1818
},
1919
"./*": "./*"
2020
},

tsconfig.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
*
88
* Usage: npx -p typescript tsc
99
*/
10-
"include": ["build.es.js"],
10+
"include": ["build.js"],
1111
"compilerOptions": {
1212
"allowJs": true,
1313
"declaration": true,

vite.config.cjs.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,13 @@ export default defineConfig({
99
lib: {
1010
formats: ['cjs'],
1111
name: 'pillarbox',
12-
entry: './build.umd.js'
12+
entry: './build.js'
1313
},
1414
rollupOptions: {
1515
external: ['video.js', 'videojs-contrib-eme'],
1616
output: {
17-
entryFileNames: 'pillarbox.cjs.js'
17+
entryFileNames: 'pillarbox.cjs',
18+
exports: 'named'
1819
},
1920
plugins: [babel({
2021
babelHelpers: 'bundled',

vite.config.core.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ export default defineConfig({
1919
},
2020
{
2121
format: 'cjs',
22-
entryFileNames: '[name]-core.cjs.js'
22+
entryFileNames: '[name]-core.cjs'
2323
}
2424
],
2525
plugins: [babel({

vite.config.es.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ export default defineConfig({
99
lib: {
1010
formats: ['es'],
1111
name: 'pillarbox',
12-
entry: './build.es.js'
12+
entry: './build.js'
1313
},
1414
rollupOptions: {
1515
external: ['video.js', 'videojs-contrib-eme'],

vite.config.umd.js

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,27 +2,36 @@ import { defineConfig } from 'vite';
22
import babel from '@rollup/plugin-babel';
33
import terser from '@rollup/plugin-terser';
44

5+
const outroScript = `
6+
window.pillarbox = pillarbox;
7+
window.videojs = window.pillarbox;
8+
`.trim();
9+
510
export default defineConfig({
611
esbuild: false,
712
build: {
813
sourcemap: true,
914
emptyOutDir: false,
1015
lib: {
1116
name: 'pillarbox',
12-
entry: './build.umd.js'
17+
entry: './build.js'
1318
},
1419
rollupOptions: {
1520
output: [
1621
{
17-
name: 'Pillarbox',
22+
name: 'srgssr',
1823
entryFileNames: 'pillarbox.umd.min.js',
24+
exports: 'named',
1925
format: 'umd',
26+
outro: outroScript,
2027
plugins: [terser()]
2128
},
2229
{
23-
name: 'Pillarbox',
30+
name: 'srgssr',
2431
entryFileNames: 'pillarbox.umd.js',
32+
exports: 'named',
2533
format: 'umd',
34+
outro: outroScript,
2635
}
2736
],
2837
plugins: [babel({

0 commit comments

Comments
 (0)