url.js 1.1 KB

1234567891011121314151617181920212223242526272829303132
  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. return [
  14. "// style-loader: Adds some reference to a css file to the DOM by adding a <link> tag",
  15. "var update = require(" + loaderUtils.stringifyRequest(this, "!" + path.join(__dirname, "lib", "addStyleUrl.js")) + ")(",
  16. "\trequire(" + loaderUtils.stringifyRequest(this, "!!" + request) + ")",
  17. ", " + JSON.stringify(options) + ");",
  18. "// Hot Module Replacement",
  19. "if(module.hot) {",
  20. "\tmodule.hot.accept(" + loaderUtils.stringifyRequest(this, "!!" + request) + ", function() {",
  21. "\t\tupdate(require(" + loaderUtils.stringifyRequest(this, "!!" + request) + "));",
  22. "\t});",
  23. "\tmodule.hot.dispose(function() { update(); });",
  24. "}"
  25. ].join("\n");
  26. };