Skip to content

Commit

Permalink
Support force disabling sourcemaps and setting sourceRoot
Browse files Browse the repository at this point in the history
style-loader will also now look for config options set by a LoaderOptionsPlugin
  • Loading branch information
kherock committed Feb 24, 2017
1 parent 8ab1c5f commit 3e961e3
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
5 changes: 5 additions & 0 deletions addStyles.js
Original file line number Diff line number Diff line change
Expand Up @@ -143,12 +143,17 @@ function createLinkElement(options) {
function addStyle(obj, options) {
var styleElement, update, remove;

if (obj.sourceMap && typeof options.sourceRoot === "string") {
obj.sourceMap.sourceRoot = options.sourceRoot;
}

if (options.singleton) {
var styleIndex = singletonCounter++;
styleElement = singletonElement || (singletonElement = createStyleElement(options));
update = applyToSingletonTag.bind(null, styleElement, styleIndex, false);
remove = applyToSingletonTag.bind(null, styleElement, styleIndex, true);
} else if(obj.sourceMap &&
options.sourceMap !== false &&
typeof URL === "function" &&
typeof URL.createObjectURL === "function" &&
typeof URL.revokeObjectURL === "function" &&
Expand Down
4 changes: 2 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,15 @@ var loaderUtils = require("loader-utils"),
module.exports = function() {};
module.exports.pitch = function(remainingRequest) {
if(this.cacheable) this.cacheable();
var query = loaderUtils.parseQuery(this.query);
var config = loaderUtils.getLoaderConfig(this, "styleLoader");
return [
"// style-loader: Adds some css to the DOM by adding a <style> tag",
"",
"// load the styles",
"var content = require(" + loaderUtils.stringifyRequest(this, "!!" + remainingRequest) + ");",
"if(typeof content === 'string') content = [[module.id, content, '']];",
"// add the styles to the DOM",
"var update = require(" + loaderUtils.stringifyRequest(this, "!" + path.join(__dirname, "addStyles.js")) + ")(content, " + JSON.stringify(query) + ");",
"var update = require(" + loaderUtils.stringifyRequest(this, "!" + path.join(__dirname, "addStyles.js")) + ")(content, " + JSON.stringify(config) + ");",
"if(content.locals) module.exports = content.locals;",
"// Hot Module Replacement",
"if(module.hot) {",
Expand Down

0 comments on commit 3e961e3

Please sign in to comment.