chore: replace `URL` dependence in moduleId loader (#3418)
IE, Edge, and some other browsers don't support `URL`. Replace it with standard DOM techniques.
This commit is contained in:
parent
3cf43d66d1
commit
a083fdbe8b
|
@ -3,15 +3,17 @@ var stylesRegex = /styleUrls *:(\s*\[[^\]]*?\])/g;
|
|||
var stringRegex = /(['`"])((?:[^\\]\\\1|.)*?)\1/g;
|
||||
|
||||
module.exports.translate = function(load){
|
||||
|
||||
var url = new URL(load.address);
|
||||
var url = document.createElement('a');
|
||||
url.href = load.address;
|
||||
|
||||
var basePathParts = url.pathname.split('/');
|
||||
|
||||
basePathParts.pop();
|
||||
var basePath = basePathParts.join('/');
|
||||
|
||||
var baseHref = new URL(this.baseURL).pathname;
|
||||
var baseHref = document.createElement('a');
|
||||
baseHref.href = this.baseURL;
|
||||
baseHref = baseHref.pathname;
|
||||
|
||||
basePath = basePath.replace(baseHref, '');
|
||||
|
||||
|
@ -23,16 +25,16 @@ module.exports.translate = function(load){
|
|||
resolvedUrl = basePath + url.substr(1);
|
||||
}
|
||||
|
||||
return `templateUrl: '${resolvedUrl}'`;
|
||||
return 'templateUrl: "' + resolvedUrl + '"';
|
||||
})
|
||||
.replace(stylesRegex, function(match, relativeUrls) {
|
||||
var urls = [];
|
||||
|
||||
while ((match = stringRegex.exec(relativeUrls)) !== null) {
|
||||
if (match[2].startsWith('.')) {
|
||||
urls.push(`'${basePath}${match[2].substr(1)}'`);
|
||||
urls.push('"' + basePath + match[2].substr(1) + '"');
|
||||
} else {
|
||||
urls.push(`'${match[2]}'`);
|
||||
urls.push('"' + match[2] + '"');
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue