@@ -35,6 +35,7 @@ import {
3535 hasPostcssConfiguration ,
3636 updateStyleImports ,
3737} from './stylesheet-updates' ;
38+ import { JsonObject } from '@angular-devkit/core' ;
3839
3940function * updateBuildTarget (
4041 projectName : string ,
@@ -362,10 +363,21 @@ export default function (): Rule {
362363 ) ,
363364 // Update main tsconfig
364365 updateJsonFile ( 'tsconfig.json' , ( rootJson ) => {
365- rootJson . modify ( [ 'compilerOptions' , 'esModuleInterop' ] , true ) ;
366+ let hasPreserveModule = false ;
367+ const compilerOptions = rootJson . get ( [ 'compilerOptions' ] ) ;
368+
369+ if ( compilerOptions && typeof compilerOptions === 'object' ) {
370+ const { module } = compilerOptions as JsonObject ;
371+ hasPreserveModule = typeof module === 'string' && module . toLowerCase ( ) === 'preserve' ;
372+ }
373+
374+ if ( ! hasPreserveModule ) {
375+ rootJson . modify ( [ 'compilerOptions' , 'esModuleInterop' ] , true ) ;
376+ rootJson . modify ( [ 'compilerOptions' , 'moduleResolution' ] , 'bundler' ) ;
377+ }
378+
366379 rootJson . modify ( [ 'compilerOptions' , 'downlevelIteration' ] , undefined ) ;
367380 rootJson . modify ( [ 'compilerOptions' , 'allowSyntheticDefaultImports' ] , undefined ) ;
368- rootJson . modify ( [ 'compilerOptions' , 'moduleResolution' ] , 'bundler' ) ;
369381 } ) ,
370382 ] ) ;
371383}
0 commit comments