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