Skip to content

Commit bd7f070

Browse files
fix: babel the es dist, by updating the generator (#68)
1 parent 70afc00 commit bd7f070

File tree

4 files changed

+89
-95
lines changed

4 files changed

+89
-95
lines changed

.yo-rc.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,4 @@
1313
"pluginType": "advanced",
1414
"css": true
1515
}
16-
}
16+
}

package.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@
8989
"serve-static": "^1.13.2",
9090
"sinon": "^5.1.0",
9191
"uglify-es": "^3.3.9",
92-
"videojs-standard": "^6.0.0"
92+
"videojs-standard": "^6.0.3"
9393
},
9494
"style": "dist/videojs-overlay.css",
9595
"videojs-plugin": {
@@ -106,7 +106,7 @@
106106
"test/"
107107
],
108108
"generator-videojs-plugin": {
109-
"version": "6.1.1"
109+
"version": "6.1.4"
110110
},
111111
"browserslist": [
112112
"defaults",

scripts/karma.conf.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ const StaticMiddlewareFactory = function(config) {
1717
};
1818
};
1919

20-
/* browsers to run on teamcitycity */
20+
/* browsers to run on teamcity */
2121
const teamcityLaunchers = {};
2222

2323
/* browsers to run on browserstack */

scripts/rollup.config.js

+85-91
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,16 @@ const {uglify} = require('rollup-plugin-uglify');
1010
const {minify} = require('uglify-es');
1111
const pkg = require('../package.json');
1212

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|--watch/).test(a)) {
20+
isWatch = true;
21+
}
22+
});
1823

1924
/* configuration for plugins */
2025
const primedPlugins = {
@@ -36,19 +41,11 @@ const primedPlugins = {
3641
uglify: uglify({output: {comments: 'some'}}, minify)
3742
};
3843

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|--watch/).test(a)) {
46-
isWatch = true;
47-
}
48-
});
44+
/* General Globals */
45+
const moduleName = 'videojsOverlay';
46+
const pluginName = 'videojs-overlay';
4947

50-
// globals, aka replace require calls
51-
// with this
48+
// globals, aka replace require calls with this
5249
const globals = {
5350
umd: {
5451
'video.js': 'videojs',
@@ -67,15 +64,16 @@ const globals = {
6764
}
6865
};
6966

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
7369
const externals = {
7470
umd: Object.keys(globals.umd).concat([
7571

7672
]),
7773
module: Object.keys(globals.module).concat([
78-
74+
'global',
75+
'global/document',
76+
'global/window'
7977
]),
8078
test: Object.keys(globals.test).concat([
8179

@@ -85,16 +83,13 @@ const externals = {
8583
/* plugins that should be used in each bundle with caveats as comments */
8684
const plugins = {
8785
// note uglify will be added before babel for minified bundle
88-
// see minPlugins below
8986
umd: [
9087
primedPlugins.resolve,
9188
primedPlugins.json,
9289
primedPlugins.commonjs,
9390
primedPlugins.babel
9491
],
9592

96-
// note babel will be removed for es module bundle
97-
// see esPlugins below
9893
module: [
9994
primedPlugins.resolve,
10095
primedPlugins.json,
@@ -111,79 +106,78 @@ const plugins = {
111106
]
112107
};
113108

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+
}
121133

122-
minPlugins.splice(plugins.umd.indexOf(primedPlugins.babel), 1);
123-
minPlugins.push(primedPlugins.uglify);
124-
minPlugins.push(primedPlugins.babel);
134+
return b;
135+
};
125136

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+
};
172167

173168
if (!isWatch) {
174-
builds.push({
175-
// minified umd
176-
input: mainFile,
177-
output: {
169+
builds.minUmd = makeBuild('umd', {
170+
output: [{
178171
name: moduleName,
179172
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])
186179
});
180+
187181
}
188182

189-
export default builds;
183+
export default Object.values(builds);

0 commit comments

Comments
 (0)