@@ -10,11 +10,16 @@ const {uglify} = require('rollup-plugin-uglify');
10
10
const { minify} = require ( 'uglify-es' ) ;
11
11
const pkg = require ( '../package.json' ) ;
12
12
13
- /* General Globals */
14
- const moduleName = 'videojsOverlay' ;
15
- const pluginName = 'videojs-overlay' ;
16
- const mainFile = 'src/plugin.js' ;
17
- const banner = `/*! @name ${ pkg . name } @version ${ pkg . version } @license ${ pkg . license } */` ;
13
+ /* to prevent going into a screen during rollup */
14
+ process . stderr . isTTY = false ;
15
+
16
+ let isWatch = false ;
17
+
18
+ process . argv . forEach ( ( a ) => {
19
+ if ( ( / - w | - - w a t c h / ) . test ( a ) ) {
20
+ isWatch = true ;
21
+ }
22
+ } ) ;
18
23
19
24
/* configuration for plugins */
20
25
const primedPlugins = {
@@ -36,19 +41,11 @@ const primedPlugins = {
36
41
uglify : uglify ( { output : { comments : 'some' } } , minify )
37
42
} ;
38
43
39
- // to prevent a screen during rollup watch/build
40
- process . stderr . isTTY = false ;
41
-
42
- let isWatch = false ;
43
-
44
- process . argv . forEach ( ( a ) => {
45
- if ( ( / - w | - - w a t c h / ) . test ( a ) ) {
46
- isWatch = true ;
47
- }
48
- } ) ;
44
+ /* General Globals */
45
+ const moduleName = 'videojsOverlay' ;
46
+ const pluginName = 'videojs-overlay' ;
49
47
50
- // globals, aka replace require calls
51
- // with this
48
+ // globals, aka replace require calls with this
52
49
const globals = {
53
50
umd : {
54
51
'video.js' : 'videojs' ,
@@ -67,15 +64,16 @@ const globals = {
67
64
}
68
65
} ;
69
66
70
- // externals, aka don't bundle there
71
- // and if not listed as a global don't require
72
- // them either
67
+ // externals, aka don't bundle these and if not
68
+ // listed as a global don't require them either
73
69
const externals = {
74
70
umd : Object . keys ( globals . umd ) . concat ( [
75
71
76
72
] ) ,
77
73
module : Object . keys ( globals . module ) . concat ( [
78
-
74
+ 'global' ,
75
+ 'global/document' ,
76
+ 'global/window'
79
77
] ) ,
80
78
test : Object . keys ( globals . test ) . concat ( [
81
79
@@ -85,16 +83,13 @@ const externals = {
85
83
/* plugins that should be used in each bundle with caveats as comments */
86
84
const plugins = {
87
85
// note uglify will be added before babel for minified bundle
88
- // see minPlugins below
89
86
umd : [
90
87
primedPlugins . resolve ,
91
88
primedPlugins . json ,
92
89
primedPlugins . commonjs ,
93
90
primedPlugins . babel
94
91
] ,
95
92
96
- // note babel will be removed for es module bundle
97
- // see esPlugins below
98
93
module : [
99
94
primedPlugins . resolve ,
100
95
primedPlugins . json ,
@@ -111,79 +106,78 @@ const plugins = {
111
106
]
112
107
} ;
113
108
114
- // clone module plugins, remove babel
115
- const esPlugins = plugins . module . slice ( ) ;
116
-
117
- esPlugins . splice ( plugins . module . indexOf ( primedPlugins . babel ) , 1 ) ;
118
-
119
- // clone umd plugins, remove babel, add uglify then babel
120
- const minPlugins = plugins . umd . slice ( ) ;
109
+ /* make a build with the specifed settings */
110
+ const makeBuild = ( name , settings ) => {
111
+ const b = Object . assign ( { } , {
112
+ plugins : plugins [ name ] ,
113
+ external : externals [ name ] ,
114
+ input : 'src/plugin.js'
115
+ } , settings ) ;
116
+
117
+ const fixOutput = ( o ) => {
118
+ if ( ! o . banner ) {
119
+ o . banner = `/*! @name ${ pkg . name } @version ${ pkg . version } @license ${ pkg . license } */` ;
120
+ }
121
+ if ( ! o . globals ) {
122
+ o . globals = globals [ name ] ;
123
+ }
124
+
125
+ return o ;
126
+ } ;
127
+
128
+ if ( ! Array . isArray ( b . output ) ) {
129
+ b . output = fixOutput ( b . output ) ;
130
+ } else {
131
+ b . output = b . output . map ( fixOutput ) ;
132
+ }
121
133
122
- minPlugins . splice ( plugins . umd . indexOf ( primedPlugins . babel ) , 1 ) ;
123
- minPlugins . push ( primedPlugins . uglify ) ;
124
- minPlugins . push ( primedPlugins . babel ) ;
134
+ return b ;
135
+ } ;
125
136
126
- const builds = [ {
127
- // umd
128
- input : mainFile ,
129
- output : {
130
- name : moduleName ,
131
- file : `dist/${ pluginName } .js` ,
132
- format : 'umd' ,
133
- globals : globals . umd ,
134
- banner
135
- } ,
136
- external : externals . umd ,
137
- plugins : plugins . umd
138
- } , {
139
- // cjs
140
- input : mainFile ,
141
- output : [ {
142
- file : `dist/${ pluginName } .cjs.js` ,
143
- format : 'cjs' ,
144
- globals : globals . module ,
145
- banner
146
- } ] ,
147
- external : externals . module ,
148
- plugins : plugins . module
149
- } , {
150
- // es
151
- input : mainFile ,
152
- output : [ {
153
- file : `dist/${ pluginName } .es.js` ,
154
- format : 'es' ,
155
- globals : globals . module ,
156
- banner
157
- } ] ,
158
- external : externals . module ,
159
- plugins : esPlugins
160
- } , {
161
- // test bundle
162
- input : 'test/**/*.test.js' ,
163
- output : {
164
- name : `${ moduleName } Tests` ,
165
- file : 'test/dist/bundle.js' ,
166
- format : 'iife' ,
167
- globals : globals . test
168
- } ,
169
- external : externals . test ,
170
- plugins : plugins . test
171
- } ] ;
137
+ /* all rollup builds by name. note only object values will be used */
138
+ const builds = {
139
+ umd : makeBuild ( 'umd' , {
140
+ output : [ {
141
+ name : moduleName ,
142
+ file : `dist/${ pluginName } .js` ,
143
+ format : 'umd'
144
+ } ]
145
+ } ) ,
146
+ cjs : makeBuild ( 'module' , {
147
+ output : [ {
148
+ file : `dist/${ pluginName } .cjs.js` ,
149
+ format : 'cjs'
150
+ } ]
151
+ } ) ,
152
+ es : makeBuild ( 'module' , {
153
+ output : [ {
154
+ file : `dist/${ pluginName } .es.js` ,
155
+ format : 'es'
156
+ } ]
157
+ } ) ,
158
+ test : makeBuild ( 'test' , {
159
+ input : 'test/**/*.test.js' ,
160
+ output : [ {
161
+ name : `${ moduleName } Tests` ,
162
+ file : 'test/dist/bundle.js' ,
163
+ format : 'iife'
164
+ } ]
165
+ } )
166
+ } ;
172
167
173
168
if ( ! isWatch ) {
174
- builds . push ( {
175
- // minified umd
176
- input : mainFile ,
177
- output : {
169
+ builds . minUmd = makeBuild ( 'umd' , {
170
+ output : [ {
178
171
name : moduleName ,
179
172
file : `dist/${ pluginName } .min.js` ,
180
- format : 'umd' ,
181
- globals : globals . umd ,
182
- banner
183
- } ,
184
- external : externals . umd ,
185
- plugins : minPlugins
173
+ format : 'umd'
174
+ } ] ,
175
+ // we need to minify before babel
176
+ plugins : plugins . umd
177
+ . filter ( ( p ) => p !== primedPlugins . babel )
178
+ . concat ( [ primedPlugins . uglify , primedPlugins . babel ] )
186
179
} ) ;
180
+
187
181
}
188
182
189
- export default builds ;
183
+ export default Object . values ( builds ) ;
0 commit comments