Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: babel the es dist, by updating the generator #127

Merged
merged 1 commit into from
Aug 3, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.4"
},
"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
176 changes: 85 additions & 91 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,15 +64,16 @@ 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([

]),
module: Object.keys(globals.module).concat([

'global',
'global/document',
'global/window'
]),
test: Object.keys(globals.test).concat([

Expand All @@ -85,16 +83,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 +106,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);