source: trip-planner-front/node_modules/webpack/lib/dependencies/RequireEnsurePlugin.js@ 571e0df

Last change on this file since 571e0df was 6a3a178, checked in by Ema <ema_spirova@…>, 3 years ago

initial commit

  • Property mode set to 100644
File size: 1.8 KB
RevLine 
[6a3a178]1/*
2 MIT License http://www.opensource.org/licenses/mit-license.php
3 Author Tobias Koppers @sokra
4*/
5
6"use strict";
7
8const RequireEnsureDependency = require("./RequireEnsureDependency");
9const RequireEnsureItemDependency = require("./RequireEnsureItemDependency");
10
11const RequireEnsureDependenciesBlockParserPlugin = require("./RequireEnsureDependenciesBlockParserPlugin");
12
13const {
14 evaluateToString,
15 toConstantDependency
16} = require("../javascript/JavascriptParserHelpers");
17
18class RequireEnsurePlugin {
19 apply(compiler) {
20 compiler.hooks.compilation.tap(
21 "RequireEnsurePlugin",
22 (compilation, { normalModuleFactory }) => {
23 compilation.dependencyFactories.set(
24 RequireEnsureItemDependency,
25 normalModuleFactory
26 );
27 compilation.dependencyTemplates.set(
28 RequireEnsureItemDependency,
29 new RequireEnsureItemDependency.Template()
30 );
31
32 compilation.dependencyTemplates.set(
33 RequireEnsureDependency,
34 new RequireEnsureDependency.Template()
35 );
36
37 const handler = (parser, parserOptions) => {
38 if (
39 parserOptions.requireEnsure !== undefined &&
40 !parserOptions.requireEnsure
41 )
42 return;
43
44 new RequireEnsureDependenciesBlockParserPlugin().apply(parser);
45 parser.hooks.evaluateTypeof
46 .for("require.ensure")
47 .tap("RequireEnsurePlugin", evaluateToString("function"));
48 parser.hooks.typeof
49 .for("require.ensure")
50 .tap(
51 "RequireEnsurePlugin",
52 toConstantDependency(parser, JSON.stringify("function"))
53 );
54 };
55
56 normalModuleFactory.hooks.parser
57 .for("javascript/auto")
58 .tap("RequireEnsurePlugin", handler);
59 normalModuleFactory.hooks.parser
60 .for("javascript/dynamic")
61 .tap("RequireEnsurePlugin", handler);
62 }
63 );
64 }
65}
66module.exports = RequireEnsurePlugin;
Note: See TracBrowser for help on using the repository browser.