1 |
|
2 |
|
3 |
|
4 |
|
5 | var path = require('path');
|
6 |
|
7 | var loaderUtils = require('loader-utils');
|
8 | var validateOptions = require('schema-utils');
|
9 |
|
10 | module.exports = function () {};
|
11 |
|
12 | module.exports.pitch = function (request) {
|
13 | if (this.cacheable) this.cacheable();
|
14 |
|
15 | var options = loaderUtils.getOptions(this) || {};
|
16 |
|
17 | validateOptions(require('./options.json'), options, 'Style Loader (URL)');
|
18 |
|
19 | options.hmr = typeof options.hmr === 'undefined' ? true : options.hmr;
|
20 |
|
21 | var hmr = [
|
22 |
|
23 | "if(module.hot) {",
|
24 | " module.hot.accept(" + loaderUtils.stringifyRequest(this, "!!" + request) + ", function() {",
|
25 | " update(require(" + loaderUtils.stringifyRequest(this, "!!" + request) + "));",
|
26 | " });",
|
27 | "",
|
28 | " module.hot.dispose(function() { update(); });",
|
29 | "}"
|
30 | ].join("\n");
|
31 |
|
32 | return [
|
33 |
|
34 | "var update = require(" + loaderUtils.stringifyRequest(this, "!" + path.join(__dirname, "lib", "addStyleUrl.js")) + ")(",
|
35 | " require(" + loaderUtils.stringifyRequest(this, "!!" + request) + ")",
|
36 | ", " + JSON.stringify(options) + ");",
|
37 | options.hmr ? hmr : ""
|
38 | ].join("\n");
|
39 | };
|