@@ -11,16 +11,27 @@ import esbuildPlugin from 'rollup-plugin-esbuild';
1111
1212const MODE_WATCH = process . argv . includes ( '-w' ) ,
1313 MODE_TYPES = process . argv . includes ( '--config-types' ) ,
14- MODE_CDN = process . argv . includes ( '--config-cdn' ) ;
14+ MODE_CDN = process . argv . includes ( '--config-cdn' ) ,
15+ MODE_PLUGINS = process . argv . includes ( '--config-plugins' ) ;
1516
1617/** @type {Record<string, string | false> } */
1718const MANGLE_CACHE = ! MODE_TYPES ? await buildMangleCache ( ) : { } ;
1819
1920const NPM_EXTERNAL_PACKAGES = [ 'hls.js' , 'media-captions' , 'media-icons' ] ,
2021 CDN_EXTERNAL_PACKAGES = [ 'media-captions' , 'media-icons' ] ,
21- NPM_BUNDLES = [ define ( { type : 'server' } ) , define ( { type : 'dev' } ) , define ( { type : 'prod' } ) ] ,
22- CDN_BUNDLES = [ defineCDN ( { dev : true } ) , defineCDN ( ) , defineCDN ( { layouts : true } ) ] ,
23- TYPES_BUNDLES = defineTypes ( ) ;
22+ PLUGINS_EXTERNAL_PACKAGES = [ 'vite' , 'rollup' , / w e b p a c k / , / r s p a c k / , 'esbuild' , 'unplugin' ] ,
23+ NPM_BUNDLES = [
24+ defineNPMBundle ( { type : 'server' } ) ,
25+ defineNPMBundle ( { type : 'dev' } ) ,
26+ defineNPMBundle ( { type : 'prod' } ) ,
27+ ] ,
28+ CDN_BUNDLES = [
29+ defineCDNBundle ( { dev : true } ) ,
30+ defineCDNBundle ( ) ,
31+ defineCDNBundle ( { layouts : true } ) ,
32+ ] ,
33+ PLUGIN_BUNDLES = definePluginsBundle ( ) ,
34+ TYPES_BUNDLES = defineTypesBundle ( ) ;
2435
2536// Styles
2637if ( ! MODE_TYPES ) {
@@ -36,19 +47,21 @@ if (!MODE_TYPES) {
3647}
3748
3849export default defineConfig (
39- MODE_CDN
40- ? CDN_BUNDLES
41- : MODE_WATCH
42- ? [ ...NPM_BUNDLES , ...TYPES_BUNDLES ]
43- : MODE_TYPES
44- ? TYPES_BUNDLES
45- : [ ...NPM_BUNDLES , ...CDN_BUNDLES ] ,
50+ MODE_PLUGINS
51+ ? PLUGIN_BUNDLES
52+ : MODE_CDN
53+ ? CDN_BUNDLES
54+ : MODE_WATCH
55+ ? [ ...NPM_BUNDLES , ...TYPES_BUNDLES ]
56+ : MODE_TYPES
57+ ? TYPES_BUNDLES
58+ : [ ...NPM_BUNDLES , ...CDN_BUNDLES , ...PLUGIN_BUNDLES ] ,
4659) ;
4760
4861/**
4962 * @returns {import('rollup').RollupOptions[] }
5063 * */
51- function defineTypes ( ) {
64+ function defineTypesBundle ( ) {
5265 /** @type {Record<string, string> } */
5366 const input = {
5467 index : 'types/index.d.ts' ,
@@ -90,6 +103,12 @@ function defineTypes() {
90103 } ,
91104 ] ,
92105 } ,
106+ {
107+ input : 'types/plugins.d.ts' ,
108+ output : { file : 'plugins.d.ts' } ,
109+ external : PLUGINS_EXTERNAL_PACKAGES ,
110+ plugins : [ dts ( { respectExternal : true } ) ] ,
111+ } ,
93112 ] ;
94113}
95114
@@ -105,7 +124,7 @@ function defineTypes() {
105124 * @param {BundleOptions }
106125 * @returns {import('rollup').RollupOptions }
107126 */
108- function define ( { target, type, minify } ) {
127+ function defineNPMBundle ( { target, type, minify } ) {
109128 /** @type {Record<string, string> } */
110129 let input = {
111130 vidstack : 'src/index.ts' ,
@@ -189,14 +208,14 @@ function define({ target, type, minify }) {
189208}
190209
191210/** @returns {import('rollup').RollupOptions } */
192- function defineCDN ( { dev = false , layouts = false } = { } ) {
211+ function defineCDNBundle ( { dev = false , layouts = false } = { } ) {
193212 const input =
194213 dev || layouts
195214 ? 'src/elements/bundles/cdn/player-with-layouts.ts'
196215 : 'src/elements/bundles/cdn/player.ts' ,
197216 output = dev ? `vidstack.dev` : `vidstack` ;
198217 return {
199- ...define ( {
218+ ...defineNPMBundle ( {
200219 type : dev ? 'dev' : 'prod' ,
201220 minify : ! dev ,
202221 target : 'es2020' ,
@@ -283,3 +302,29 @@ function getProviderInputs() {
283302 [ `providers/vidstack-google-cast` ] : 'src/providers/google-cast/provider.ts' ,
284303 } ;
285304}
305+
306+ /** @returns {import('rollup').RollupOptions[] } */
307+ function definePluginsBundle ( ) {
308+ return [
309+ {
310+ input : 'src/plugins.ts' ,
311+ output : { file : 'plugins.js' , format : 'esm' } ,
312+ external : PLUGINS_EXTERNAL_PACKAGES ,
313+ treeshake : true ,
314+ plugins : [
315+ nodeResolve ( ) ,
316+ esbuildPlugin ( {
317+ tsconfig : 'tsconfig.build.json' ,
318+ target : 'node18' ,
319+ platform : 'node' ,
320+ format : 'esm' ,
321+ // minify: true,
322+ legalComments : 'none' ,
323+ define : {
324+ __DEV__ : 'false' ,
325+ } ,
326+ } ) ,
327+ ] ,
328+ } ,
329+ ] ;
330+ }
0 commit comments