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 24, 2016
1 parent 6fa059b commit 7febeb3
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 28 deletions.
60 changes: 32 additions & 28 deletions lib/broccoli/angular2-app.js
@@ -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 @@ -77,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 @@ -93,14 +94,33 @@ Angular2App.prototype.toTree = function() {
destDir: 'vendor'
});

var merged = mergeTrees([

var thirdPartyJsTree = new Funnel('node_modules', {
include: ['ng2*/bundles/*.js'],
exclude: ['ng2*/bundles/*.min.js', 'ng2*/bundles/*.standalone.js'],
});

var thirdPartyJs = new Concat(thirdPartyJsTree, {
inputFiles: ['**/*.js'],
outputFile: '/thirdparty/libs.js',
allowNone: true
});

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

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 @@ -112,10 +132,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 @@ -172,12 +188,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 @@ -187,7 +197,6 @@ Angular2App.prototype.contentFor = function(match, type) {
return content;
}, content);


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

Expand All @@ -197,16 +206,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 @@ -228,7 +233,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
@@ -0,0 +1 @@
module.exports = (/(^production$|^prod$)/).test(process.env.EMBER_ENV);

0 comments on commit 7febeb3

Please sign in to comment.