From 6b115dc2d64e6eef7fb30c15b1f859f26de388b0 Mon Sep 17 00:00:00 2001 From: Dcalsky Date: Thu, 17 Aug 2017 13:40:42 -0500 Subject: [PATCH] fix(@angular/cli): fix problem of SuppressPlugin in case entryFiles type is string (#7393) The type of entryFiles from entryPoint is array in webpack official suggested, but actually it could be string. The error caused by `every` method which is only invoked by array, however entryFiles is a string. Solution: if entryFiles is not array, make it as an array which includes just a single string element. --- .../suppress-entry-chunks-webpack-plugin.ts | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/packages/@angular/cli/plugins/suppress-entry-chunks-webpack-plugin.ts b/packages/@angular/cli/plugins/suppress-entry-chunks-webpack-plugin.ts index 765431902094..497e73b33320 100644 --- a/packages/@angular/cli/plugins/suppress-entry-chunks-webpack-plugin.ts +++ b/packages/@angular/cli/plugins/suppress-entry-chunks-webpack-plugin.ts @@ -8,14 +8,17 @@ export class SuppressExtractedTextChunksWebpackPlugin { compiler.plugin('compilation', function (compilation: any) { // find which chunks have css only entry points const cssOnlyChunks: string[] = []; - const entryPoints = compilation.options.entry; - // determine which entry points are composed entirely of css files - for (let entryPoint of Object.keys(entryPoints)) { - if (entryPoints[entryPoint].every((el: string) => - el.match(/\.(css|scss|sass|less|styl)$/))) { - cssOnlyChunks.push(entryPoint); - } + const entryPoints = compilation.options.entry; + // determine which entry points are composed entirely of css files + for (let entryPoint of Object.keys(entryPoints)) { + let entryFiles: string[]|string = entryPoints[entryPoint]; + // when type of entryFiles is not array, make it as an array + entryFiles = entryFiles instanceof Array ? entryFiles : [entryFiles]; + if (entryFiles.every((el: string) => + el.match(/\.(css|scss|sass|less|styl)$/) !== null)) { + cssOnlyChunks.push(entryPoint); } + } // Remove the js file for supressed chunks compilation.plugin('after-seal', (callback: any) => { compilation.chunks