2 MIT License http://www.opensource.org/licenses/mit-license.php
3 Author Tobias Koppers @sokra
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 */
13 class EntryOptionPlugin {
15 * @param {Compiler} compiler the compiler instance one is tapping into
19 compiler.hooks.entryOption.tap("EntryOptionPlugin", (context, entry) => {
20 EntryOptionPlugin.applyEntryOption(compiler, context, entry);
26 * @param {Compiler} compiler the compiler
27 * @param {string} context context directory
28 * @param {Entry} entry request
31 static applyEntryOption(compiler, context, entry) {
32 if (typeof entry === "function") {
33 const DynamicEntryPlugin = require("./DynamicEntryPlugin");
34 new DynamicEntryPlugin(context, entry).apply(compiler);
36 const EntryPlugin = require("./EntryPlugin");
37 for (const name of Object.keys(entry)) {
38 const desc = entry[name];
39 const options = EntryOptionPlugin.entryDescriptionToOptions(
44 for (const entry of desc.import) {
45 new EntryPlugin(context, entry, options).apply(compiler);
52 * @param {Compiler} compiler the compiler
53 * @param {string} name entry name
54 * @param {EntryDescription} desc entry description
55 * @returns {EntryOptions} options for the entry
57 static entryDescriptionToOptions(compiler, name, desc) {
58 /** @type {EntryOptions} */
61 filename: desc.filename,
62 runtime: desc.runtime,
64 dependOn: desc.dependOn,
65 baseUri: desc.baseUri,
66 publicPath: desc.publicPath,
67 chunkLoading: desc.chunkLoading,
68 asyncChunks: desc.asyncChunks,
69 wasmLoading: desc.wasmLoading,
72 if (desc.layer !== undefined && !compiler.options.experiments.layers) {
74 "'entryOptions.layer' is only allowed when 'experiments.layers' is enabled"
77 if (desc.chunkLoading) {
78 const EnableChunkLoadingPlugin = require("./javascript/EnableChunkLoadingPlugin");
79 EnableChunkLoadingPlugin.checkEnabled(compiler, desc.chunkLoading);
81 if (desc.wasmLoading) {
82 const EnableWasmLoadingPlugin = require("./wasm/EnableWasmLoadingPlugin");
83 EnableWasmLoadingPlugin.checkEnabled(compiler, desc.wasmLoading);
86 const EnableLibraryPlugin = require("./library/EnableLibraryPlugin");
87 EnableLibraryPlugin.checkEnabled(compiler, desc.library.type);
93 module.exports = EntryOptionPlugin;