source: imaps-frontend/node_modules/webpack/lib/dependencies/ImportMetaContextPlugin.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.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("../../declarations/WebpackOptions").ResolveOptions} ResolveOptions */
18/** @typedef {import("../Compiler")} Compiler */
19/** @typedef {import("../javascript/JavascriptParser")} Parser */
20
21const PLUGIN_NAME = "ImportMetaContextPlugin";
22
23class ImportMetaContextPlugin {
24 /**
25 * Apply the plugin
26 * @param {Compiler} compiler the compiler instance
27 * @returns {void}
28 */
29 apply(compiler) {
30 compiler.hooks.compilation.tap(
31 PLUGIN_NAME,
32 (compilation, { contextModuleFactory, normalModuleFactory }) => {
33 compilation.dependencyFactories.set(
34 ImportMetaContextDependency,
35 contextModuleFactory
36 );
37 compilation.dependencyTemplates.set(
38 ImportMetaContextDependency,
39 new ImportMetaContextDependency.Template()
40 );
41 compilation.dependencyFactories.set(
42 ContextElementDependency,
43 normalModuleFactory
44 );
45
46 /**
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 new ImportMetaContextDependencyParserPlugin().apply(parser);
59 };
60
61 normalModuleFactory.hooks.parser
62 .for(JAVASCRIPT_MODULE_TYPE_AUTO)
63 .tap(PLUGIN_NAME, handler);
64 normalModuleFactory.hooks.parser
65 .for(JAVASCRIPT_MODULE_TYPE_ESM)
66 .tap(PLUGIN_NAME, handler);
67 }
68 );
69 }
70}
71
72module.exports = ImportMetaContextPlugin;
Note: See TracBrowser for help on using the repository browser.