You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

39 lines
1.2 KiB

4 years ago
  1. /*
  2. MIT License http://www.opensource.org/licenses/mit-license.php
  3. Author Tobias Koppers @sokra
  4. */
  5. var path = require('path');
  6. var loaderUtils = require('loader-utils');
  7. var validateOptions = require('schema-utils');
  8. module.exports = function () {};
  9. module.exports.pitch = function (request) {
  10. if (this.cacheable) this.cacheable();
  11. var options = loaderUtils.getOptions(this) || {};
  12. validateOptions(require('./options.json'), options, 'Style Loader (URL)');
  13. options.hmr = typeof options.hmr === 'undefined' ? true : options.hmr;
  14. var hmr = [
  15. // Hot Module Replacement
  16. "if(module.hot) {",
  17. " module.hot.accept(" + loaderUtils.stringifyRequest(this, "!!" + request) + ", function() {",
  18. " update(require(" + loaderUtils.stringifyRequest(this, "!!" + request) + "));",
  19. " });",
  20. "",
  21. " module.hot.dispose(function() { update(); });",
  22. "}"
  23. ].join("\n");
  24. return [
  25. // Adds some reference to a CSS file to the DOM by adding a <link> tag
  26. "var update = require(" + loaderUtils.stringifyRequest(this, "!" + path.join(__dirname, "lib", "addStyleUrl.js")) + ")(",
  27. " require(" + loaderUtils.stringifyRequest(this, "!!" + request) + ")",
  28. ", " + JSON.stringify(options) + ");",
  29. options.hmr ? hmr : ""
  30. ].join("\n");
  31. };