1 |
|
2 |
|
3 |
|
4 |
|
5 | var loaderUtils = require("loader-utils"),
|
6 | path = require("path");
|
7 | module.exports = function() {};
|
8 | module.exports.pitch = function(remainingRequest) {
|
9 | if(this.cacheable) this.cacheable();
|
10 | var query = loaderUtils.parseQuery(this.query);
|
11 | return [
|
12 | "// style-loader: Adds some css to the DOM by adding a <style> tag",
|
13 | "",
|
14 | "// load the styles",
|
15 | "var content = require(" + loaderUtils.stringifyRequest(this, "!!" + remainingRequest) + ");",
|
16 | "if(typeof content === 'string') content = [[module.id, content, '']];",
|
17 | "// add the styles to the DOM",
|
18 | "var update = require(" + loaderUtils.stringifyRequest(this, "!" + path.join(__dirname, "addStyles.js")) + ")(content, " + JSON.stringify(query) + ");",
|
19 | "if(content.locals) module.exports = content.locals;",
|
20 | "// Hot Module Replacement",
|
21 | "if(module.hot) {",
|
22 | " // When the styles change, update the <style> tags",
|
23 | " if(!content.locals) {",
|
24 | " module.hot.accept(" + loaderUtils.stringifyRequest(this, "!!" + remainingRequest) + ", function() {",
|
25 | " var newContent = require(" + loaderUtils.stringifyRequest(this, "!!" + remainingRequest) + ");",
|
26 | " if(typeof newContent === 'string') newContent = [[module.id, newContent, '']];",
|
27 | " update(newContent);",
|
28 | " });",
|
29 | " }",
|
30 | " // When the module is disposed, remove the <style> tags",
|
31 | " module.hot.dispose(function() { update(); });",
|
32 | "}"
|
33 | ].join("\n");
|
34 | };
|