Skip to content

Commit

Permalink
Fix build Perf
Browse files Browse the repository at this point in the history
Babel first, then rollup. Rather then rolling and then babeling.
  • Loading branch information
stefanpenner committed Apr 24, 2017
1 parent 9f46c6d commit 77bce45
Show file tree
Hide file tree
Showing 4 changed files with 68 additions and 46 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Expand Up @@ -23,3 +23,5 @@ node_modules/
bower_components/
.metadata_never_index
npm-debug.log

DEBUG-*
92 changes: 56 additions & 36 deletions index.js
Expand Up @@ -5,6 +5,10 @@ var path = require('path');
var SilentError = require('silent-error');
var Funnel = require('broccoli-funnel');
var Rollup = require('broccoli-rollup');
var stew = require('broccoli-stew');
var Babel = require('broccoli-babel-transpiler');
var merge = require('broccoli-merge-trees');
var version = require('./lib/version');

// allow toggling of heimdall instrumentation
var INSTRUMENT_HEIMDALL = false;
Expand All @@ -16,6 +20,9 @@ for (var i = 0; i < args.length; i++) {
break;
}
}
var NOOP_TREE = function(dir ) {
return { inputTree: dir, rebuild: function() { return []; } };
};

process.env.INSTRUMENT_HEIMDALL = INSTRUMENT_HEIMDALL;

Expand Down Expand Up @@ -97,73 +104,86 @@ module.exports = {
},

treeForApp: function(dir) {
if (this._forceBowerUsage) {
// Fake an empty broccoli tree
return { inputTree: dir, rebuild: function() { return []; } };
}
if (this._forceBowerUsage) { return NOOP_TREE(dir); }

// this._super.treeForApp is undefined in ember-cli (1.13) for some reason.
// TODO: investigate why treeForApp isn't on _super
return dir;
},

