UNPKG

1.25 kBJavaScriptView Raw
1/*
2 MIT License http://www.opensource.org/licenses/mit-license.php
3 Author Tobias Koppers @sokra
4*/
5var path = require('path');
6
7var loaderUtils = require('loader-utils');
8var validateOptions = require('schema-utils');
9
10module.exports = function () {};
11
12module.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 // Hot Module Replacement
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 // Adds some reference to a CSS file to the DOM by adding a <link> tag
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};