| 1 | /*
|
|---|
| 2 | MIT License http://www.opensource.org/licenses/mit-license.php
|
|---|
| 3 | Author Tobias Koppers @sokra
|
|---|
| 4 | */
|
|---|
| 5 |
|
|---|
| 6 | "use strict";
|
|---|
| 7 |
|
|---|
| 8 | const JavascriptModulesPlugin = require("./javascript/JavascriptModulesPlugin");
|
|---|
| 9 |
|
|---|
| 10 | /** @typedef {import("../declarations/plugins/SourceMapDevToolPlugin").SourceMapDevToolPluginOptions} SourceMapDevToolPluginOptions */
|
|---|
| 11 | /** @typedef {import("./Compilation")} Compilation */
|
|---|
| 12 |
|
|---|
| 13 | const PLUGIN_NAME = "SourceMapDevToolModuleOptionsPlugin";
|
|---|
| 14 |
|
|---|
| 15 | class SourceMapDevToolModuleOptionsPlugin {
|
|---|
| 16 | /**
|
|---|
| 17 | * Creates an instance of SourceMapDevToolModuleOptionsPlugin.
|
|---|
| 18 | * @param {SourceMapDevToolPluginOptions=} options options
|
|---|
| 19 | */
|
|---|
| 20 | constructor(options = {}) {
|
|---|
| 21 | /** @type {SourceMapDevToolPluginOptions} */
|
|---|
| 22 | this.options = options;
|
|---|
| 23 | }
|
|---|
| 24 |
|
|---|
| 25 | /**
|
|---|
| 26 | * Applies the plugin by registering its hooks on the compiler.
|
|---|
| 27 | * @param {Compilation} compilation the compiler instance
|
|---|
| 28 | * @returns {void}
|
|---|
| 29 | */
|
|---|
| 30 | apply(compilation) {
|
|---|
| 31 | const options = this.options;
|
|---|
| 32 | if (options.module !== false) {
|
|---|
| 33 | compilation.hooks.buildModule.tap(PLUGIN_NAME, (module) => {
|
|---|
| 34 | module.useSourceMap = true;
|
|---|
| 35 | });
|
|---|
| 36 | compilation.hooks.runtimeModule.tap(PLUGIN_NAME, (module) => {
|
|---|
| 37 | module.useSourceMap = true;
|
|---|
| 38 | });
|
|---|
| 39 | } else {
|
|---|
| 40 | compilation.hooks.buildModule.tap(PLUGIN_NAME, (module) => {
|
|---|
| 41 | module.useSimpleSourceMap = true;
|
|---|
| 42 | });
|
|---|
| 43 | compilation.hooks.runtimeModule.tap(PLUGIN_NAME, (module) => {
|
|---|
| 44 | module.useSimpleSourceMap = true;
|
|---|
| 45 | });
|
|---|
| 46 | }
|
|---|
| 47 | JavascriptModulesPlugin.getCompilationHooks(compilation).useSourceMap.tap(
|
|---|
| 48 | PLUGIN_NAME,
|
|---|
| 49 | () => true
|
|---|
| 50 | );
|
|---|
| 51 | }
|
|---|
| 52 | }
|
|---|
| 53 |
|
|---|
| 54 | module.exports = SourceMapDevToolModuleOptionsPlugin;
|
|---|