Use rollup for bundling to speed up startup time (#190)

This commit is contained in:
Andrew Levine 2016-10-26 09:44:21 -05:00 committed by Henry Zhu
parent d1b0886d46
commit beb8db6264
5 changed files with 32 additions and 11 deletions

View File

@ -1,7 +1,8 @@
{
"presets": [
["es2015", {
"loose": true
"loose": true,
"modules": false
}],
"stage-0"
],

View File

@ -7,7 +7,16 @@ node_js:
- "5"
- "6"
before_script: 'if [ -n "${BABEL-}" ]; then make bootstrap-babel ; fi'
before_install:
# Rollup doesn't support node < 4.x. Switch to latest for build
- . $HOME/.nvm/nvm.sh
- nvm install stable && nvm use stable
before_script:
- 'if [ -n "${BABEL-}" ]; then make bootstrap-babel ; fi'
- 'BABEL_ENV=test npm run build'
# Switch back to node version currently being tested prior to test run
- 'nvm use $TRAVIS_NODE_VERSION;'
script:
- 'if [ -n "${LINT-}" ]; then npm run lint ; fi'

View File

@ -29,13 +29,16 @@
"flow-bin": "^0.33.0",
"lodash": "^4.15.0",
"nyc": "^8.1.0",
"rollup": "^0.36.3",
"rollup-plugin-babel": "^2.6.1",
"rollup-plugin-node-resolve": "^2.0.0",
"unicode-9.0.0": "~0.7.0"
},
"bin": {
"babylon": "./bin/babylon.js"
},
"scripts": {
"build": "babel src --out-dir lib",
"build": "rollup -c",
"coverage": "nyc report --reporter=json && codecov -f coverage/coverage-final.json",
"lint": "eslint src bin",
"flow": "flow",
@ -43,8 +46,7 @@
"preversion": "npm run test && npm run changelog",
"test": "npm run lint && npm run flow && npm run build && npm run test-only",
"test-only": "ava test",
"test-ci": "cross-env BABEL_ENV=test npm run build && nyc npm run test-only",
"watch": "babel src --out-dir lib --watch",
"test-ci": "nyc npm run test-only",
"changelog": "git log `git describe --tags --abbrev=0`..HEAD --pretty=format:' * %s (%an)' | grep -v 'Merge pull request'"
},
"nyc": {

9
rollup.config.js Normal file
View File

@ -0,0 +1,9 @@
import babel from "rollup-plugin-babel";
import nodeResolve from "rollup-plugin-node-resolve";
export default {
entry: "src/index.js",
dest: "lib/index.js",
plugins: [babel(), nodeResolve()],
format: "cjs"
};

View File

@ -30,20 +30,20 @@ export default class Parser extends Tokenizer {
this[name] = f(this[name]);
}
loadPlugins(plugins: Array<string>): Object {
loadPlugins(pluginList: Array<string>): Object {
let pluginMap = {};
if (plugins.indexOf("flow") >= 0) {
if (pluginList.indexOf("flow") >= 0) {
// ensure flow plugin loads last
plugins = plugins.filter((plugin) => plugin !== "flow");
plugins.push("flow");
pluginList = pluginList.filter((plugin) => plugin !== "flow");
pluginList.push("flow");
}
for (let name of plugins) {
for (let name of pluginList) {
if (!pluginMap[name]) {
pluginMap[name] = true;
let plugin = exports.plugins[name];
let plugin = plugins[name];
if (plugin) plugin(this);
}
}