Skip to content

Commit e313917

Browse files
committed
1 parent 7b1e6f1 commit e313917

File tree

1 file changed

+32
-23
lines changed

1 file changed

+32
-23
lines changed

lib/processCss.js

+32-23
Original file line numberDiff line numberDiff line change
@@ -22,15 +22,18 @@ var parserPlugin = postcss.plugin("css-loader-parser", function(options) {
2222
var urlItems = [];
2323

2424
function replaceImportsInString(str) {
25-
var tokens = str.split(/(\S+)/);
26-
tokens = tokens.map(function(token) {
27-
var importIndex = imports["$" + token];
28-
if(typeof importIndex === "number") {
29-
return "___CSS_LOADER_IMPORT___" + importIndex + "___";
30-
}
31-
return token;
32-
});
33-
return tokens.join("");
25+
if(options.import) {
26+
var tokens = str.split(/(\S+)/);
27+
tokens = tokens.map(function (token) {
28+
var importIndex = imports["$" + token];
29+
if(typeof importIndex === "number") {
30+
return "___CSS_LOADER_IMPORT___" + importIndex + "___";
31+
}
32+
return token;
33+
});
34+
return tokens.join("");
35+
}
36+
return str;
3437
}
3538

3639
css.walkAtRules("import", function(rule) {
@@ -83,23 +86,27 @@ var parserPlugin = postcss.plugin("css-loader-parser", function(options) {
8386
value.nodes.forEach(function(item) {
8487
switch(item.type) {
8588
case "item":
86-
var importIndex = imports["$" + item.name];
87-
if(typeof importIndex === "number") {
88-
item.name = "___CSS_LOADER_IMPORT___" + importIndex + "___";
89+
if(options.import) {
90+
var importIndex = imports["$" + item.name];
91+
if(typeof importIndex === "number") {
92+
item.name = "___CSS_LOADER_IMPORT___" + importIndex + "___";
93+
}
8994
}
9095
break;
9196
case "url":
92-
if(!/^#/.test(item.url) && loaderUtils.isUrlRequest(item.url, options.root)) {
93-
item.stringType = "";
94-
delete item.innerSpacingBefore;
95-
delete item.innerSpacingAfter;
96-
var url = item.url;
97-
item.url = "___CSS_LOADER_URL___" + urlItems.length + "___";
98-
urlItems.push({
99-
url: url
100-
});
97+
if(options.url) {
98+
if(!/^#/.test(item.url) && loaderUtils.isUrlRequest(item.url, options.root)) {
99+
item.stringType = "";
100+
delete item.innerSpacingBefore;
101+
delete item.innerSpacingAfter;
102+
var url = item.url;
103+
item.url = "___CSS_LOADER_URL___" + urlItems.length + "___";
104+
urlItems.push({
105+
url: url
106+
});
107+
}
108+
break;
101109
}
102-
break;
103110
}
104111
});
105112
});
@@ -129,7 +136,9 @@ module.exports = function processCss(inputSource, inputMap, options, callback) {
129136

130137
var parserOptions = {
131138
root: root,
132-
mode: options.mode
139+
mode: options.mode,
140+
url: !query.hasOwnProperty('url'),
141+
import: !query.hasOwnProperty('import')
133142
};
134143

135144
var pipeline = postcss([

0 commit comments

Comments
 (0)