Skip to content

Commit

Permalink
Add ES module build (#275)
Browse files Browse the repository at this point in the history
* Rollup build: explicit external/globals to squelch warnings

* Update all Babel and Rollup related packages

* Add pkg.module entry, add ES6 module build
  • Loading branch information
pglewis authored and blikblum committed Nov 27, 2017
1 parent b3f7948 commit 72ed976
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 13 deletions.
27 changes: 22 additions & 5 deletions gulpfile.babel.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import webpack from 'webpack';
import webpackStream from 'webpack-stream';

import _ from 'underscore';
import rollup from 'rollup';
import {rollup} from 'rollup';
import babel from 'rollup-plugin-babel';
import preset from 'babel-preset-es2015-rollup';
import fs from 'fs';
Expand Down Expand Up @@ -68,9 +68,23 @@ function getBanner() {
return _.template(banner)(manifest);
}

function buildESModule(bundle) {
return bundle.write({
format: 'es',
dest: manifest.module,
sourceMap: true,
banner: getBanner()
}).then(function(gen) {
return gen;
}).catch(function(error) {
console.log(error);
});
}

function build(done) {
rollup.rollup({
rollup({
entry: path.join('src', config.entryFileName),
external: ['underscore', 'backbone'],
plugins: [
babel({
sourceMaps: true,
Expand All @@ -79,12 +93,15 @@ function build(done) {
})
]
}).then(function(bundle) {
var banner = getBanner();

buildESModule(bundle);
var result = bundle.generate({
banner: banner,
banner: getBanner(),
format: 'umd',
sourceMap: 'inline',
globals: {
underscore: '_',
backbone: 'Backbone'
},
sourceMapSource: config.entryFileName + '.js',
sourceMapFile: exportFileName + '.js',
moduleName: config.mainVarName
Expand Down
17 changes: 9 additions & 8 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"homepage": "https://github.com/marionettejs/backbone.radio",
"version": "2.0.0",
"main": "build/backbone.radio.js",
"module": "build/backbone.radio.esm.js",
"keywords": [
"backbone",
"marionette",
Expand Down Expand Up @@ -45,13 +46,13 @@
"underscore": "^1.8.3"
},
"devDependencies": {
"babel-core": "6.7.0",
"babel-eslint": "6.0.4",
"babel-core": "6.24.0",
"babel-eslint": "7.0.0",
"babel-loader": "6.2.0",
"babel-polyfill": "6.6.1",
"babel-preset-es2015": "6.3.13",
"babel-preset-es2015-rollup": "1.1.1",
"babel-register": "6.4.3",
"babel-polyfill": "6.23.0",
"babel-preset-es2015": "6.24.0",
"babel-preset-es2015-rollup": "3.0.0",
"babel-register": "6.24.0",
"backbone": ">=1.3.3 <1.4.0",
"chai": "3.4.1",
"del": "2.2.0",
Expand All @@ -76,8 +77,8 @@
"json-loader": "0.5.3",
"mkdirp": "0.5.1",
"mocha": "2.3.4",
"rollup": "0.25.4",
"rollup-plugin-babel": "2.4.0",
"rollup": "0.36.3",
"rollup-plugin-babel": "2.6.1",
"sinon": "1.17.2",
"sinon-chai": "2.8.0",
"underscore": "1.8.3",
Expand Down

0 comments on commit 72ed976

Please sign in to comment.