11import * as path from 'path' ;
22import { stripIndent } from 'common-tags' ;
33import {
4- AotPlugin ,
5- AotPluginOptions ,
64 AngularCompilerPlugin ,
75 AngularCompilerPluginOptions ,
86 PLATFORM
@@ -80,47 +78,31 @@ function _createAotPlugin(wco: WebpackConfigOptions, options: any, useMain = tru
8078 } ;
8179 }
8280
83- if ( AngularCompilerPlugin . isSupported ( ) ) {
84- const additionalLazyModules : { [ module : string ] : string } = { } ;
85- if ( appConfig . lazyModules ) {
86- for ( const lazyModule of appConfig . lazyModules ) {
87- additionalLazyModules [ lazyModule ] = path . resolve (
88- projectRoot ,
89- appConfig . root ,
90- lazyModule ,
91- ) ;
92- }
81+ const additionalLazyModules : { [ module : string ] : string } = { } ;
82+ if ( appConfig . lazyModules ) {
83+ for ( const lazyModule of appConfig . lazyModules ) {
84+ additionalLazyModules [ lazyModule ] = path . resolve (
85+ projectRoot ,
86+ appConfig . root ,
87+ lazyModule ,
88+ ) ;
9389 }
94-
95- const pluginOptions : AngularCompilerPluginOptions = Object . assign ( { } , {
96- mainPath : useMain ? path . join ( projectRoot , appConfig . root , appConfig . main ) : undefined ,
97- i18nInFile : buildOptions . i18nFile ,
98- i18nInFormat : buildOptions . i18nFormat ,
99- i18nOutFile : buildOptions . i18nOutFile ,
100- i18nOutFormat : buildOptions . i18nOutFormat ,
101- locale : buildOptions . locale ,
102- platform : appConfig . platform === 'server' ? PLATFORM . Server : PLATFORM . Browser ,
103- missingTranslation : buildOptions . missingTranslation ,
104- hostReplacementPaths,
105- sourceMap : buildOptions . sourcemaps ,
106- additionalLazyModules,
107- } , options ) ;
108- return new AngularCompilerPlugin ( pluginOptions ) ;
109- } else {
110- const pluginOptions : AotPluginOptions = Object . assign ( { } , {
111- mainPath : path . join ( projectRoot , appConfig . root , appConfig . main ) ,
112- i18nFile : buildOptions . i18nFile ,
113- i18nFormat : buildOptions . i18nFormat ,
114- locale : buildOptions . locale ,
115- replaceExport : appConfig . platform === 'server' ,
116- missingTranslation : buildOptions . missingTranslation ,
117- hostReplacementPaths,
118- sourceMap : buildOptions . sourcemaps ,
119- // If we don't explicitely list excludes, it will default to `['**/*.spec.ts']`.
120- exclude : [ ]
121- } , options ) ;
122- return new AotPlugin ( pluginOptions ) ;
12390 }
91+
92+ const pluginOptions : AngularCompilerPluginOptions = Object . assign ( { } , {
93+ mainPath : useMain ? path . join ( projectRoot , appConfig . root , appConfig . main ) : undefined ,
94+ i18nInFile : buildOptions . i18nFile ,
95+ i18nInFormat : buildOptions . i18nFormat ,
96+ i18nOutFile : buildOptions . i18nOutFile ,
97+ i18nOutFormat : buildOptions . i18nOutFormat ,
98+ locale : buildOptions . locale ,
99+ platform : appConfig . platform === 'server' ? PLATFORM . Server : PLATFORM . Browser ,
100+ missingTranslation : buildOptions . missingTranslation ,
101+ hostReplacementPaths,
102+ sourceMap : buildOptions . sourcemaps ,
103+ additionalLazyModules,
104+ } , options ) ;
105+ return new AngularCompilerPlugin ( pluginOptions ) ;
124106}
125107
126108export function getNonAotConfig ( wco : WebpackConfigOptions ) {
@@ -136,67 +118,34 @@ export function getNonAotConfig(wco: WebpackConfigOptions) {
136118export function getAotConfig ( wco : WebpackConfigOptions ) {
137119 const { projectRoot, buildOptions, appConfig } = wco ;
138120 const tsConfigPath = path . resolve ( projectRoot , appConfig . root , appConfig . tsconfig ) ;
139- const testTsConfigPath = path . resolve ( projectRoot , appConfig . root , appConfig . testTsconfig ) ;
140121
141- let pluginOptions : any = { tsConfigPath } ;
142-
143- // Fallback to exclude spec files from AoT compilation on projects using a shared tsconfig.
144- if ( testTsConfigPath === tsConfigPath ) {
145- let exclude = [ '**/*.spec.ts' ] ;
146- if ( appConfig . test ) {
147- exclude . push ( path . join ( projectRoot , appConfig . root , appConfig . test ) ) ;
148- }
149- pluginOptions . exclude = exclude ;
150- }
151-
152- let boLoader : any = [ ] ;
122+ const loaders : any [ ] = [ webpackLoader ] ;
153123 if ( buildOptions . buildOptimizer ) {
154- boLoader = [ {
124+ loaders . unshift ( {
155125 loader : '@angular-devkit/build-optimizer/webpack-loader' ,
156126 options : { sourceMap : buildOptions . sourcemaps }
157- } ] ;
127+ } ) ;
158128 }
159129
160- const test = AngularCompilerPlugin . isSupported ( )
161- ? / (?: \. n g f a c t o r y \. j s | \. n g s t y l e \. j s | \. t s ) $ /
162- : / \. t s $ / ;
130+ const test = / (?: \. n g f a c t o r y \. j s | \. n g s t y l e \. j s | \. t s ) $ / ;
163131
164132 return {
165- module : { rules : [ { test, use : [ ... boLoader , webpackLoader ] } ] } ,
166- plugins : [ _createAotPlugin ( wco , pluginOptions ) ]
133+ module : { rules : [ { test, use : loaders } ] } ,
134+ plugins : [ _createAotPlugin ( wco , { tsConfigPath } ) ]
167135 } ;
168136}
169137
170138export function getNonAotTestConfig ( wco : WebpackConfigOptions ) {
171139 const { projectRoot, appConfig } = wco ;
172140 const tsConfigPath = path . resolve ( projectRoot , appConfig . root , appConfig . testTsconfig ) ;
173- const appTsConfigPath = path . resolve ( projectRoot , appConfig . root , appConfig . tsconfig ) ;
174141
175142 let pluginOptions : any = { tsConfigPath, skipCodeGeneration : true } ;
176143
177- if ( AngularCompilerPlugin . isSupported ( ) ) {
178- if ( appConfig . polyfills ) {
179- // TODO: remove singleFileIncludes for 2.0, this is just to support old projects that did not
180- // include 'polyfills.ts' in `tsconfig.spec.json'.
181- const polyfillsPath = path . resolve ( projectRoot , appConfig . root , appConfig . polyfills ) ;
182- pluginOptions . singleFileIncludes = [ polyfillsPath ] ;
183- }
184- } else {
185- // The options below only apply to AoTPlugin.
186- // Force include main and polyfills.
187- // This is needed for AngularCompilerPlugin compatibility with existing projects,
188- // since TS compilation there is stricter and tsconfig.spec.ts doesn't include them.
189- const include = [ appConfig . main , appConfig . polyfills , '**/*.spec.ts' ] ;
190- if ( appConfig . test ) {
191- include . push ( appConfig . test ) ;
192- }
193-
194- pluginOptions . include = include ;
195-
196- // Fallback to correct module format on projects using a shared tsconfig.
197- if ( tsConfigPath === appTsConfigPath ) {
198- pluginOptions . compilerOptions = { module : 'commonjs' } ;
199- }
144+ if ( appConfig . polyfills ) {
145+ // TODO: remove singleFileIncludes for 2.0, this is just to support old projects that did not
146+ // include 'polyfills.ts' in `tsconfig.spec.json'.
147+ const polyfillsPath = path . resolve ( projectRoot , appConfig . root , appConfig . polyfills ) ;
148+ pluginOptions . singleFileIncludes = [ polyfillsPath ] ;
200149 }
201150
202151 return {
0 commit comments