Skip to content

Commit edb165f

Browse files
committed
feat(build production): introduce the production build
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
1 parent 59d4997 commit edb165f

File tree

2 files changed

+20
-30
lines changed

2 files changed

+20
-30
lines changed

lib/broccoli/angular2-app.js

+19-30
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
var path = require('path');
22
var Concat = require('broccoli-concat');
3+
var isProduction = require('./is-production');
34
var configReplace = require('./broccoli-config-replace');
45
var compileWithTypescript = require('./broccoli-typescript').default;
56
var SwManifest = require('./service-worker-manifest').default;
@@ -41,8 +42,6 @@ Angular2App.prototype.toTree = function() {
4142
'angular2/bundles/upgrade.dev.js'
4243
];
4344

44-
45-
4645
if (this.options && this.options.vendorNpmFiles) {
4746
vendorNpmFiles = vendorNpmFiles.concat(this.options.vendorNpmFiles);
4847
}
@@ -79,8 +78,8 @@ Angular2App.prototype.toTree = function() {
7978
allowEmpty: true
8079
});
8180

82-
var jsTree = new Funnel(sourceDir, {
83-
include: ['**/*.js'],
81+
var jsTree = new Funnel(tsTree, {
82+
include: ['**/!(*.spec).js'],
8483
allowEmpty: true
8584
});
8685

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

109-
var merged = mergeTrees([
108+
var buildTree = [
110109
assetTree,
111-
tsSrcTree,
112-
tsTree,
113-
jsTree,
114110
this.index(),
115111
vendorNpmTree,
116112
thirdPartyJs
117-
], { overwrite: true });
113+
];
114+
115+
if (isProduction) {
116+
buildTree.push(jsTree);
117+
} else {
118+
buildTree.push(tsSrcTree);
119+
buildTree.push(tsTree);
120+
}
121+
122+
var merged = mergeTrees(buildTree, { overwrite: true });
118123

119124
return mergeTrees([merged, new SwManifest(merged)]);
120125
};
@@ -126,10 +131,6 @@ Angular2App.prototype.toTree = function() {
126131
*/
127132
Angular2App.prototype._initProject = function() {
128133
this.project = Project.closestSync(process.cwd());
129-
130-
/*if (options.configPath) {
131-
this.project.configPath = function() { return options.configPath; };
132-
}*/
133134
};
134135

135136
/**
@@ -186,12 +187,6 @@ Angular2App.prototype.initializeAddons = function() {
186187
Angular2App.prototype.contentFor = function(match, type) {
187188
var content = [];
188189

189-
/*switch (type) {
190-
case 'head': this._contentForHead(content, config); break;
191-
case 'config-module': this._contentForConfigModule(content, config); break;
192-
case 'app-boot': this._contentForAppBoot(content, config); break;
193-
}*/
194-
195190
content = this.project.addons.reduce(function(content, addon) {
196191
var addonContent = addon.contentFor ? addon.contentFor(type) : null;
197192
if (addonContent) {
@@ -201,7 +196,6 @@ Angular2App.prototype.contentFor = function(match, type) {
201196
return content;
202197
}, content);
203198

204-
205199
return content.join('\n');
206200
};
207201

@@ -211,16 +205,12 @@ Angular2App.prototype.contentFor = function(match, type) {
211205
@return
212206
*/
213207
Angular2App.prototype._configReplacePatterns = function() {
214-
return [/*{
215-
match: /\{\{EMBER_ENV\}\}/g,
216-
replacement: calculateEmberENV
217-
}, */{
208+
return [
209+
{
218210
match: /\{\{content-for ['"](.+)["']\}\}/g,
219-
replacement: this.contentFor.bind(this)
220-
}/*, {
221-
match: /\{\{MODULE_PREFIX\}\}/g,
222-
replacement: calculateModulePrefix
223-
}*/];
211+
replacement: isProduction ? '' : this.contentFor.bind(this)
212+
}
213+
];
224214
};
225215

226216

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

245-
246235
return configReplace(index, {
247236
files: [ htmlName ],
248237
patterns: this._configReplacePatterns()

lib/broccoli/is-production.js

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
module.exports = (/(^production$|^prod$)/).test(process.env.EMBER_ENV);

0 commit comments

Comments
 (0)