Skip to content

Commit 7febeb3

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 6fa059b commit 7febeb3

File tree

2 files changed

+33
-28
lines changed

2 files changed

+33
-28
lines changed

lib/broccoli/angular2-app.js

+32-28
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;
@@ -77,8 +78,8 @@ Angular2App.prototype.toTree = function() {
7778
allowEmpty: true
7879
});
7980

80-
var jsTree = new Funnel(sourceDir, {
81-
include: ['**/*.js'],
81+
var jsTree = new Funnel(tsTree, {
82+
include: ['**/!(*.spec).js'],
8283
allowEmpty: true
8384
});
8485

@@ -93,14 +94,33 @@ Angular2App.prototype.toTree = function() {
9394
destDir: 'vendor'
9495
});
9596

96-
var merged = mergeTrees([
97+
98+
var thirdPartyJsTree = new Funnel('node_modules', {
99+
include: ['ng2*/bundles/*.js'],
100+
exclude: ['ng2*/bundles/*.min.js', 'ng2*/bundles/*.standalone.js'],
101+
});
102+
103+
var thirdPartyJs = new Concat(thirdPartyJsTree, {
104+
inputFiles: ['**/*.js'],
105+
outputFile: '/thirdparty/libs.js',
106+
allowNone: true
107+
});
108+
109+
var buildTree = [
97110
assetTree,
98-
tsSrcTree,
99-
tsTree,
100-
jsTree,
101111
this.index(),
102112
vendorNpmTree,
103-
], { overwrite: true });
113+
thirdPartyJs
114+
];
115+
116+
if (isProduction) {
117+
buildTree.push(jsTree);
118+
} else {
119+
buildTree.push(tsSrcTree);
120+
buildTree.push(tsTree);
121+
}
122+
123+
var merged = mergeTrees(buildTree, { overwrite: true });
104124

105125
return mergeTrees([merged, new SwManifest([merged])]);
106126
};
@@ -112,10 +132,6 @@ Angular2App.prototype.toTree = function() {
112132
*/
113133
Angular2App.prototype._initProject = function() {
114134
this.project = Project.closestSync(process.cwd());
115-
116-
/*if (options.configPath) {
117-
this.project.configPath = function() { return options.configPath; };
118-
}*/
119135
};
120136

121137
/**
@@ -172,12 +188,6 @@ Angular2App.prototype.initializeAddons = function() {
172188
Angular2App.prototype.contentFor = function(match, type) {
173189
var content = [];
174190

175-
/*switch (type) {
176-
case 'head': this._contentForHead(content, config); break;
177-
case 'config-module': this._contentForConfigModule(content, config); break;
178-
case 'app-boot': this._contentForAppBoot(content, config); break;
179-
}*/
180-
181191
content = this.project.addons.reduce(function(content, addon) {
182192
var addonContent = addon.contentFor ? addon.contentFor(type) : null;
183193
if (addonContent) {
@@ -187,7 +197,6 @@ Angular2App.prototype.contentFor = function(match, type) {
187197
return content;
188198
}, content);
189199

190-
191200
return content.join('\n');
192201
};
193202

@@ -197,16 +206,12 @@ Angular2App.prototype.contentFor = function(match, type) {
197206
@return
198207
*/
199208
Angular2App.prototype._configReplacePatterns = function() {
200-
return [/*{
201-
match: /\{\{EMBER_ENV\}\}/g,
202-
replacement: calculateEmberENV
203-
}, */{
209+
return [
210+
{
204211
match: /\{\{content-for ['"](.+)["']\}\}/g,
205-
replacement: this.contentFor.bind(this)
206-
}/*, {
207-
match: /\{\{MODULE_PREFIX\}\}/g,
208-
replacement: calculateModulePrefix
209-
}*/];
212+
replacement: isProduction ? '' : this.contentFor.bind(this)
213+
}
214+
];
210215
};
211216

212217

@@ -228,7 +233,6 @@ Angular2App.prototype.index = function() {
228233
description: 'Funnel: index.html'
229234
});
230235

231-
232236
return configReplace(index, {
233237
files: [ htmlName ],
234238
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)