Skip to content

Commit

Permalink
fix: babel the es dist, by updating the generator
Browse files Browse the repository at this point in the history
  • Loading branch information
brandonocasey committed Jul 27, 2018
1 parent 7e95841 commit 153075b
Show file tree
Hide file tree
Showing 3 changed files with 85 additions and 93 deletions.
2 changes: 1 addition & 1 deletion .yo-rc.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"generator-videojs-plugin": {
"scope": " ",
"scope": "",
"name": "errors",
"description": "A Video.js plugin for custom error reporting",
"author": "Brightcove, Inc.",
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
"videojs-plugin"
],
"generator-videojs-plugin": {
"version": "6.1.1"
"version": "6.1.2"
},
"scripts": {
"prebuild": "npm run clean",
Expand Down Expand Up @@ -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",
Expand Down
172 changes: 82 additions & 90 deletions scripts/rollup.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand All @@ -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',
Expand All @@ -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([

Expand All @@ -85,16 +81,13 @@ 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,
primedPlugins.commonjs,
primedPlugins.babel
],

// note babel will be removed for es module bundle
// see esPlugins below
module: [
primedPlugins.resolve,
primedPlugins.json,
Expand All @@ -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);

0 comments on commit 153075b

Please sign in to comment.