From 7febeb3fccfebaa3b2995140898125df32b589bc Mon Sep 17 00:00:00 2001 From: Ciro Nunes Date: Sun, 20 Mar 2016 17:33:58 +0100 Subject: [PATCH] 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 #41 --- lib/broccoli/angular2-app.js | 60 +++++++++++++++++++---------------- lib/broccoli/is-production.js | 1 + 2 files changed, 33 insertions(+), 28 deletions(-) create mode 100644 lib/broccoli/is-production.js diff --git a/lib/broccoli/angular2-app.js b/lib/broccoli/angular2-app.js index 57f560773c5e..67f2aa6a72a3 100644 --- a/lib/broccoli/angular2-app.js +++ b/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; @@ -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 }); @@ -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])]); }; @@ -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; }; - }*/ }; /** @@ -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) { @@ -187,7 +197,6 @@ Angular2App.prototype.contentFor = function(match, type) { return content; }, content); - return content.join('\n'); }; @@ -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) + } + ]; }; @@ -228,7 +233,6 @@ Angular2App.prototype.index = function() { description: 'Funnel: index.html' }); - return configReplace(index, { files: [ htmlName ], patterns: this._configReplacePatterns() diff --git a/lib/broccoli/is-production.js b/lib/broccoli/is-production.js new file mode 100644 index 000000000000..64885fd576ae --- /dev/null +++ b/lib/broccoli/is-production.js @@ -0,0 +1 @@ +module.exports = (/(^production$|^prod$)/).test(process.env.EMBER_ENV);