File tree Expand file tree Collapse file tree 6 files changed +27
-0
lines changed Expand file tree Collapse file tree 6 files changed +27
-0
lines changed Original file line number Diff line number Diff line change @@ -220,6 +220,11 @@ const BuildCommand = Command.extend({
220220 commandOptions . vendorChunk = ! commandOptions . buildOptimizer ;
221221 }
222222
223+ // Force commonjs module format for TS on dev watch builds.
224+ if ( commandOptions . target === 'development' && commandOptions . watch === true ) {
225+ commandOptions . forceTsCommonjs = true ;
226+ }
227+
223228 const BuildTask = require ( '../tasks/build' ) . default ;
224229
225230 const buildTask = new BuildTask ( {
Original file line number Diff line number Diff line change @@ -135,6 +135,11 @@ const ServeCommand = Command.extend({
135135 commandOptions . vendorChunk = ! commandOptions . buildOptimizer ;
136136 }
137137
138+ // Force commonjs module format for TS on dev builds.
139+ if ( commandOptions . target === 'development' ) {
140+ commandOptions . forceTsCommonjs = true ;
141+ }
142+
138143 // Default evalSourcemaps to true for serve. This makes rebuilds faster.
139144 commandOptions . evalSourcemaps = true ;
140145
Original file line number Diff line number Diff line change @@ -24,6 +24,7 @@ export interface TestOptions {
2424 environment ?: string ;
2525 app ?: string ;
2626 preserveSymlinks ?: boolean ;
27+ forceTsCommonjs ?: boolean ;
2728}
2829
2930
@@ -134,6 +135,13 @@ const TestCommand = Command.extend({
134135 // if not watching ensure karma is doing a single run
135136 commandOptions . singleRun = true ;
136137 }
138+
139+ // Don't force commonjs for code coverage builds, some setups need es2015 for it.
140+ // https://github.com/angular/angular-cli/issues/5526
141+ if ( ! commandOptions . codeCoverage ) {
142+ commandOptions . forceTsCommonjs = true ;
143+ }
144+
137145 return testTask . run ( commandOptions ) ;
138146 }
139147} ) ;
Original file line number Diff line number Diff line change @@ -30,4 +30,5 @@ export interface BuildOptions {
3030 buildOptimizer ?: boolean ;
3131 namedChunks ?: boolean ;
3232 subresourceIntegrity ?: boolean ;
33+ forceTsCommonjs ?: boolean ;
3334}
Original file line number Diff line number Diff line change @@ -21,10 +21,17 @@ const webpackLoader: string = g['angularCliIsLocal']
2121function _createAotPlugin ( wco : WebpackConfigOptions , options : any ) {
2222 const { appConfig, projectRoot, buildOptions } = wco ;
2323 options . compilerOptions = options . compilerOptions || { } ;
24+
2425 if ( wco . buildOptions . preserveSymlinks ) {
2526 options . compilerOptions . preserveSymlinks = true ;
2627 }
2728
29+ // Forcing commonjs seems to drastically improve rebuild speeds on webpack.
30+ // Dev builds on watch mode will set this option to true.
31+ if ( wco . buildOptions . forceTsCommonjs ) {
32+ options . compilerOptions . module = 'commonjs' ;
33+ }
34+
2835 // Read the environment, and set it in the compiler host.
2936 let hostReplacementPaths : any = { } ;
3037 // process environment file replacement
Original file line number Diff line number Diff line change @@ -44,6 +44,7 @@ export default Task.extend({
4444 poll : options . poll ,
4545 environment : options . environment ,
4646 preserveSymlinks : options . preserveSymlinks ,
47+ forceTsCommonjs : options . forceTsCommonjs ,
4748 app : options . app
4849 } ;
4950
You can’t perform that action at this time.
0 commit comments