Skip to content

Commit

Permalink
refactor: A single rollup config, and let karma rollup during run (#155)
Browse files Browse the repository at this point in the history
  • Loading branch information
misteroneill authored and brandonocasey committed Jun 7, 2018
1 parent 6664523 commit d3c6ba1
Show file tree
Hide file tree
Showing 16 changed files with 1,452 additions and 241 deletions.
8 changes: 3 additions & 5 deletions generators/app/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -219,14 +219,12 @@ module.exports = yeoman.generators.Base.extend({
'_.nvmrc',
'scripts/_banner.js',
'scripts/_server.js',
'scripts/_version.js'
'scripts/_version.js',
'scripts/_primed-rollup-plugins.js'
];

this._templatesToCopy = [
'scripts/_modules.rollup.config.js',
'scripts/_test.rollup.config.js',
'scripts/_umd.rollup.config.js',
'test/_index.html',
'scripts/_rollup.config.js',
'test/_karma.conf.js',
'test/_plugin.test.js',
'_index.html',
Expand Down
44 changes: 9 additions & 35 deletions generators/app/package-json.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ const DEFAULTS = {
'karma-ie-launcher',
'karma-qunit',
'karma-safari-launcher',
'karma-rollup-preprocessor',
'mkdirp',
'node-static',
'npm-run-all',
Expand All @@ -52,10 +53,11 @@ const DEFAULTS = {
'rollup-plugin-json',
'rollup-plugin-multi-entry',
'rollup-plugin-node-resolve',
'rollup-plugin-uglify',
'rollup-watch',
'semver',
'sinon',
'uglify-js',
'uglify-es',
'videojs-standard'
])
};
Expand Down Expand Up @@ -150,46 +152,20 @@ const packageJSON = (current, context) => {
'scripts': _.assign({}, current.scripts, {
'prebuild': 'npm run clean',
'build': 'npm-run-all -p build:*',

'build:js': scriptify([
'npm-run-all',
'build:js:rollup-modules',
'build:js:rollup-umd',
'build:js:bannerize',
'build:js:uglify'
]),

'build:js:rollup-modules': 'rollup -c scripts/modules.rollup.config.js',
'build:js:rollup-umd': 'rollup -c scripts/umd.rollup.config.js',

// This could easily be part of the rollup config, but because we need it
// for the CSS, we might as well keep things consistent.
'build:js:bannerize': scriptify([
'bannerize dist/%s.js',
'--banner=scripts/banner.ejs'
]),

'build:js:uglify': scriptify([
'uglifyjs dist/%s.js',
'--comments --mangle --compress',
'-o dist/%s.min.js'
]),

'build:test': 'rollup -c scripts/test.rollup.config.js',
'build:js': 'rollup -c scripts/rollup.config.js',
'clean': 'rimraf dist test/dist',
'postclean': 'mkdirp dist test/dist',
'lint': 'vjsstandard',
'prepublish': 'not-in-install && npm run build || in-install',
'start': 'npm-run-all -p start:server watch',
'start': 'npm-run-all -p start:server test:server watch',
'start:server': 'node scripts/server.js',
'pretest': 'npm-run-all lint build',
'pretest': 'npm run all lint',
'test': 'karma start test/karma.conf.js',
'test:server': 'karma start test/karma.conf.js --singleRun=false --auto-watch --no-browsers',
'preversion': 'npm test',
'version': 'node scripts/version.js',
'watch': 'npm-run-all -p watch:*',
'watch:js-modules': 'rollup -c scripts/modules.rollup.config.js -w',
'watch:js-umd': 'rollup -c scripts/umd.rollup.config.js -w',
'watch:test': 'rollup -c scripts/test.rollup.config.js -w'
'watch:js': 'rollup -c scripts/rollup.config.js -w'
}),

// Always include the two minimum keywords with whatever exists in the
Expand All @@ -202,9 +178,7 @@ const packageJSON = (current, context) => {
'vjsstandard': {
ignore: [
'dist',
'docs',
'test/dist',
'test/karma.conf.js'
'docs'
]
},

Expand Down
1 change: 0 additions & 1 deletion generators/app/templates/_.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,3 @@ node_modules/
# Build-related directories
dist/
docs/api/
test/dist/
6 changes: 0 additions & 6 deletions generators/app/templates/scripts/_banner.ejs

This file was deleted.

1 change: 0 additions & 1 deletion generators/app/templates/scripts/_banner.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
const pkg = require('../package.json');

const bannerString = `@name ${pkg.name} @version ${pkg.version} @copyright ${pkg.author} @license ${pkg.license}`;

module.exports = {
Expand Down
47 changes: 0 additions & 47 deletions generators/app/templates/scripts/_modules.rollup.config.js

This file was deleted.

26 changes: 26 additions & 0 deletions generators/app/templates/scripts/_primed-rollup-plugins.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
const babel = require('rollup-plugin-babel');
const commonjs = require('rollup-plugin-commonjs');
const json = require('rollup-plugin-json');
const multiEntry = require('rollup-plugin-multi-entry');
const resolve = require('rollup-plugin-node-resolve');
const {uglify} = require('rollup-plugin-uglify');
const {minify} = require('uglify-es');

module.exports = {
babel: babel({
babelrc: false,
exclude: 'node_modules/**',
presets: [
['es2015', {loose: true, modules: false}]
],
plugins: [
'external-helpers',
'transform-object-assign'
]
}),
commonjs: commonjs({sourceMap: false}),
json: json(),
multiEntry: multiEntry({exports: false}),
resolve: resolve({browser: true, main: true, jsnext: true}),
uglify: uglify({output: {comments: 'some'}}, minify)
};
62 changes: 62 additions & 0 deletions generators/app/templates/scripts/_rollup.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
/**
* Rollup configuration for packaging the plugin in various formats.
*/
const plugins = require('./primed-rollup-plugins.js');
const banner = require('./banner.js').comment;



// to prevent a screen during rollup watch
process.stderr.isTTY = false;

const umdGlobals = {
'video.js': 'videojs',
'global': 'window',
'global/window': 'window',
'global/document': 'document'
};
const moduleGlobals = {
'video.js': 'videojs'
};

export default [{
// umd
input: 'src/plugin.js',
output: {
name: '<%= moduleName %>',
file: 'dist/<%= pluginName %>.js',
format: 'umd',
globals: umdGlobals,
banner
},
external: Object.keys(umdGlobals),
plugins: [plugins.resolve, plugins.json, plugins.commonjs, plugins.babel]
}, {
// minified umd
input: 'src/plugin.js',
output: {
name: '<%= moduleName %>',
file: 'dist/<%= pluginName %>.min.js',
format: 'umd',
globals: umdGlobals,
banner
},
external: Object.keys(umdGlobals),
plugins: [
plugins.resolve,
plugins.json,
plugins.commonjs,
plugins.uglify,
plugins.babel
]
}, {
// cjs and es
input: 'src/plugin.js',
output: [
{file: 'dist/<%= pluginName %>.cjs.js', format: 'cjs', globals: moduleGlobals, banner},
{file: 'dist/<%= pluginName %>.es.js', format: 'es', globals: moduleGlobals, banner}
],
external: Object.keys(moduleGlobals)
.concat(['global', 'global/window', 'global/document']),
plugins: [plugins.json, plugins.babel]
}];
8 changes: 8 additions & 0 deletions generators/app/templates/scripts/_server.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,19 @@
const http = require('http');
const portscanner = require('portscanner');
const nodeStatic = require('node-static');
const url = require('url');

const files = new nodeStatic.Server(process.cwd(), {cache: false});

const server = http.createServer((request, response) => {
response.setHeader('Cache-Control', 'no-cache,must-revalidate');
const requestUrl = url.parse('http://' + request.headers.host + request.url);

if ((/^\/test.*/).test(requestUrl.path)) {
response.writeHead(302, {Location: `http://${requestUrl.hostname}:9876/debug.html`});
response.end();
return;
}

request.addListener('end', () => {
files.serve(request, response, (err) => {
Expand Down
59 changes: 0 additions & 59 deletions generators/app/templates/scripts/_test.rollup.config.js

This file was deleted.

56 changes: 0 additions & 56 deletions generators/app/templates/scripts/_umd.rollup.config.js

This file was deleted.

Loading

0 comments on commit d3c6ba1

Please sign in to comment.