loader.js 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. 'use strict';
  2. var path = require('path');
  3. var loaderUtils = require('loader-utils');
  4. var process = require('./process');
  5. /**
  6. * Webpack loader that manipulates the source-map of a preceding loader.
  7. * @this {object} The loader context
  8. * @param {string} content The content
  9. * @param {object} sourceMap The source-map
  10. * @returns {string|String}
  11. */
  12. function loader(content, sourceMap) {
  13. /* jshint validthis:true */
  14. // loader result is cacheable
  15. this.cacheable();
  16. // webpack 1: prefer loader query, else options object
  17. // webpack 2: prefer loader options
  18. // webpack 3: deprecate loader.options object
  19. // webpack 4: loader.options no longer defined
  20. var options = Object.assign(
  21. {},
  22. this.options && this.options.adjustSourcemapLoader,
  23. loaderUtils.getOptions(this),
  24. {sep: path.sep}
  25. );
  26. // process the source-map
  27. var outputMap = process(this, options, sourceMap);
  28. // need to use callback when there are multiple arguments
  29. this.callback(null, content, outputMap);
  30. }
  31. module.exports = loader;