Skip to content

Commit

Permalink
fix bug that causes an error when style files are empty
Browse files Browse the repository at this point in the history
  • Loading branch information
kroeder committed Oct 2, 2019
1 parent bbed3b0 commit 334cc20
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions app/angular/src/server/ngx-template-loader/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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} : ''`;
});
};

Expand All @@ -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)}`;
});
}

0 comments on commit 334cc20

Please sign in to comment.