From 63567f266a21eecef36b26394e441bae95d6e47d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Chopin?= Date: Wed, 30 Aug 2017 18:27:15 +0200 Subject: [PATCH 1/2] fix: add support for aliases starting with `/` (`options.alias`) (#597) * Add support for alias starting with / * startByAlias -> isAlias --- lib/loader.js | 1 + lib/processCss.js | 10 ++++++++-- test/aliasTest.js | 27 +++++++++++++++++++++++++++ 3 files changed, 36 insertions(+), 2 deletions(-) diff --git a/lib/loader.js b/lib/loader.js index ca856cd3..cb8ff307 100644 --- a/lib/loader.js +++ b/lib/loader.js @@ -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 diff --git a/lib/processCss.js b/lib/processCss.js index 944bc89f..8979f7ad 100644 --- a/lib/processCss.js +++ b/lib/processCss.js @@ -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": @@ -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 = ""; @@ -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([ diff --git a/test/aliasTest.js b/test/aliasTest.js index 19ebaf16..2805c0bb 100644 --- a/test/aliasTest.js +++ b/test/aliasTest.js @@ -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" })); +}); From d18ee04e12edb76ed7937df5183e239131cbdaeb Mon Sep 17 00:00:00 2001 From: Joshua Wiens Date: Wed, 30 Aug 2017 11:28:22 -0500 Subject: [PATCH 2/2] chore(release): 0.28.6 --- CHANGELOG.md | 10 ++++++++++ package.json | 2 +- 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 46716b1c..9f09e999 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,16 @@ All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines. + +## [0.28.6](https://github.com/webpack/css-loader/compare/v0.28.5...v0.28.6) (2017-08-30) + + +### Bug Fixes + +* add support for aliases starting with `/` (`options.alias`) ([#597](https://github.com/webpack/css-loader/issues/597)) ([63567f2](https://github.com/webpack/css-loader/commit/63567f2)) + + + ## [0.28.5](https://github.com/webpack/css-loader/compare/v0.28.4...v0.28.5) (2017-08-17) diff --git a/package.json b/package.json index 9de4fc63..205f8d4d 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "css-loader", - "version": "0.28.5", + "version": "0.28.6", "author": "Tobias Koppers @sokra", "description": "css loader module for webpack", "engines": {