source: imaps-frontend/node_modules/webpack/lib/dependencies/ImportPlugin.js@ 79a0317

main
Last change on this file since 79a0317 was 79a0317, checked in by stefan toskovski <stefantoska84@…>, 3 days ago

F4 Finalna Verzija

  • Property mode set to 100644
File size: 2.6 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 {
9 JAVASCRIPT_MODULE_TYPE_AUTO,
10 JAVASCRIPT_MODULE_TYPE_DYNAMIC,
11 JAVASCRIPT_MODULE_TYPE_ESM
12} = require("../ModuleTypeConstants");
13const ImportContextDependency = require("./ImportContextDependency");
14const ImportDependency = require("./ImportDependency");
15const ImportEagerDependency = require("./ImportEagerDependency");
16const ImportParserPlugin = require("./ImportParserPlugin");
17const ImportWeakDependency = require("./ImportWeakDependency");
18
19/** @typedef {import("../../declarations/WebpackOptions").JavascriptParserOptions} JavascriptParserOptions */
20/** @typedef {import("../Compiler")} Compiler */
21/** @typedef {import("../javascript/JavascriptParser")} Parser */
22
23const PLUGIN_NAME = "ImportPlugin";
24
25class ImportPlugin {
26 /**
27 * Apply the plugin
28 * @param {Compiler} compiler the compiler instance
29 * @returns {void}
30 */
31 apply(compiler) {
32 compiler.hooks.compilation.tap(
33 PLUGIN_NAME,
34 (compilation, { contextModuleFactory, normalModuleFactory }) => {
35 compilation.dependencyFactories.set(
36 ImportDependency,
37 normalModuleFactory
38 );
39 compilation.dependencyTemplates.set(
40 ImportDependency,
41 new ImportDependency.Template()
42 );
43
44 compilation.dependencyFactories.set(
45 ImportEagerDependency,
46 normalModuleFactory
47 );
48 compilation.dependencyTemplates.set(
49 ImportEagerDependency,
50 new ImportEagerDependency.Template()
51 );
52
53 compilation.dependencyFactories.set(
54 ImportWeakDependency,
55 normalModuleFactory
56 );
57 compilation.dependencyTemplates.set(
58 ImportWeakDependency,
59 new ImportWeakDependency.Template()
60 );
61
62 compilation.dependencyFactories.set(
63 ImportContextDependency,
64 contextModuleFactory
65 );
66 compilation.dependencyTemplates.set(
67 ImportContextDependency,
68 new ImportContextDependency.Template()
69 );
70
71 /**
72 * @param {Parser} parser parser parser
73 * @param {JavascriptParserOptions} parserOptions parserOptions
74 * @returns {void}
75 */
76 const handler = (parser, parserOptions) => {
77 if (parserOptions.import !== undefined && !parserOptions.import)
78 return;
79
80 new ImportParserPlugin(parserOptions).apply(parser);
81 };
82
83 normalModuleFactory.hooks.parser
84 .for(JAVASCRIPT_MODULE_TYPE_AUTO)
85 .tap(PLUGIN_NAME, handler);
86 normalModuleFactory.hooks.parser
87 .for(JAVASCRIPT_MODULE_TYPE_DYNAMIC)
88 .tap(PLUGIN_NAME, handler);
89 normalModuleFactory.hooks.parser
90 .for(JAVASCRIPT_MODULE_TYPE_ESM)
91 .tap(PLUGIN_NAME, handler);
92 }
93 );
94 }
95}
96module.exports = ImportPlugin;
Note: See TracBrowser for help on using the repository browser.