File size: 1,036 Bytes
cc651f6
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
'use strict';

var path = require('path');

var loaderUtils = require('loader-utils');

var process = require('./process');

/**
 * Webpack loader that manipulates the source-map of a preceding loader.
 * @this {object} The loader context
 * @param {string} content The content
 * @param {object} sourceMap The source-map
 * @returns {string|String}
 */
function loader(content, sourceMap) {
  /* jshint validthis:true */

  // loader result is cacheable
  this.cacheable();

  // webpack 1: prefer loader query, else options object
  // webpack 2: prefer loader options
  // webpack 3: deprecate loader.options object
  // webpack 4: loader.options no longer defined
  var options = Object.assign(
    {},
    this.options && this.options.adjustSourcemapLoader,
    loaderUtils.getOptions(this),
    {sep: path.sep}
  );

  // process the source-map
  var outputMap = process(this, options, sourceMap);

  // need to use callback when there are multiple arguments
  this.callback(null, content, outputMap);
}

module.exports = loader;