source: frontend/node_modules/webpack/lib/dependencies/URLPlugin.js

Last change on this file was 9af201e, checked in by MBK <marija.karapandzova@…>, 11 days ago

Fix frontend appearance

  • Property mode set to 100644
File size: 1.9 KB
Line 
1/*
2 MIT License http://www.opensource.org/licenses/mit-license.php
3 Author Ivan Kopeykin @vankop
4*/
5
6"use strict";
7
8const {
9 JAVASCRIPT_MODULE_TYPE_AUTO,
10 JAVASCRIPT_MODULE_TYPE_ESM
11} = require("../ModuleTypeConstants");
12
13const URLContextDependency = require("../dependencies/URLContextDependency");
14const URLDependency = require("../dependencies/URLDependency");
15const URLParserPlugin = require("../url/URLParserPlugin");
16
17/** @typedef {import("../../declarations/WebpackOptions").JavascriptParserOptions} JavascriptParserOptions */
18/** @typedef {import("../Compiler")} Compiler */
19/** @typedef {import("../javascript/JavascriptParser")} JavascriptParser */
20
21const PLUGIN_NAME = "URLPlugin";
22
23class URLPlugin {
24 /**
25 * Applies the plugin by registering its hooks on the compiler.
26 * @param {Compiler} compiler compiler
27 */
28 apply(compiler) {
29 compiler.hooks.compilation.tap(
30 PLUGIN_NAME,
31 (compilation, { normalModuleFactory, contextModuleFactory }) => {
32 compilation.dependencyFactories.set(URLDependency, normalModuleFactory);
33 compilation.dependencyTemplates.set(
34 URLDependency,
35 new URLDependency.Template()
36 );
37 compilation.dependencyFactories.set(
38 URLContextDependency,
39 contextModuleFactory
40 );
41 compilation.dependencyTemplates.set(
42 URLContextDependency,
43 new URLContextDependency.Template()
44 );
45
46 /**
47 * Handles the hook callback for this code path.
48 * @param {JavascriptParser} parser parser parser
49 * @param {JavascriptParserOptions} parserOptions parserOptions
50 * @returns {void}
51 */
52 const handler = (parser, parserOptions) => {
53 if (parserOptions.url === false) return;
54 new URLParserPlugin(parserOptions).apply(parser);
55 };
56
57 normalModuleFactory.hooks.parser
58 .for(JAVASCRIPT_MODULE_TYPE_AUTO)
59 .tap(PLUGIN_NAME, handler);
60
61 normalModuleFactory.hooks.parser
62 .for(JAVASCRIPT_MODULE_TYPE_ESM)
63 .tap(PLUGIN_NAME, handler);
64 }
65 );
66 }
67}
68
69module.exports = URLPlugin;
Note: See TracBrowser for help on using the repository browser.