source: frontend/node_modules/webpack/lib/dependencies/ImportMetaContextPlugin.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: 2.1 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");
12const ContextElementDependency = require("./ContextElementDependency");
13const ImportMetaContextDependency = require("./ImportMetaContextDependency");
14const ImportMetaContextDependencyParserPlugin = require("./ImportMetaContextDependencyParserPlugin");
15
16/** @typedef {import("../../declarations/WebpackOptions").JavascriptParserOptions} JavascriptParserOptions */
17/** @typedef {import("../Compiler")} Compiler */
18/** @typedef {import("../javascript/JavascriptParser")} Parser */
19
20const PLUGIN_NAME = "ImportMetaContextPlugin";
21
22class ImportMetaContextPlugin {
23 /**
24 * Applies the plugin by registering its hooks on the compiler.
25 * @param {Compiler} compiler the compiler instance
26 * @returns {void}
27 */
28 apply(compiler) {
29 compiler.hooks.compilation.tap(
30 PLUGIN_NAME,
31 (compilation, { contextModuleFactory, normalModuleFactory }) => {
32 compilation.dependencyFactories.set(
33 ImportMetaContextDependency,
34 contextModuleFactory
35 );
36 compilation.dependencyTemplates.set(
37 ImportMetaContextDependency,
38 new ImportMetaContextDependency.Template()
39 );
40 compilation.dependencyFactories.set(
41 ContextElementDependency,
42 normalModuleFactory
43 );
44
45 /**
46 * Handles the hook callback for this code path.
47 * @param {Parser} parser parser parser
48 * @param {JavascriptParserOptions} parserOptions parserOptions
49 * @returns {void}
50 */
51 const handler = (parser, parserOptions) => {
52 if (
53 parserOptions.importMetaContext !== undefined &&
54 !parserOptions.importMetaContext
55 ) {
56 return;
57 }
58
59 new ImportMetaContextDependencyParserPlugin().apply(parser);
60 };
61
62 normalModuleFactory.hooks.parser
63 .for(JAVASCRIPT_MODULE_TYPE_AUTO)
64 .tap(PLUGIN_NAME, handler);
65 normalModuleFactory.hooks.parser
66 .for(JAVASCRIPT_MODULE_TYPE_ESM)
67 .tap(PLUGIN_NAME, handler);
68 }
69 );
70 }
71}
72
73module.exports = ImportMetaContextPlugin;
Note: See TracBrowser for help on using the repository browser.