Browse Source

use rollup CLI for build

better-aggressive
Rich Harris 9 years ago
parent
commit
4d01607625
  1. 3
      .babelrc
  2. 57
      gobblefile.js
  3. 10
      package.json
  4. 12
      rollup.config.browser.js
  5. 32
      rollup.config.js

3
.babelrc

@ -15,5 +15,6 @@
"es6.classes", "es6.classes",
"es6.destructuring" "es6.destructuring"
], ],
"compact": false "compact": false,
"sourceMap": true
} }

57
gobblefile.js

@ -1,57 +0,0 @@
var gobble = require( 'gobble' );
var fs = require( 'fs' );
var version = require( './package.json' ).version;
var commitHash = (function () {
try {
return fs.readFileSync( '.commithash', 'utf-8' );
} catch ( err ) {
return 'unknown';
}
})();
var banner = fs.readFileSync( 'src/banner.js' ).toString()
.replace( '${version}', version )
.replace( '${time}', new Date() )
.replace( '${commitHash}', commitHash );
var src = gobble( 'src' );
var node = src
.transform( 'rollup-babel', {
entry: 'rollup.js',
dest: 'rollup.js',
format: 'cjs',
external: [ 'fs' ],
sourceMap: true,
banner: banner,
load: function ( id ) {
if ( ~id.indexOf( 'rollup.js' ) ) {
return fs.readFileSync( 'src/rollup.js', 'utf-8' ).replace( /<@VERSION@>/, version );
}
}
});
var browserPlaceholders = {
fs: fs.readFileSync( 'browser/fs.js' ).toString(),
promise: fs.readFileSync( 'browser/promise.js' ).toString()
};
var browser = src
.transform( 'rollup-babel', {
entry: 'rollup.js',
dest: 'rollup.browser.js',
format: 'umd',
moduleName: 'rollup',
sourceMap: true,
banner: banner,
load: function ( id ) {
if ( ~id.indexOf( 'rollup.js' ) ) {
return fs.readFileSync( 'src/rollup.js', 'utf-8' ).replace( /<@VERSION@>/, version );
}
if ( ~id.indexOf( 'fs.js' ) ) return browserPlaceholders.fs;
if ( ~id.indexOf( 'es6-promise' ) ) return browserPlaceholders.promise;
}
});
module.exports = gobble([ node, browser ]);

10
package.json

@ -14,8 +14,9 @@
"test-coverage": "rm -rf coverage/* && istanbul cover --report json node_modules/.bin/_mocha -- -u exports -R spec test/test.js", "test-coverage": "rm -rf coverage/* && istanbul cover --report json node_modules/.bin/_mocha -- -u exports -R spec test/test.js",
"posttest-coverage": "remap-istanbul -i coverage/coverage-final.json -o coverage/coverage-remapped.json -b dist && remap-istanbul -i coverage/coverage-final.json -o coverage/coverage-remapped.lcov -t lcovonly -b dist && remap-istanbul -i coverage/coverage-final.json -o coverage/coverage-remapped -t html -b dist", "posttest-coverage": "remap-istanbul -i coverage/coverage-final.json -o coverage/coverage-remapped.json -b dist && remap-istanbul -i coverage/coverage-final.json -o coverage/coverage-remapped.lcov -t lcovonly -b dist && remap-istanbul -i coverage/coverage-final.json -o coverage/coverage-remapped -t html -b dist",
"ci": "npm run test-coverage && codecov < coverage/coverage-remapped.lcov", "ci": "npm run test-coverage && codecov < coverage/coverage-remapped.lcov",
"build": "git rev-parse HEAD > .commithash && gobble build -f dist", "build": "git rev-parse HEAD > .commithash && rollup -c",
"prepublish": "npm test", "build:browser": "git rev-parse HEAD > .commithash && rollup -c rollup.config.browser.js",
"prepublish": "npm test && npm run build:browser",
"lint": "eslint src" "lint": "eslint src"
}, },
"repository": { "repository": {
@ -46,11 +47,6 @@
"es6-promise": "^3.0.2", "es6-promise": "^3.0.2",
"eslint": "^1.7.1", "eslint": "^1.7.1",
"estree-walker": "^0.2.0", "estree-walker": "^0.2.0",
"gobble": "^0.10.1",
"gobble-babel": "^5.5.8",
"gobble-cli": "^0.6.0",
"gobble-rollup": "^0.10.0",
"gobble-rollup-babel": "^0.6.1",
"istanbul": "^0.4.0", "istanbul": "^0.4.0",
"magic-string": "^0.8.0", "magic-string": "^0.8.0",
"mocha": "^2.3.3", "mocha": "^2.3.3",

12
rollup.config.browser.js

@ -0,0 +1,12 @@
import config from './rollup.config.js';
config.plugins.push({
load: function ( id ) {
if ( ~id.indexOf( 'fs.js' ) ) return readFileSync( 'browser/fs.js' ).toString();
if ( ~id.indexOf( 'es6-promise' ) ) return readFileSync( 'browser/promise.js' ).toString();
}
});
config.format = 'umd';
export default config;

32
rollup.config.js

@ -0,0 +1,32 @@
import { readFileSync } from 'fs';
import babel from 'rollup-plugins-babel';
import replace from 'rollup-plugins-replace';
var pkg = JSON.parse( readFileSync( 'package.json', 'utf-8' ) );
var version = JSON.parse( pkg.version );
var commitHash = (function () {
try {
return readFileSync( '.commithash', 'utf-8' );
} catch ( err ) {
return 'unknown';
}
})();
var banner = readFileSync( 'src/banner.js', 'utf-8' )
.replace( '${version}', version )
.replace( '${time}', new Date() )
.replace( '${commitHash}', commitHash );
export default {
entry: 'src/rollup.js',
format: 'cjs',
plugins: [
babel(),
replace({
'VERSION': pkg.version
})
],
external: [ 'fs' ],
banner: banner,
sourceMap: true
};
Loading…
Cancel
Save