Skip to content
This repository was archived by the owner on Feb 6, 2019. It is now read-only.

Commit bbf76d8

Browse files
authored
feat: ignore NS resource urls when processing css (#2)
1 parent 5570df9 commit bbf76d8

File tree

1 file changed

+22
-4
lines changed

1 file changed

+22
-4
lines changed

lib/processCss.js

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ var parserPlugin = postcss.plugin("css-loader-parser", function(options) {
4949
values.nodes[0].nodes.shift();
5050
var mediaQuery = Tokenizer.stringifyValues(values);
5151
if(loaderUtils.isUrlRequest(url, options.root) && options.mode === "global") {
52-
url = loaderUtils.urlToRequest(url, options.root);
52+
url = urlToRequest(url, options.root);
5353
}
5454
importItems.push({
5555
url: url,
@@ -98,7 +98,11 @@ var parserPlugin = postcss.plugin("css-loader-parser", function(options) {
9898
}
9999
break;
100100
case "url":
101-
if (options.url && !/^#/.test(item.url) && loaderUtils.isUrlRequest(item.url, options.root)) {
101+
if (options.url &&
102+
!/^#/.test(item.url) &&
103+
loaderUtils.isUrlRequest(item.url, options.root) &&
104+
!isResourceUrl(item.url)
105+
) {
102106
item.stringType = "";
103107
delete item.innerSpacingBefore;
104108
delete item.innerSpacingAfter;
@@ -141,7 +145,7 @@ module.exports = function processCss(inputSource, inputMap, options, callback) {
141145
var minimize = typeof forceMinimize !== "undefined" ? !!forceMinimize : options.minimize;
142146

143147
var customGetLocalIdent = query.getLocalIdent || getLocalIdent;
144-
148+
145149
var parserOptions = {
146150
root: root,
147151
mode: options.mode,
@@ -158,7 +162,7 @@ module.exports = function processCss(inputSource, inputMap, options, callback) {
158162
return url;
159163
}
160164
if(global) {
161-
return loaderUtils.urlToRequest(url, root);
165+
return urlToRequest(url, root);
162166
}
163167
}
164168
return url;
@@ -248,5 +252,19 @@ function CSSLoaderError(name, message, loc, source, error) {
248252
this.hideStack = true;
249253
}
250254

255+
function urlToRequest(url, root) {
256+
url = loaderUtils.urlToRequest(url, root);
257+
258+
return isResourceUrl(url) ? trimLocalUrl(url) : url;
259+
}
260+
261+
function trimLocalUrl(url) {
262+
return url.replace(/\.\/(.+)/, "$1");
263+
}
264+
265+
function isResourceUrl(url) {
266+
return /~*res:\/\/(.+)/.test(url);
267+
}
268+
251269
CSSLoaderError.prototype = Object.create(Error.prototype);
252270
CSSLoaderError.prototype.constructor = CSSLoaderError;

0 commit comments

Comments
 (0)