source: imaps-frontend/node_modules/webpack/lib/EntryOptionPlugin.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.9 KB
RevLine 
[79a0317]1/*
2 MIT License http://www.opensource.org/licenses/mit-license.php
3 Author Tobias Koppers @sokra
4*/
5
6"use strict";
7
8/** @typedef {import("../declarations/WebpackOptions").EntryDescriptionNormalized} EntryDescription */
9/** @typedef {import("../declarations/WebpackOptions").EntryNormalized} Entry */
10/** @typedef {import("./Compiler")} Compiler */
11/** @typedef {import("./Entrypoint").EntryOptions} EntryOptions */
12
13class EntryOptionPlugin {
14 /**
15 * @param {Compiler} compiler the compiler instance one is tapping into
16 * @returns {void}
17 */
18 apply(compiler) {
19 compiler.hooks.entryOption.tap("EntryOptionPlugin", (context, entry) => {
20 EntryOptionPlugin.applyEntryOption(compiler, context, entry);
21 return true;
22 });
23 }
24
25 /**
26 * @param {Compiler} compiler the compiler
27 * @param {string} context context directory
28 * @param {Entry} entry request
29 * @returns {void}
30 */
31 static applyEntryOption(compiler, context, entry) {
32 if (typeof entry === "function") {
33 const DynamicEntryPlugin = require("./DynamicEntryPlugin");
34 new DynamicEntryPlugin(context, entry).apply(compiler);
35 } else {
36 const EntryPlugin = require("./EntryPlugin");
37 for (const name of Object.keys(entry)) {
38 const desc = entry[name];
39 const options = EntryOptionPlugin.entryDescriptionToOptions(
40 compiler,
41 name,
42 desc
43 );
44 const descImport =
45 /** @type {Exclude<EntryDescription["import"], undefined>} */
46 (desc.import);
47 for (const entry of descImport) {
48 new EntryPlugin(context, entry, options).apply(compiler);
49 }
50 }
51 }
52 }
53
54 /**
55 * @param {Compiler} compiler the compiler
56 * @param {string} name entry name
57 * @param {EntryDescription} desc entry description
58 * @returns {EntryOptions} options for the entry
59 */
60 static entryDescriptionToOptions(compiler, name, desc) {
61 /** @type {EntryOptions} */
62 const options = {
63 name,
64 filename: desc.filename,
65 runtime: desc.runtime,
66 layer: desc.layer,
67 dependOn: desc.dependOn,
68 baseUri: desc.baseUri,
69 publicPath: desc.publicPath,
70 chunkLoading: desc.chunkLoading,
71 asyncChunks: desc.asyncChunks,
72 wasmLoading: desc.wasmLoading,
73 library: desc.library
74 };
75 if (desc.layer !== undefined && !compiler.options.experiments.layers) {
76 throw new Error(
77 "'entryOptions.layer' is only allowed when 'experiments.layers' is enabled"
78 );
79 }
80 if (desc.chunkLoading) {
81 const EnableChunkLoadingPlugin = require("./javascript/EnableChunkLoadingPlugin");
82 EnableChunkLoadingPlugin.checkEnabled(compiler, desc.chunkLoading);
83 }
84 if (desc.wasmLoading) {
85 const EnableWasmLoadingPlugin = require("./wasm/EnableWasmLoadingPlugin");
86 EnableWasmLoadingPlugin.checkEnabled(compiler, desc.wasmLoading);
87 }
88 if (desc.library) {
89 const EnableLibraryPlugin = require("./library/EnableLibraryPlugin");
90 EnableLibraryPlugin.checkEnabled(compiler, desc.library.type);
91 }
92 return options;
93 }
94}
95
96module.exports = EntryOptionPlugin;
Note: See TracBrowser for help on using the repository browser.