Skip to content

Commit 82df55e

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 5da51b0 commit 82df55e

File tree

3 files changed

+19
-15
lines changed

3 files changed

+19
-15
lines changed

lib/broccoli/angular2-app.js

+17-15
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
var path = require('path');
2+
var isProduction = require('./is-production');
23
var configReplace = require('./broccoli-config-replace');
34
var compileWithTypescript = require('./broccoli-typescript').default;
45
var SwManifest = require('./service-worker-manifest').default;
@@ -66,21 +67,23 @@ Angular2App.prototype.toTree = function () {
6667
var srcAndTypingsTree = mergeTrees([sourceTree, typingsTree]);
6768
var tsTree = new compileWithTypescript(srcAndTypingsTree, tsconfig);
6869

70+
var tsTreeExcludes = ['*.d.ts', 'tsconfig.json'];
71+
var excludeSpecFiles = '**/*.spec.*';
72+
73+
if (isProduction) {
74+
tsTreeExcludes.push(excludeSpecFiles);
75+
}
76+
6977
tsTree = new Funnel(tsTree, {
7078
srcDir: 'src',
71-
exclude: ['*.d.ts', 'tsconfig.json']
79+
exclude: tsTreeExcludes
7280
});
7381

7482
var tsSrcTree = new Funnel(sourceDir, {
7583
include: ['**/*.ts'],
7684
allowEmpty: true
7785
});
7886

79-
var jsTree = new Funnel(sourceDir, {
80-
include: ['**/*.js'],
81-
allowEmpty: true
82-
});
83-
8487
var assetTree = new Funnel(sourceDir, {
8588
include: ['**/*.*'],
8689
exclude: ['**/*.ts', '**/*.js'],
@@ -92,14 +95,13 @@ Angular2App.prototype.toTree = function () {
9295
destDir: 'vendor'
9396
});
9497

95-
var merged = mergeTrees([
96-
assetTree,
97-
tsSrcTree,
98-
tsTree,
99-
jsTree,
100-
this.index(),
101-
vendorNpmTree
102-
], { overwrite: true });
98+
var buildTrees = [assetTree, tsTree, this.index(), vendorNpmTree];
99+
100+
if (!isProduction) {
101+
buildTrees.push(tsSrcTree);
102+
}
103+
104+
var merged = mergeTrees(buildTrees, { overwrite: true });
103105

104106
return mergeTrees([merged, new SwManifest([merged])]);
105107
};
@@ -198,7 +200,7 @@ Angular2App.prototype.contentFor = function (match, type) {
198200
Angular2App.prototype._configReplacePatterns = function () {
199201
return [{
200202
match: /\{\{content-for ['"](.+)["']\}\}/g,
201-
replacement: this.contentFor.bind(this)
203+
replacement: isProduction ? '' : this.contentFor.bind(this)
202204
}];
203205
};
204206

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);

package.json

+1
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@
6363
"glob": "^7.0.3",
6464
"minimatch": "^3.0.0",
6565
"mocha": "^2.4.5",
66+
"object-assign": "^4.0.1",
6667
"rewire": "^2.5.1",
6768
"through": "^2.3.8",
6869
"tslint": "^3.6.0",

0 commit comments

Comments
 (0)