Created
April 17, 2016 14:51
-
-
Save lipelopeslage/7533547064ea08819c762311ca16b64a to your computer and use it in GitHub Desktop.
A url workaround in CSS image paths using webpack.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
USAGE: | |
webpack.config.js: | |
[..] loaders:{ | |
{ test: /\.(png|jpg)$/, loader: 'url-css-loader-workaround?relativePath=./../..&name=[path][name].[ext]' } | |
} | |
*/ | |
var loaderUtils = require("loader-utils"); | |
module.exports = function(content) { | |
var query = loaderUtils.parseQuery(this.query); | |
var url = loaderUtils.interpolateName(this, query.name || "[hash].[ext]", { | |
context: this.options.context, | |
content: content, | |
regExp: query.regExp | |
}); | |
url = query.relativePath+url.substr(1, url.length-1); | |
return "module.exports = __webpack_public_path__ + " + JSON.stringify(url) + ";"; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment