source: trip-planner-front/node_modules/webpack/lib/dependencies/ImportPlugin.js@ 1ad8e64

Last change on this file since 1ad8e64 was 6a3a178, checked in by Ema <ema_spirova@…>, 3 years ago

initial commit

  • Property mode set to 100644
File size: 2.1 KB
Line 
1/*
2 MIT License http://www.opensource.org/licenses/mit-license.php
3 Author Tobias Koppers @sokra
4*/
5
6"use strict";
7
8const ImportContextDependency = require("./ImportContextDependency");
9const ImportDependency = require("./ImportDependency");
10const ImportEagerDependency = require("./ImportEagerDependency");
11const ImportParserPlugin = require("./ImportParserPlugin");
12const ImportWeakDependency = require("./ImportWeakDependency");
13
14/** @typedef {import("../Compiler")} Compiler */
15
16class ImportPlugin {
17 /**
18 * Apply the plugin
19 * @param {Compiler} compiler the compiler instance
20 * @returns {void}
21 */
22 apply(compiler) {
23 compiler.hooks.compilation.tap(
24 "ImportPlugin",
25 (compilation, { contextModuleFactory, normalModuleFactory }) => {
26 compilation.dependencyFactories.set(
27 ImportDependency,
28 normalModuleFactory
29 );
30 compilation.dependencyTemplates.set(
31 ImportDependency,
32 new ImportDependency.Template()
33 );
34
35 compilation.dependencyFactories.set(
36 ImportEagerDependency,
37 normalModuleFactory
38 );
39 compilation.dependencyTemplates.set(
40 ImportEagerDependency,
41 new ImportEagerDependency.Template()
42 );
43
44 compilation.dependencyFactories.set(
45 ImportWeakDependency,
46 normalModuleFactory
47 );
48 compilation.dependencyTemplates.set(
49 ImportWeakDependency,
50 new ImportWeakDependency.Template()
51 );
52
53 compilation.dependencyFactories.set(
54 ImportContextDependency,
55 contextModuleFactory
56 );
57 compilation.dependencyTemplates.set(
58 ImportContextDependency,
59 new ImportContextDependency.Template()
60 );
61
62 const handler = (parser, parserOptions) => {
63 if (parserOptions.import !== undefined && !parserOptions.import)
64 return;
65
66 new ImportParserPlugin(parserOptions).apply(parser);
67 };
68
69 normalModuleFactory.hooks.parser
70 .for("javascript/auto")
71 .tap("ImportPlugin", handler);
72 normalModuleFactory.hooks.parser
73 .for("javascript/dynamic")
74 .tap("ImportPlugin", handler);
75 normalModuleFactory.hooks.parser
76 .for("javascript/esm")
77 .tap("ImportPlugin", handler);
78 }
79 );
80 }
81}
82module.exports = ImportPlugin;
Note: See TracBrowser for help on using the repository browser.