Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ var templateUrlRegex = /templateUrl\s*:(\s*['"`](.*?)['"`]\s*([,}]))/gm;
var stylesRegex = /styleUrls *:(\s*\[[^\]]*?\])/g;
var stringRegex = /(['`"])((?:[^\\]\\\1|.)*?)\1/g;

function replaceStringsWithRequires(string) {
function replaceStringsWithRequires(string, keepPath) {
return string.replace(stringRegex, function (match, quote, url) {
if (url.charAt(0) !== ".") {
if (url.charAt(0) !== "." && !keepPath) {
url = "./" + url;
}
return "require('" + url + "')";
Expand All @@ -33,6 +33,8 @@ module.exports = function(source, sourcemap) {
templateProperty = 'templateUrl';
}

var keepPath = config.keepPath === true;

// Not cacheable during unit tests;
this.cacheable && this.cacheable();

Expand All @@ -41,14 +43,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, keepPath);
})
.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, keepPath);
});

// Support for tests
Expand Down
Loading