Skip to content
This repository has been archived by the owner on May 19, 2018. It is now read-only.

Commit

Permalink
Use rollup for bundling to speed up startup time
Browse files Browse the repository at this point in the history
  • Loading branch information
Andrew Levine committed Oct 23, 2016
1 parent 930cdd0 commit 6222bc5
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 11 deletions.
3 changes: 2 additions & 1 deletion .babelrc
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
{
"presets": [
["es2015", {
"loose": true
"loose": true,
"modules": false
}],
"stage-0"
],
Expand Down
11 changes: 10 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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'
- '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'
Expand Down
8 changes: 5 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,22 +29,24 @@
"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",
"prepublish": "cross-env BABEL_ENV=production npm run build",
"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": "cross-env BABEL_ENV=test nyc npm run test-only",
"changelog": "git log `git describe --tags --abbrev=0`..HEAD --pretty=format:' * %s (%an)' | grep -v 'Merge pull request'"
},
"nyc": {
Expand Down
9 changes: 9 additions & 0 deletions rollup.config.js
Original file line number Diff line number Diff line change
@@ -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"
};
12 changes: 6 additions & 6 deletions src/parser/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
Expand Down

0 comments on commit 6222bc5

Please sign in to comment.