Skip to content
Merged
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
1 change: 1 addition & 0 deletions lib/loader.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ module.exports = function(content, map) {
from: loaderUtils.getRemainingRequest(this).split("!").pop(),
to: loaderUtils.getCurrentRequest(this).split("!").pop(),
query: query,
resolve: resolve,
minimize: this.minimize,
loaderContext: this,
sourceMap: sourceMap
Expand Down
10 changes: 8 additions & 2 deletions lib/processCss.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,11 @@ var parserPlugin = postcss.plugin("css-loader-parser", function(options) {
exports[exportName] = replaceImportsInString(exports[exportName]);
});

function isAlias(url) {
// Handle alias starting by / and root disabled
return url !== options.resolve(url)
}

function processNode(item) {
switch (item.type) {
case "value":
Expand All @@ -98,7 +103,7 @@ var parserPlugin = postcss.plugin("css-loader-parser", function(options) {
}
break;
case "url":
if (options.url && item.url.replace(/\s/g, '').length && !/^#/.test(item.url) && loaderUtils.isUrlRequest(item.url, options.root)) {
if (options.url && item.url.replace(/\s/g, '').length && !/^#/.test(item.url) && (isAlias(item.url) || loaderUtils.isUrlRequest(item.url, options.root))) {
// Don't remove quotes around url when contain space
if (item.url.indexOf(" ") === -1) {
item.stringType = "";
Expand Down Expand Up @@ -149,7 +154,8 @@ module.exports = function processCss(inputSource, inputMap, options, callback) {
root: root,
mode: options.mode,
url: query.url !== false,
import: query.import !== false
import: query.import !== false,
resolve: options.resolve
};

var pipeline = postcss([
Expand Down
27 changes: 27 additions & 0 deletions test/aliasTest.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,30 @@ describe("alias", function() {
test("exactMatch", css, exports.exactMatch, aliasOptions({ "./path/to/file.png$": "module/file.png" }));
test("notExactMatch", css, exports.notExactMatch, aliasOptions({ "./path/to/file.jpg$": "module/file.jpg" }));
});

describe("alias starting with /", function() {
var css = ".className { background: url(/path/to/file.png); }";
var exports = {
without: [
[1, ".className { background: url(/path/to/file.png); }", ""]
],
onlyModule: [
[1, ".className { background: url({module/file.png}); }", ""]
],
exactMatch: [
[1, ".className { background: url({module/file.png}); }", ""]
],
notExactMatch: [
[1, ".className { background: url(/path/to/file.png); }", ""]
]
};

function aliasOptions(alias) {
return { query: { alias: alias }}
}

test("without", css, exports.without);
test("onlyModule", css, exports.onlyModule, aliasOptions({ "/path/to": "module" }));
test("exactMatch", css, exports.exactMatch, aliasOptions({ "/path/to/file.png$": "module/file.png" }));
test("notExactMatch", css, exports.notExactMatch, aliasOptions({ "/path/to/file.jpg$": "module/file.jpg" }));
});