From 426977775e4d8730b37b440788c0b6598ff73608 Mon Sep 17 00:00:00 2001 From: Anders Blenstrup-Pedersen Date: Mon, 6 Feb 2017 17:15:53 +0900 Subject: [PATCH 1/3] Adding case insensitivity this fixes a bug where its not altering the templateUrl and leaves it as templateUrl: require() instead of template: require(), even when keepUrl is false --- index.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/index.js b/index.js index b708d29..d7fa640 100644 --- a/index.js +++ b/index.js @@ -2,9 +2,9 @@ var loaderUtils = require("loader-utils"); // using: regex, capture groups, and capture group variables. -var templateUrlRegex = /templateUrl\s*:(\s*['"`](.*?)['"`]([,}\n]))/gm; -var stylesRegex = /styleUrls *:(\s*\[[^\]]*?\])/g; -var stringRegex = /(['"])((?:[^\\]\\\1|.)*?)\1/g; +var templateUrlRegex = /templateUrl\s*:\s*(['"`](.*?)['"`]([,}\n]))/igm; +var stylesRegex = /styleUrls\s*:\s*(\[[^\]]*?\])/ig; +var stringRegex = /(['"])((?:[^\\]\\\1|.)*?)\1/ig; function replaceStringsWithRequires(string) { return string.replace(stringRegex, function (match, quote, url) { From 1682025bddbebccfd9f1d7f99912997f5c690e6c Mon Sep 17 00:00:00 2001 From: Anders Blenstrup-Pedersen Date: Mon, 6 Feb 2017 17:36:06 +0900 Subject: [PATCH 2/3] adding fix according to travis CI results --- index.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/index.js b/index.js index d7fa640..fa56ffd 100644 --- a/index.js +++ b/index.js @@ -11,7 +11,7 @@ function replaceStringsWithRequires(string) { if (url.charAt(0) !== ".") { url = "./" + url; } - return "require('" + url + "')"; + return "require(\"" + url + "\")"; }); } @@ -41,14 +41,14 @@ module.exports = function(source, sourcemap) { // with: template: require('./path/to/template.html') // or: templateUrl: require('./path/to/template.html') // if `keepUrl` query parameter is set to true. - return templateProperty + ":" + replaceStringsWithRequires(url); + return templateProperty + ": " + replaceStringsWithRequires(url); }) .replace(stylesRegex, function (match, urls) { // 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. - return styleProperty + ":" + replaceStringsWithRequires(urls); + return styleProperty + ": " + replaceStringsWithRequires(urls); }); // Support for tests From 23b466e20d84a629ec37c19d1e97d27dd02469bc Mon Sep 17 00:00:00 2001 From: Anders Blenstrup-Pedersen Date: Mon, 6 Feb 2017 17:39:59 +0900 Subject: [PATCH 3/3] removing double quotes (consider changing the test to use double maybe?) --- index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/index.js b/index.js index fa56ffd..cfd4432 100644 --- a/index.js +++ b/index.js @@ -11,7 +11,7 @@ function replaceStringsWithRequires(string) { if (url.charAt(0) !== ".") { url = "./" + url; } - return "require(\"" + url + "\")"; + return "require('" + url + "')"; }); }