11'use strict' ;
22const path = require ( 'path' ) ;
3+ const fs = require ( 'fs' ) ;
34
45const isProduction = require ( './is-production' ) ;
56const BroccoliPlugin = require ( 'broccoli-writer' ) ;
67const BroccoliConfigReplace = require ( './broccoli-config-replace' ) ;
78const BroccoliTypescript = require ( './broccoli-typescript' ) ;
89const BroccoliSwManifest = require ( './service-worker-manifest' ) . default ;
10+ const BundlePlugin = require ( './angular-broccoli-bundle' ) ;
911const BroccoliFunnel = require ( 'broccoli-funnel' ) ;
1012const BroccoliMergeTrees = require ( 'broccoli-merge-trees' ) ;
11- const BroccoliUglify = require ( 'broccoli-uglify-js' ) ;
13+ const BroccoliSource = require ( 'broccoli-source' ) ;
14+ const UnwatchedDir = BroccoliSource . UnwatchedDir ;
1215const Project = require ( 'ember-cli/lib/models/project' ) ;
1316const config = require ( '../../addon/ng2/models/config' ) ;
1417
15-
1618class Angular2App extends BroccoliPlugin {
1719 constructor ( project , inputNode , options ) {
1820 const ngConfig = config . CliConfig . fromProject ( ) ;
19-
21+
2022 if ( ! options ) {
2123 options = inputNode ;
2224 inputNode = null ;
@@ -117,7 +119,7 @@ class Angular2App extends BroccoliPlugin {
117119 }
118120 } ) ) ;
119121 }
120-
122+
121123 // Add the public folder in.
122124 buildTrees . push ( new BroccoliFunnel ( this . _inputNode , {
123125 include : [ 'public/**/*' ] ,
@@ -131,7 +133,12 @@ class Angular2App extends BroccoliPlugin {
131133 } ) ) ;
132134
133135 var merged = new BroccoliMergeTrees ( buildTrees , { overwrite : true } ) ;
134- merged = new BroccoliMergeTrees ( [ merged , new BroccoliSwManifest ( [ merged ] ) ] ) ;
136+
137+ if ( isProduction ) {
138+ merged = this . _getBundleTree ( merged ) ;
139+ merged = new BroccoliMergeTrees ( [ merged , new BroccoliSwManifest ( [ merged ] ) ] ) ;
140+ }
141+
135142 return new BroccoliFunnel ( merged , {
136143 destDir : this . _destDir
137144 } ) ;
@@ -279,7 +286,6 @@ class Angular2App extends BroccoliPlugin {
279286
280287 if ( isProduction ) {
281288 tsTreeExcludes . push ( excludeSpecFiles ) ;
282- tsTree = BroccoliUglify ( tsTree ) ;
283289 }
284290
285291 tsTree = new BroccoliFunnel ( tsTree , {
@@ -307,7 +313,7 @@ class Angular2App extends BroccoliPlugin {
307313 vendorNpmFiles = vendorNpmFiles . concat ( this . _options . vendorNpmFiles ) ;
308314 }
309315
310- return new BroccoliFunnel ( 'node_modules' , {
316+ return new BroccoliFunnel ( new UnwatchedDir ( 'node_modules' ) , {
311317 include : vendorNpmFiles ,
312318 destDir : 'vendor' ,
313319 name : 'vendor'
@@ -357,6 +363,25 @@ class Angular2App extends BroccoliPlugin {
357363 getDestinationPath : ( ) => 'environment.ts'
358364 } ) ;
359365 }
366+
367+ _getBundleTree ( preBundleTree ) {
368+ var indexFile = path . join ( this . _sourceDir , 'index.html' ) ;
369+ var indexContent = fs . readFileSync ( indexFile , 'utf8' ) ;
370+ var scriptTagVendorFiles = indexContent . match ( / v e n d o r \/ [ ^ " ' ] * \. j s / gi) ;
371+
372+ var scriptTree = new BroccoliFunnel ( preBundleTree , {
373+ include : scriptTagVendorFiles
374+ } ) ;
375+
376+ var nonJsTree = new BroccoliFunnel ( preBundleTree , {
377+ exclude : [ '**/*.js' , '**/*.js.map' ]
378+ } ) ;
379+ var jsTree = new BroccoliFunnel ( preBundleTree , {
380+ include : [ '**/*.js' ]
381+ } ) ;
382+
383+ return BroccoliMergeTrees ( [ nonJsTree , scriptTree , new BundlePlugin ( [ jsTree ] ) ] , { overwrite : true } ) ;
384+ }
360385}
361386
362387module . exports = Angular2App ;
0 commit comments