From 925b1fcf81cae425f8f55e3e5c6a5243a28b324b Mon Sep 17 00:00:00 2001 From: dcalsky Date: Tue, 15 Aug 2017 19:58:15 +0800 Subject: [PATCH 1/2] fix(@angular/cli): fix problem of SuppressPlugin in case entryFiles type is string 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. --- .../cli/plugins/suppress-entry-chunks-webpack-plugin.ts | 7 +++++-- 1 file changed, 5 insertions(+), 2 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..2b40e0c63f20 100644 --- a/packages/@angular/cli/plugins/suppress-entry-chunks-webpack-plugin.ts +++ b/packages/@angular/cli/plugins/suppress-entry-chunks-webpack-plugin.ts @@ -11,8 +11,11 @@ export class SuppressExtractedTextChunksWebpackPlugin { 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)$/))) { + 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); } } From 446783869f7da511d05dd2df73d6130591ad2b25 Mon Sep 17 00:00:00 2001 From: dcalsky Date: Tue, 15 Aug 2017 20:15:10 +0800 Subject: [PATCH 2/2] style(@angular/cli): add missed semi-colons and format code indent for SuppressPlugin --- .../suppress-entry-chunks-webpack-plugin.ts | 20 +++++++++---------- 1 file changed, 10 insertions(+), 10 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 2b40e0c63f20..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,17 +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)) { - 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); - } + 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