From 153075bec35e5777452f17bba6ec5cf8733a1bb1 Mon Sep 17 00:00:00 2001 From: brandonocasey Date: Fri, 27 Jul 2018 15:04:28 -0400 Subject: [PATCH] fix: babel the es dist, by updating the generator --- .yo-rc.json | 2 +- package.json | 4 +- scripts/rollup.config.js | 172 +++++++++++++++++++-------------------- 3 files changed, 85 insertions(+), 93 deletions(-) diff --git a/.yo-rc.json b/.yo-rc.json index 325303c..84d729c 100644 --- a/.yo-rc.json +++ b/.yo-rc.json @@ -1,6 +1,6 @@ { "generator-videojs-plugin": { - "scope": " ", + "scope": "", "name": "errors", "description": "A Video.js plugin for custom error reporting", "author": "Brightcove, Inc.", diff --git a/package.json b/package.json index 1b4d1c3..4c476ae 100644 --- a/package.json +++ b/package.json @@ -15,7 +15,7 @@ "videojs-plugin" ], "generator-videojs-plugin": { - "version": "6.1.1" + "version": "6.1.2" }, "scripts": { "prebuild": "npm run clean", @@ -107,7 +107,7 @@ "sinon": "^5.1.0", "uglify-es": "^3.3.9", "videojs-languages": "^1.0.0", - "videojs-standard": "^6.0.0" + "videojs-standard": "^6.0.3" }, "browserslist": [ "defaults", diff --git a/scripts/rollup.config.js b/scripts/rollup.config.js index 10e98f5..ce6645a 100644 --- a/scripts/rollup.config.js +++ b/scripts/rollup.config.js @@ -10,11 +10,16 @@ const {uglify} = require('rollup-plugin-uglify'); const {minify} = require('uglify-es'); const pkg = require('../package.json'); -/* General Globals */ -const moduleName = 'videojsErrors'; -const pluginName = 'videojs-errors'; -const mainFile = 'src/plugin.js'; -const banner = `/*! @name ${pkg.name} @version ${pkg.version} @license ${pkg.license} */`; +/* to prevent going into a screen during rollup */ +process.stderr.isTTY = false; + +let isWatch = false; + +process.argv.forEach((a) => { + if ((/-w|--watch/).test(a)) { + isWatch = true; + } +}); /* configuration for plugins */ const primedPlugins = { @@ -36,19 +41,11 @@ const primedPlugins = { uglify: uglify({output: {comments: 'some'}}, minify) }; -// to prevent a screen during rollup watch/build -process.stderr.isTTY = false; - -let isWatch = false; - -process.argv.forEach((a) => { - if ((/-w|--watch/).test(a)) { - isWatch = true; - } -}); +/* General Globals */ +const moduleName = 'videojsErrors'; +const pluginName = 'videojs-errors'; -// globals, aka replace require calls -// with this +// globals, aka replace require calls with this const globals = { umd: { 'video.js': 'videojs', @@ -67,9 +64,8 @@ const globals = { } }; -// externals, aka don't bundle there -// and if not listed as a global don't require -// them either +// externals, aka don't bundle these and if not +// listed as a global don't require them either const externals = { umd: Object.keys(globals.umd).concat([ @@ -85,7 +81,6 @@ const externals = { /* plugins that should be used in each bundle with caveats as comments */ const plugins = { // note uglify will be added before babel for minified bundle - // see minPlugins below umd: [ primedPlugins.resolve, primedPlugins.json, @@ -93,8 +88,6 @@ const plugins = { primedPlugins.babel ], - // note babel will be removed for es module bundle - // see esPlugins below module: [ primedPlugins.resolve, primedPlugins.json, @@ -111,79 +104,78 @@ const plugins = { ] }; -// clone module plugins, remove babel -const esPlugins = plugins.module.slice(); - -esPlugins.splice(plugins.module.indexOf(primedPlugins.babel), 1); - -// clone umd plugins, remove babel, add uglify then babel -const minPlugins = plugins.umd.slice(); +/* make a build with the specifed settings */ +const makeBuild = (name, settings) => { + const b = Object.assign({}, { + plugins: plugins[name], + external: externals[name], + input: 'src/plugin.js' + }, settings); + + const fixOutput = (o) => { + if (!o.banner) { + o.banner = `/*! @name ${pkg.name} @version ${pkg.version} @license ${pkg.license} */`; + } + if (!o.globals) { + o.globals = globals[name]; + } + + return o; + }; + + if (!Array.isArray(b.output)) { + b.output = fixOutput(b.output); + } else { + b.output = b.output.map(fixOutput); + } -minPlugins.splice(plugins.umd.indexOf(primedPlugins.babel), 1); -minPlugins.push(primedPlugins.uglify); -minPlugins.push(primedPlugins.babel); + return b; +}; -const builds = [{ - // umd - input: mainFile, - output: { - name: moduleName, - file: `dist/${pluginName}.js`, - format: 'umd', - globals: globals.umd, - banner - }, - external: externals.umd, - plugins: plugins.umd -}, { - // cjs - input: mainFile, - output: [{ - file: `dist/${pluginName}.cjs.js`, - format: 'cjs', - globals: globals.module, - banner - }], - external: externals.module, - plugins: plugins.module -}, { - // es - input: mainFile, - output: [{ - file: `dist/${pluginName}.es.js`, - format: 'es', - globals: globals.module, - banner - }], - external: externals.module, - plugins: esPlugins -}, { - // test bundle - input: 'test/**/*.test.js', - output: { - name: `${moduleName}Tests`, - file: 'test/dist/bundle.js', - format: 'iife', - globals: globals.test - }, - external: externals.test, - plugins: plugins.test -}]; +/* all rollup builds by name. note only object values will be used */ +const builds = { + umd: makeBuild('umd', { + output: [{ + name: moduleName, + file: `dist/${pluginName}.js`, + format: 'umd' + }] + }), + cjs: makeBuild('module', { + output: [{ + file: `dist/${pluginName}.cjs.js`, + format: 'cjs' + }] + }), + es: makeBuild('module', { + output: [{ + file: `dist/${pluginName}.es.js`, + format: 'es' + }] + }), + test: makeBuild('test', { + input: 'test/**/*.test.js', + output: [{ + name: `${moduleName}Tests`, + file: 'test/dist/bundle.js', + format: 'iife' + }] + }) +}; if (!isWatch) { - builds.push({ - // minified umd - input: mainFile, - output: { + builds.minUmd = makeBuild('umd', { + output: [{ name: moduleName, file: `dist/${pluginName}.min.js`, - format: 'umd', - globals: globals.umd, - banner - }, - external: externals.umd, - plugins: minPlugins + format: 'umd' + }], + // we need to minify before babel + plugins: plugins.umd + .filter((p) => p !== primedPlugins.babel) + .concat([primedPlugins.uglify, primedPlugins.babel]) }); + } -export default builds; +export default Object.values(builds);