@@ -11,6 +11,7 @@ import {
1111} from '@angular-devkit/build-optimizer' ;
1212import { tags } from '@angular-devkit/core' ;
1313import * as CopyWebpackPlugin from 'copy-webpack-plugin' ;
14+ import { existsSync } from 'fs' ;
1415import * as path from 'path' ;
1516import { RollupOptions } from 'rollup' ;
1617import { ScriptTarget } from 'typescript' ;
@@ -214,23 +215,28 @@ export function getCommonConfig(wco: WebpackConfigOptions): Configuration {
214215 buildOptions . scripts ,
215216 'scripts' ,
216217 ) . reduce ( ( prev : { bundleName : string ; paths : string [ ] ; inject : boolean } [ ] , curr ) => {
217- const bundleName = curr . bundleName ;
218- const resolvedPath = path . resolve ( root , curr . input ) ;
218+ const { bundleName, inject, input } = curr ;
219+ const resolvedPath = path . resolve ( root , input ) ;
220+
221+ if ( ! existsSync ( resolvedPath ) ) {
222+ throw new Error ( `Script file ${ input } does not exist.` ) ;
223+ }
224+
219225 const existingEntry = prev . find ( el => el . bundleName === bundleName ) ;
220226 if ( existingEntry ) {
221- if ( existingEntry . inject && ! curr . inject ) {
227+ if ( existingEntry . inject && ! inject ) {
222228 // All entries have to be lazy for the bundle to be lazy.
223229 throw new Error (
224- `The ${ curr . bundleName } bundle is mixing injected and non-injected scripts.` ,
230+ `The ${ bundleName } bundle is mixing injected and non-injected scripts.` ,
225231 ) ;
226232 }
227233
228234 existingEntry . paths . push ( resolvedPath ) ;
229235 } else {
230236 prev . push ( {
231237 bundleName,
238+ inject,
232239 paths : [ resolvedPath ] ,
233- inject : curr . inject ,
234240 } ) ;
235241 }
236242
0 commit comments