From 334cc202d2ac00f7118dba1b4854dd21d6b3150c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kai=20R=C3=B6der?= Date: Wed, 2 Oct 2019 17:05:21 +0200 Subject: [PATCH] fix bug that causes an error when style files are empty --- app/angular/src/server/ngx-template-loader/index.ts | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/app/angular/src/server/ngx-template-loader/index.ts b/app/angular/src/server/ngx-template-loader/index.ts index 4ab1c7226860..6e2d2381ee14 100644 --- a/app/angular/src/server/ngx-template-loader/index.ts +++ b/app/angular/src/server/ngx-template-loader/index.ts @@ -18,7 +18,11 @@ const replaceStringsWithRequires = (string: string) => { if (url.charAt(0) !== '.') { newUrl = `./${url}`; } - return `(require('${newUrl}').default || require('${newUrl}'))`; + const requireString = `(require('${newUrl}').default || require('${newUrl}'))`; + + // without the length check an empty style file will throw + // "Expected 'styles' to be an array of strings" + return `${requireString}.length ? ${requireString} : ''`; }); }; @@ -35,12 +39,10 @@ export default function(source: string) { return `${templateProperty}:${replaceStringsWithRequires(templateUrlString)}`; }) .replace(stylesRegex, (_, styleUrlsString: string) => { - console.log(styleUrlsString); // replace: stylesUrl: ['./foo.css', "./baz.css", "./index.component.css"] // with: styles: [require('./foo.css'), require("./baz.css"), require("./index.component.css")] // or: styleUrls: [require('./foo.css'), require("./baz.css"), require("./index.component.css")] // if `keepUrl` query parameter is set to true. - console.log(`${styleProperty}:${replaceStringsWithRequires(styleUrlsString)}`); return `${styleProperty}:${replaceStringsWithRequires(styleUrlsString)}`; }); }