Skip to content

Commit

Permalink
feat(build production): introduce the production build
Browse files Browse the repository at this point in the history
For production build:
- remove live reload references (still not 100%)
- stop copying tests and .ts files + tsconfig.json

Missing:
- enableProdMode()
- add a CNAME file

Closes angular#41
  • Loading branch information
cironunes committed Mar 20, 2016
1 parent 59d4997 commit edb165f
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 30 deletions.
49 changes: 19 additions & 30 deletions lib/broccoli/angular2-app.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
var path = require('path');
var Concat = require('broccoli-concat');
var isProduction = require('./is-production');
var configReplace = require('./broccoli-config-replace');
var compileWithTypescript = require('./broccoli-typescript').default;
var SwManifest = require('./service-worker-manifest').default;
Expand Down Expand Up @@ -41,8 +42,6 @@ Angular2App.prototype.toTree = function() {
'angular2/bundles/upgrade.dev.js'
];



if (this.options && this.options.vendorNpmFiles) {
vendorNpmFiles = vendorNpmFiles.concat(this.options.vendorNpmFiles);
}
Expand Down Expand Up @@ -79,8 +78,8 @@ Angular2App.prototype.toTree = function() {
allowEmpty: true
});

var jsTree = new Funnel(sourceDir, {
include: ['**/*.js'],
var jsTree = new Funnel(tsTree, {
include: ['**/!(*.spec).js'],
allowEmpty: true
});

Expand All @@ -106,15 +105,21 @@ Angular2App.prototype.toTree = function() {
allowNone: true
});

var merged = mergeTrees([
var buildTree = [
assetTree,
tsSrcTree,
tsTree,
jsTree,
this.index(),
vendorNpmTree,
thirdPartyJs
], { overwrite: true });
];

if (isProduction) {
buildTree.push(jsTree);
} else {
buildTree.push(tsSrcTree);
buildTree.push(tsTree);
}

var merged = mergeTrees(buildTree, { overwrite: true });

return mergeTrees([merged, new SwManifest(merged)]);
};
Expand All @@ -126,10 +131,6 @@ Angular2App.prototype.toTree = function() {
*/
Angular2App.prototype._initProject = function() {
this.project = Project.closestSync(process.cwd());

/*if (options.configPath) {
this.project.configPath = function() { return options.configPath; };
}*/
};

/**
Expand Down Expand Up @@ -186,12 +187,6 @@ Angular2App.prototype.initializeAddons = function() {
Angular2App.prototype.contentFor = function(match, type) {
var content = [];

/*switch (type) {
case 'head': this._contentForHead(content, config); break;
case 'config-module': this._contentForConfigModule(content, config); break;
case 'app-boot': this._contentForAppBoot(content, config); break;
}*/

content = this.project.addons.reduce(function(content, addon) {
var addonContent = addon.contentFor ? addon.contentFor(type) : null;
if (addonContent) {
Expand All @@ -201,7 +196,6 @@ Angular2App.prototype.contentFor = function(match, type) {
return content;
}, content);


return content.join('\n');
};

Expand All @@ -211,16 +205,12 @@ Angular2App.prototype.contentFor = function(match, type) {
@return
*/
Angular2App.prototype._configReplacePatterns = function() {
return [/*{
match: /\{\{EMBER_ENV\}\}/g,
replacement: calculateEmberENV
}, */{
return [
{
match: /\{\{content-for ['"](.+)["']\}\}/g,
replacement: this.contentFor.bind(this)
}/*, {
match: /\{\{MODULE_PREFIX\}\}/g,
replacement: calculateModulePrefix
}*/];
replacement: isProduction ? '' : this.contentFor.bind(this)
}
];
};


Expand All @@ -242,7 +232,6 @@ Angular2App.prototype.index = function() {
description: 'Funnel: index.html'
});


return configReplace(index, {
files: [ htmlName ],
patterns: this._configReplacePatterns()
Expand Down
1 change: 1 addition & 0 deletions lib/broccoli/is-production.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
module.exports = (/(^production$|^prod$)/).test(process.env.EMBER_ENV);

0 comments on commit edb165f

Please sign in to comment.