treeForAddon: function(dir) {
if (this._forceBowerUsage) {
// Fakes an empty broccoli tree
return { inputTree: dir, rebuild: function() { return []; } };
}
treeForAddon: function(tree) {
if (this._forceBowerUsage) { return NOOP_TREE(tree); }

let babel = this.addons.find(addon => addon.name === 'ember-cli-babel');

let treeWithVersion = merge([
tree,
version() // compile the VERSION into the build
]);

var version = require('./lib/version');
var merge = require('broccoli-merge-trees');
let withPrivate = new Funnel(tree, { include: ['-private/**'] });
let withoutPrivate = new Funnel(treeWithVersion, {
exclude: [
'-private',
isProductionEnv() ? '-debug' : false
].filter(Boolean),

var privateTree = 'addon/-private';
var publicTree = new Funnel('addon', {
exclude: [ /-private/ ]
destDir: 'ember-data'
});

var privateTree = babel.transpileTree(withPrivate, {
babel: this.buildBabelOptions(),
'ember-cli-babel': {
compileModules: false
}
});

// use the default options
var publicTree = babel.transpileTree(withoutPrivate);

privateTree = new Rollup(privateTree, {
rollup: {
entry: 'index.js',
dest: '-private.js',
entry: '-private/index.js',
targets: [
{ dest: '-private.js', format: 'amd', moduleId: 'ember-data/-private' }
],
external: [
'ember',
'ember-inflector',
'ember-data/version',
'ember-data/-debug',
'ember-data/adapters/errors'
]
]
// cache: true|false Defaults to true
}
});

var tree = merge([publicTree, privateTree]);

if (isProductionEnv()) {
tree = new Funnel(tree, {
exclude: [
/-debug/
]
});
}
// the output of treeForAddon is required to be modules/<your files>
publicTree = new Funnel(publicTree, { destDir: 'modules' });
privateTree = new Funnel(privateTree, { destDir: 'modules' });

return this._super.treeForAddon.call(this, merge([
version(),
tree
]));
return merge([
publicTree,
privateTree
]);
},

_setupBabelOptions: function() {
if (this._hasSetupBabelOptions) {
return;
}

buildBabelOptions() {
let customPlugins = require('./lib/stripped-build-plugins')(process.env.EMBER_ENV);

this.options.babel = {
return {
loose: true,
plugins: customPlugins.plugins,
postTransformPlugins: customPlugins.postTransformPlugins
};
},

_setupBabelOptions: function() {
if (this._hasSetupBabelOptions) {
return;
}

this.options.babel = this.buildBabelOptions();

this._hasSetupBabelOptions = true;
},
Expand Down
6 changes: 3 additions & 3 deletions package.json
Expand Up @@ -27,11 +27,11 @@
"babel6-plugin-strip-heimdall": "^6.0.1",
"broccoli-babel-transpiler": "^6.0.0",
"broccoli-file-creator": "^1.0.0",
"broccoli-funnel": "^1.2.0",
"broccoli-merge-trees": "^1.0.0",
"broccoli-rollup": "^1.2.0",
"broccoli-funnel": "^1.0.0",
"chalk": "^1.1.1",
"ember-cli-babel": "^6.0.0-beta.7",
"ember-cli-babel": "^6.0.0-beta.10",
"ember-cli-path-utils": "^1.0.0",
"ember-cli-string-utils": "^1.0.0",
"ember-cli-test-info": "^1.0.0",
Expand Down Expand Up @@ -61,7 +61,7 @@
"bower": "^1.6.5",
"broccoli-asset-rev": "^2.4.5",
"broccoli-concat": "^3.2.2",
"broccoli-stew": "^1.0.1",
"broccoli-stew": "^1.4.2",
"broccoli-string-replace": "^0.1.1",
"broccoli-uglify-sourcemap": "^1.0.1",
"broccoli-yuidoc": "^2.1.0",
Expand Down
14 changes: 7 additions & 7 deletions yarn.lock
Expand Up @@ -1213,7 +1213,7 @@ broccoli-funnel-reducer@^1.0.0:
version "1.0.0"
resolved "https://registry.npmjs.org/broccoli-funnel-reducer/-/broccoli-funnel-reducer-1.0.0.tgz#11365b2a785aec9b17972a36df87eef24c5cc0ea"

broccoli-funnel@^1.0.0, broccoli-funnel@^1.0.1, broccoli-funnel@^1.0.6, broccoli-funnel@^1.1.0:
broccoli-funnel@^1.0.0, broccoli-funnel@^1.0.1, broccoli-funnel@^1.0.6, broccoli-funnel@^1.1.0, broccoli-funnel@^1.2.0:
version "1.2.0"
resolved "https://registry.npmjs.org/broccoli-funnel/-/broccoli-funnel-1.2.0.tgz#cddc3afc5ff1685a8023488fff74ce6fb5a51296"
dependencies:
Expand Down Expand Up @@ -1357,7 +1357,7 @@ broccoli-sri-hash@^2.1.0:
sri-toolbox "^0.2.0"
symlink-or-copy "^1.0.1"

broccoli-stew@^1.0.1, broccoli-stew@^1.2.0, broccoli-stew@^1.3.3:
broccoli-stew@^1.2.0, broccoli-stew@^1.3.3, broccoli-stew@^1.4.2:
version "1.4.2"
resolved "https://registry.npmjs.org/broccoli-stew/-/broccoli-stew-1.4.2.tgz#9ec4062fd7162c6026561a2fbf64558363aff8d6"
dependencies:
Expand Down Expand Up @@ -2072,7 +2072,7 @@ ember-cli-babel@^5.0.0, ember-cli-babel@^5.1.10, ember-cli-babel@^5.1.5, ember-c
ember-cli-version-checker "^1.0.2"
resolve "^1.1.2"

ember-cli-babel@^6.0.0, ember-cli-babel@^6.0.0-beta.7:
ember-cli-babel@^6.0.0, ember-cli-babel@^6.0.0-beta.10, ember-cli-babel@^6.0.0-beta.7:
version "6.0.0"
resolved "https://registry.npmjs.org/ember-cli-babel/-/ember-cli-babel-6.0.0.tgz#caab075780dca3759982c9f54ea70a9adb1f3550"
dependencies:
Expand Down Expand Up @@ -5250,13 +5250,13 @@ right-align@^0.1.1:
dependencies:
align-text "^0.1.1"

rimraf@2.5.2, rimraf@^2.2.8, rimraf@^2.3.2, rimraf@^2.3.4, rimraf@^2.4.1, rimraf@^2.4.3, rimraf@^2.5.1:
rimraf@2.5.2, rimraf@^2.2.8, rimraf@^2.3.4, rimraf@^2.4.1, rimraf@^2.4.3, rimraf@^2.5.1:
version "2.5.2"
resolved "https://registry.npmjs.org/rimraf/-/rimraf-2.5.2.tgz#62ba947fa4c0b4363839aefecd4f0fbad6059726"
dependencies:
glob "^7.0.0"

rimraf@^2.1.4, rimraf@^2.4.4, rimraf@^2.5.3, rimraf@^2.5.4:
rimraf@^2.1.4, rimraf@^2.3.2, rimraf@^2.4.4, rimraf@^2.5.3, rimraf@^2.5.4:
version "2.6.1"
resolved "https://registry.npmjs.org/rimraf/-/rimraf-2.6.1.tgz#c2338ec643df7a1b7fe5c54fa86f57428a55f33d"
dependencies:
Expand All @@ -5280,11 +5280,11 @@ route-recognizer@^0.2.3:
version "0.2.10"
resolved "https://registry.npmjs.org/route-recognizer/-/route-recognizer-0.2.10.tgz#024b2283c2e68d13a7c7f5173a5924645e8902df"

rsvp@3.2.1, rsvp@^3.0.16, rsvp@^3.0.17, rsvp@^3.0.6, rsvp@~3.2.1:
rsvp@3.2.1, rsvp@^3.0.16, rsvp@^3.0.17, rsvp@^3.0.6, rsvp@^3.2.1, rsvp@~3.2.1:
version "3.2.1"
resolved "https://registry.npmjs.org/rsvp/-/rsvp-3.2.1.tgz#07cb4a5df25add9e826ebc67dcc9fd89db27d84a"

rsvp@^3.0.14, rsvp@^3.0.18, rsvp@^3.0.21, rsvp@^3.1.0, rsvp@^3.2.1, rsvp@^3.3.3, rsvp@^3.4.0:
rsvp@^3.0.14, rsvp@^3.0.18, rsvp@^3.0.21, rsvp@^3.1.0, rsvp@^3.3.3, rsvp@^3.4.0:
version "3.5.0"
resolved "https://registry.npmjs.org/rsvp/-/rsvp-3.5.0.tgz#a62c573a4ae4e1dfd0697ebc6242e79c681eaa34"

Expand Down

0 comments on commit 77bce45

Please sign in to comment.