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

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

Fix frontend appearance

  • Property mode set to 100644
File size: 2.3 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} = require("../ModuleTypeConstants");
12const RuntimeGlobals = require("../RuntimeGlobals");
13const {
14 toConstantDependency
15} = require("../javascript/JavascriptParserHelpers");
16const ConstDependency = require("./ConstDependency");
17
18/** @typedef {import("../../declarations/WebpackOptions").JavascriptParserOptions} JavascriptParserOptions */
19/** @typedef {import("../Compiler")} Compiler */
20/** @typedef {import("../javascript/JavascriptParser")} JavascriptParser */
21
22const PLUGIN_NAME = "RequireJsStuffPlugin";
23
24module.exports = class RequireJsStuffPlugin {
25 /**
26 * Applies the plugin by registering its hooks on the compiler.
27 * @param {Compiler} compiler the compiler instance
28 * @returns {void}
29 */
30 apply(compiler) {
31 compiler.hooks.compilation.tap(
32 PLUGIN_NAME,
33 (compilation, { normalModuleFactory }) => {
34 compilation.dependencyTemplates.set(
35 ConstDependency,
36 new ConstDependency.Template()
37 );
38 /**
39 * Handles the hook callback for this code path.
40 * @param {JavascriptParser} parser the parser
41 * @param {JavascriptParserOptions} parserOptions options
42 * @returns {void}
43 */
44 const handler = (parser, parserOptions) => {
45 if (
46 parserOptions.requireJs === undefined ||
47 !parserOptions.requireJs
48 ) {
49 return;
50 }
51
52 parser.hooks.call
53 .for("require.config")
54 .tap(PLUGIN_NAME, toConstantDependency(parser, "undefined"));
55 parser.hooks.call
56 .for("requirejs.config")
57 .tap(PLUGIN_NAME, toConstantDependency(parser, "undefined"));
58
59 parser.hooks.expression
60 .for("require.version")
61 .tap(
62 PLUGIN_NAME,
63 toConstantDependency(parser, JSON.stringify("0.0.0"))
64 );
65 parser.hooks.expression
66 .for("requirejs.onError")
67 .tap(
68 PLUGIN_NAME,
69 toConstantDependency(
70 parser,
71 RuntimeGlobals.uncaughtErrorHandler,
72 [RuntimeGlobals.uncaughtErrorHandler]
73 )
74 );
75 };
76 normalModuleFactory.hooks.parser
77 .for(JAVASCRIPT_MODULE_TYPE_AUTO)
78 .tap(PLUGIN_NAME, handler);
79 normalModuleFactory.hooks.parser
80 .for(JAVASCRIPT_MODULE_TYPE_DYNAMIC)
81 .tap(PLUGIN_NAME, handler);
82 }
83 );
84 }
85};
Note: See TracBrowser for help on using the repository browser.