webpack 5.101.2 → 5.102.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +21 -26
- package/lib/APIPlugin.js +30 -36
- package/lib/AsyncDependenciesBlock.js +1 -4
- package/lib/BannerPlugin.js +0 -1
- package/lib/Cache.js +7 -6
- package/lib/CacheFacade.js +0 -1
- package/lib/Chunk.js +49 -31
- package/lib/ChunkGraph.js +35 -25
- package/lib/ChunkGroup.js +8 -10
- package/lib/ChunkTemplate.js +1 -1
- package/lib/CleanPlugin.js +3 -3
- package/lib/CodeGenerationResults.js +2 -1
- package/lib/CompatibilityPlugin.js +29 -12
- package/lib/Compilation.js +204 -185
- package/lib/Compiler.js +36 -35
- package/lib/ConcatenationScope.js +6 -1
- package/lib/ConditionalInitFragment.js +1 -1
- package/lib/ConstPlugin.js +18 -10
- package/lib/ContextExclusionPlugin.js +0 -1
- package/lib/ContextModule.js +22 -20
- package/lib/ContextModuleFactory.js +30 -11
- package/lib/ContextReplacementPlugin.js +38 -15
- package/lib/DefinePlugin.js +18 -8
- package/lib/DelegatedModule.js +7 -11
- package/lib/DependenciesBlock.js +0 -2
- package/lib/Dependency.js +9 -11
- package/lib/DependencyTemplates.js +1 -3
- package/lib/DllModule.js +1 -7
- package/lib/DllReferencePlugin.js +2 -4
- package/lib/DynamicEntryPlugin.js +0 -2
- package/lib/EntryOptionPlugin.js +0 -5
- package/lib/EnvironmentNotSupportAsyncWarning.js +0 -3
- package/lib/EvalDevToolModulePlugin.js +4 -3
- package/lib/EvalSourceMapDevToolPlugin.js +3 -4
- package/lib/ExportsInfo.js +50 -49
- package/lib/ExternalModule.js +84 -52
- package/lib/ExternalModuleFactoryPlugin.js +27 -7
- package/lib/ExternalsPlugin.js +24 -17
- package/lib/FileSystemInfo.js +96 -78
- package/lib/FlagDependencyUsagePlugin.js +3 -4
- package/lib/Generator.js +2 -13
- package/lib/GraphHelpers.js +0 -3
- package/lib/HookWebpackError.js +0 -2
- package/lib/HotModuleReplacementPlugin.js +22 -24
- package/lib/HotUpdateChunk.js +0 -3
- package/lib/IgnorePlugin.js +5 -2
- package/lib/InitFragment.js +41 -29
- package/lib/InvalidDependenciesModuleWarning.js +0 -1
- package/lib/LibManifestPlugin.js +4 -6
- package/lib/LoaderOptionsPlugin.js +1 -10
- package/lib/MainTemplate.js +8 -19
- package/lib/Module.js +32 -20
- package/lib/ModuleFactory.js +1 -1
- package/lib/ModuleFilenameHelpers.js +41 -24
- package/lib/ModuleGraph.js +30 -16
- package/lib/ModuleInfoHeaderPlugin.js +0 -1
- package/lib/ModuleTemplate.js +0 -2
- package/lib/ModuleTypeConstants.js +11 -1
- package/lib/MultiCompiler.js +23 -15
- package/lib/MultiWatching.js +6 -10
- package/lib/NodeStuffPlugin.js +2 -10
- package/lib/NormalModule.js +145 -88
- package/lib/NormalModuleFactory.js +59 -40
- package/lib/OptionsApply.js +1 -1
- package/lib/Parser.js +1 -1
- package/lib/ProgressPlugin.js +6 -10
- package/lib/ProvidePlugin.js +5 -7
- package/lib/RawModule.js +1 -6
- package/lib/RecordIdsPlugin.js +10 -6
- package/lib/ResolverFactory.js +0 -2
- package/lib/RuntimeGlobals.js +5 -0
- package/lib/RuntimeModule.js +1 -3
- package/lib/RuntimePlugin.js +26 -22
- package/lib/RuntimeTemplate.js +12 -11
- package/lib/SourceMapDevToolModuleOptionsPlugin.js +2 -2
- package/lib/SourceMapDevToolPlugin.js +6 -11
- package/lib/Stats.js +0 -1
- package/lib/Template.js +6 -11
- package/lib/TemplatedPathPlugin.js +2 -1
- package/lib/WatchIgnorePlugin.js +2 -3
- package/lib/Watching.js +15 -15
- package/lib/WebpackIsIncludedPlugin.js +0 -2
- package/lib/WebpackOptionsApply.js +74 -107
- package/lib/asset/AssetBytesGenerator.js +166 -0
- package/lib/asset/AssetBytesParser.js +37 -0
- package/lib/asset/AssetGenerator.js +20 -34
- package/lib/asset/AssetModulesPlugin.js +34 -16
- package/lib/asset/AssetParser.js +7 -3
- package/lib/asset/AssetSourceGenerator.js +1 -1
- package/lib/asset/RawDataUrlModule.js +3 -2
- package/lib/async-modules/AsyncModuleHelpers.js +6 -4
- package/lib/async-modules/AwaitDependenciesInitFragment.js +4 -1
- package/lib/buildChunkGraph.js +0 -1
- package/lib/cache/MemoryCachePlugin.js +0 -2
- package/lib/cache/MemoryWithGcCachePlugin.js +0 -2
- package/lib/cache/PackFileCacheStrategy.js +14 -1
- package/lib/cache/ResolverCachePlugin.js +9 -15
- package/lib/config/defaults.js +155 -21
- package/lib/config/normalization.js +18 -3
- package/lib/container/ContainerEntryDependency.js +0 -1
- package/lib/container/ContainerEntryModule.js +3 -7
- package/lib/container/ContainerPlugin.js +1 -2
- package/lib/container/ContainerReferencePlugin.js +0 -1
- package/lib/container/FallbackDependency.js +2 -1
- package/lib/container/FallbackModule.js +6 -7
- package/lib/container/ModuleFederationPlugin.js +0 -1
- package/lib/container/RemoteModule.js +8 -8
- package/lib/container/RemoteRuntimeModule.js +2 -2
- package/lib/css/CssGenerator.js +3 -6
- package/lib/css/CssLoadingRuntimeModule.js +6 -9
- package/lib/css/CssModulesPlugin.js +11 -13
- package/lib/css/CssParser.js +3 -3
- package/lib/css/walkCssTokens.js +1 -1
- package/lib/debug/ProfilingPlugin.js +35 -8
- package/lib/dependencies/AMDDefineDependencyParserPlugin.js +12 -17
- package/lib/dependencies/AMDPlugin.js +2 -2
- package/lib/dependencies/AMDRequireDependenciesBlockParserPlugin.js +1 -2
- package/lib/dependencies/CachedConstDependency.js +0 -4
- package/lib/dependencies/CommonJsExportRequireDependency.js +20 -14
- package/lib/dependencies/CommonJsExportsDependency.js +2 -1
- package/lib/dependencies/CommonJsExportsParserPlugin.js +20 -5
- package/lib/dependencies/CommonJsFullRequireDependency.js +6 -4
- package/lib/dependencies/CommonJsImportsParserPlugin.js +16 -7
- package/lib/dependencies/CommonJsRequireContextDependency.js +1 -1
- package/lib/dependencies/CommonJsSelfReferenceDependency.js +4 -4
- package/lib/dependencies/ConstDependency.js +2 -2
- package/lib/dependencies/ContextDependency.js +9 -4
- package/lib/dependencies/ContextDependencyHelpers.js +2 -2
- package/lib/dependencies/ContextDependencyTemplateAsId.js +9 -9
- package/lib/dependencies/ContextDependencyTemplateAsRequireCall.js +9 -9
- package/lib/dependencies/ContextElementDependency.js +22 -11
- package/lib/dependencies/CssIcssImportDependency.js +0 -2
- package/lib/dependencies/CssIcssSymbolDependency.js +2 -2
- package/lib/dependencies/CssImportDependency.js +0 -8
- package/lib/dependencies/CssLocalIdentifierDependency.js +3 -4
- package/lib/dependencies/CssSelfLocalIdentifierDependency.js +2 -2
- package/lib/dependencies/CssUrlDependency.js +0 -6
- package/lib/dependencies/ExportsInfoDependency.js +7 -9
- package/lib/dependencies/ExternalModuleDependency.js +0 -3
- package/lib/dependencies/ExternalModuleInitFragment.js +1 -1
- package/lib/dependencies/HarmonyAcceptDependency.js +1 -1
- package/lib/dependencies/HarmonyAcceptImportDependency.js +0 -4
- package/lib/dependencies/HarmonyCompatibilityDependency.js +0 -1
- package/lib/dependencies/HarmonyDetectionParserPlugin.js +0 -14
- package/lib/dependencies/HarmonyEvaluatedImportSpecifierDependency.js +3 -3
- package/lib/dependencies/HarmonyExportDependencyParserPlugin.js +4 -1
- package/lib/dependencies/HarmonyExportImportedSpecifierDependency.js +29 -35
- package/lib/dependencies/HarmonyImportDependency.js +30 -14
- package/lib/dependencies/HarmonyImportDependencyParserPlugin.js +38 -24
- package/lib/dependencies/HarmonyImportSideEffectDependency.js +0 -4
- package/lib/dependencies/HarmonyImportSpecifierDependency.js +46 -31
- package/lib/dependencies/HarmonyModulesPlugin.js +3 -3
- package/lib/dependencies/ImportDependency.js +18 -6
- package/lib/dependencies/ImportEagerDependency.js +2 -3
- package/lib/dependencies/ImportMetaContextDependencyParserPlugin.js +8 -5
- package/lib/dependencies/ImportMetaContextPlugin.js +0 -1
- package/lib/dependencies/ImportMetaPlugin.js +8 -1
- package/lib/dependencies/ImportParserPlugin.js +294 -45
- package/lib/dependencies/ImportWeakDependency.js +2 -3
- package/lib/dependencies/JsonExportsDependency.js +0 -1
- package/lib/dependencies/LoaderDependency.js +0 -3
- package/lib/dependencies/LoaderImportDependency.js +0 -3
- package/lib/dependencies/LoaderPlugin.js +11 -5
- package/lib/dependencies/ModuleDecoratorDependency.js +2 -4
- package/lib/dependencies/ModuleDependency.js +3 -9
- package/lib/dependencies/NullDependency.js +2 -0
- package/lib/dependencies/ProvidedDependency.js +6 -8
- package/lib/dependencies/PureExpressionDependency.js +0 -1
- package/lib/dependencies/RequireEnsureDependenciesBlock.js +0 -1
- package/lib/dependencies/RequireEnsureDependenciesBlockParserPlugin.js +1 -2
- package/lib/dependencies/RequireIncludeDependency.js +2 -2
- package/lib/dependencies/RequireResolveDependency.js +2 -2
- package/lib/dependencies/RuntimeRequirementsDependency.js +2 -3
- package/lib/dependencies/StaticExportsDependency.js +3 -5
- package/lib/dependencies/URLDependency.js +2 -7
- package/lib/dependencies/URLPlugin.js +1 -2
- package/lib/dependencies/WebAssemblyExportImportedDependency.js +2 -2
- package/lib/dependencies/WebAssemblyImportDependency.js +2 -2
- package/lib/dependencies/WebpackIsIncludedDependency.js +2 -3
- package/lib/dependencies/WorkerDependency.js +2 -3
- package/lib/dependencies/WorkerPlugin.js +3 -9
- package/lib/dependencies/processExportInfo.js +2 -3
- package/lib/esm/ModuleChunkFormatPlugin.js +0 -3
- package/lib/esm/ModuleChunkLoadingPlugin.js +2 -1
- package/lib/esm/ModuleChunkLoadingRuntimeModule.js +7 -7
- package/lib/hmr/LazyCompilationPlugin.js +6 -4
- package/lib/hmr/lazyCompilationBackend.js +13 -10
- package/lib/ids/DeterministicChunkIdsPlugin.js +0 -1
- package/lib/ids/NamedChunkIdsPlugin.js +1 -6
- package/lib/ids/NamedModuleIdsPlugin.js +1 -5
- package/lib/ids/NaturalChunkIdsPlugin.js +0 -1
- package/lib/ids/NaturalModuleIdsPlugin.js +0 -1
- package/lib/ids/OccurrenceChunkIdsPlugin.js +0 -1
- package/lib/ids/OccurrenceModuleIdsPlugin.js +0 -1
- package/lib/ids/SyncModuleIdsPlugin.js +4 -3
- package/lib/index.js +8 -7
- package/lib/javascript/ArrayPushCallbackChunkFormatPlugin.js +4 -1
- package/lib/javascript/BasicEvaluatedExpression.js +13 -6
- package/lib/javascript/ChunkFormatHelpers.js +1 -1
- package/lib/javascript/CommonJsChunkFormatPlugin.js +0 -1
- package/lib/javascript/JavascriptGenerator.js +2 -3
- package/lib/javascript/JavascriptModulesPlugin.js +44 -21
- package/lib/javascript/JavascriptParser.js +159 -93
- package/lib/javascript/JavascriptParserHelpers.js +2 -2
- package/lib/javascript/StartupHelpers.js +2 -4
- package/lib/json/JsonData.js +1 -1
- package/lib/json/JsonGenerator.js +4 -5
- package/lib/json/JsonModulesPlugin.js +0 -3
- package/lib/json/JsonParser.js +4 -2
- package/lib/library/AbstractLibraryPlugin.js +2 -2
- package/lib/library/AmdLibraryPlugin.js +0 -1
- package/lib/library/AssignLibraryPlugin.js +23 -12
- package/lib/library/EnableLibraryPlugin.js +7 -11
- package/lib/library/ExportPropertyLibraryPlugin.js +8 -20
- package/lib/library/JsonpLibraryPlugin.js +5 -2
- package/lib/library/ModuleLibraryPlugin.js +88 -43
- package/lib/library/SystemLibraryPlugin.js +0 -1
- package/lib/library/UmdLibraryPlugin.js +12 -18
- package/lib/logging/Logger.js +12 -10
- package/lib/logging/createConsoleLogger.js +15 -14
- package/lib/logging/truncateArgs.js +1 -1
- package/lib/node/CommonJsChunkLoadingPlugin.js +2 -1
- package/lib/node/NodeWatchFileSystem.js +4 -4
- package/lib/node/ReadFileChunkLoadingRuntimeModule.js +2 -2
- package/lib/node/RequireChunkLoadingRuntimeModule.js +5 -2
- package/lib/node/nodeConsole.js +2 -2
- package/lib/optimize/AggressiveSplittingPlugin.js +2 -0
- package/lib/optimize/ConcatenatedModule.js +142 -100
- package/lib/optimize/InnerGraph.js +17 -11
- package/lib/optimize/InnerGraphPlugin.js +0 -3
- package/lib/optimize/ModuleConcatenationPlugin.js +3 -4
- package/lib/optimize/RuntimeChunkPlugin.js +0 -1
- package/lib/optimize/SideEffectsFlagPlugin.js +3 -10
- package/lib/optimize/SplitChunksPlugin.js +46 -40
- package/lib/performance/SizeLimitsPlugin.js +2 -1
- package/lib/prefetch/ChunkPrefetchFunctionRuntimeModule.js +5 -7
- package/lib/prefetch/ChunkPrefetchPreloadPlugin.js +0 -2
- package/lib/prefetch/ChunkPrefetchStartupRuntimeModule.js +0 -1
- package/lib/prefetch/ChunkPrefetchTriggerRuntimeModule.js +2 -2
- package/lib/prefetch/ChunkPreloadTriggerRuntimeModule.js +2 -2
- package/lib/rules/BasicMatcherRulePlugin.js +0 -2
- package/lib/rules/ObjectMatcherRulePlugin.js +0 -1
- package/lib/rules/RuleSetCompiler.js +8 -6
- package/lib/runtime/BaseUriRuntimeModule.js +2 -2
- package/lib/runtime/CompatRuntimeModule.js +0 -1
- package/lib/runtime/GetChunkFilenameRuntimeModule.js +8 -9
- package/lib/runtime/LoadScriptRuntimeModule.js +0 -2
- package/lib/runtime/MakeDeferredNamespaceObjectRuntime.js +1 -1
- package/lib/runtime/PublicPathRuntimeModule.js +2 -2
- package/lib/runtime/StartupEntrypointRuntimeModule.js +0 -1
- package/lib/runtime/SystemContextRuntimeModule.js +0 -2
- package/lib/runtime/ToBinaryRuntimeModule.js +64 -0
- package/lib/schemes/DataUriPlugin.js +2 -28
- package/lib/schemes/FileUriPlugin.js +5 -2
- package/lib/schemes/HttpUriPlugin.js +4 -2
- package/lib/schemes/VirtualUrlPlugin.js +11 -11
- package/lib/serialization/NullPrototypeObjectSerializer.js +5 -3
- package/lib/serialization/ObjectMiddleware.js +30 -19
- package/lib/serialization/SerializerMiddleware.js +1 -3
- package/lib/serialization/types.js +1 -1
- package/lib/sharing/ConsumeSharedModule.js +3 -5
- package/lib/sharing/ConsumeSharedPlugin.js +2 -4
- package/lib/sharing/ConsumeSharedRuntimeModule.js +9 -6
- package/lib/sharing/ProvideSharedModule.js +3 -7
- package/lib/sharing/SharePlugin.js +0 -2
- package/lib/sharing/ShareRuntimeModule.js +4 -1
- package/lib/sharing/resolveMatchedConfigs.js +14 -6
- package/lib/sharing/utils.js +0 -6
- package/lib/stats/DefaultStatsFactoryPlugin.js +178 -94
- package/lib/stats/DefaultStatsPresetPlugin.js +15 -9
- package/lib/stats/DefaultStatsPrinterPlugin.js +77 -113
- package/lib/stats/StatsFactory.js +14 -11
- package/lib/url/URLParserPlugin.js +2 -4
- package/lib/util/ArrayHelpers.js +4 -4
- package/lib/util/AsyncQueue.js +1 -0
- package/lib/util/LazySet.js +2 -2
- package/lib/util/StackedCacheMap.js +0 -2
- package/lib/util/TupleSet.js +9 -4
- package/lib/util/URLAbsoluteSpecifier.js +0 -1
- package/lib/util/WeakTupleMap.js +1 -1
- package/lib/util/chainedImports.js +3 -1
- package/lib/util/cleverMerge.js +15 -18
- package/lib/util/comparators.js +2 -4
- package/lib/util/compileBooleanMatcher.js +11 -9
- package/lib/util/concatenate.js +1 -2
- package/lib/util/create-schema-validation.js +0 -1
- package/lib/util/dataURL.js +39 -0
- package/lib/util/deprecation.js +29 -31
- package/lib/util/deterministicGrouping.js +34 -30
- package/lib/util/extractSourceMap.js +319 -0
- package/lib/util/findGraphRoots.js +15 -5
- package/lib/util/fs.js +29 -8
- package/lib/util/semver.js +9 -8
- package/lib/util/smartGrouping.js +41 -26
- package/lib/util/traverseDestructuringAssignmentProperties.js +45 -0
- package/lib/wasm/EnableWasmLoadingPlugin.js +3 -2
- package/lib/wasm-async/AsyncWasmLoadingRuntimeModule.js +5 -1
- package/lib/wasm-async/AsyncWebAssemblyJavascriptGenerator.js +2 -13
- package/lib/wasm-async/AsyncWebAssemblyModulesPlugin.js +2 -9
- package/lib/wasm-async/AsyncWebAssemblyParser.js +2 -1
- package/lib/wasm-sync/WasmChunkLoadingRuntimeModule.js +6 -4
- package/lib/wasm-sync/WebAssemblyGenerator.js +1 -3
- package/lib/wasm-sync/WebAssemblyJavascriptGenerator.js +1 -4
- package/lib/wasm-sync/WebAssemblyModulesPlugin.js +2 -7
- package/lib/wasm-sync/WebAssemblyParser.js +1 -4
- package/lib/web/JsonpChunkLoadingPlugin.js +2 -1
- package/lib/web/JsonpChunkLoadingRuntimeModule.js +1 -1
- package/lib/web/JsonpTemplatePlugin.js +0 -1
- package/lib/webpack.js +21 -8
- package/lib/webworker/ImportScriptsChunkLoadingPlugin.js +2 -1
- package/lib/webworker/ImportScriptsChunkLoadingRuntimeModule.js +1 -1
- package/package.json +13 -13
- package/schemas/WebpackOptions.check.js +1 -1
- package/schemas/WebpackOptions.json +77 -93
- package/schemas/plugins/BannerPlugin.check.js +1 -1
- package/schemas/plugins/BannerPlugin.json +4 -0
- package/schemas/plugins/IgnorePlugin.json +1 -1
- package/schemas/plugins/ProgressPlugin.json +1 -1
- package/schemas/plugins/SourceMapDevToolPlugin.check.js +1 -1
- package/schemas/plugins/SourceMapDevToolPlugin.json +5 -1
- package/schemas/plugins/schemes/VirtualUrlPlugin.json +3 -3
- package/types.d.ts +1140 -505
- package/SECURITY.md +0 -9
|
@@ -17,9 +17,9 @@ const JavascriptModulesPlugin = require("../javascript/JavascriptModulesPlugin")
|
|
|
17
17
|
/** @typedef {import("../Compilation").ChunkHashContext} ChunkHashContext */
|
|
18
18
|
/** @typedef {import("../Compiler")} Compiler */
|
|
19
19
|
/** @typedef {import("../Module")} Module */
|
|
20
|
+
/** @typedef {import("../Module").RuntimeRequirements} RuntimeRequirements */
|
|
20
21
|
/** @typedef {import("../javascript/JavascriptModulesPlugin").RenderContext} RenderContext */
|
|
21
22
|
/** @typedef {import("../javascript/JavascriptModulesPlugin").StartupRenderContext} StartupRenderContext */
|
|
22
|
-
/** @typedef {import("../javascript/JavascriptModulesPlugin").ChunkRenderContext} ChunkRenderContext */
|
|
23
23
|
/** @typedef {import("../javascript/JavascriptModulesPlugin").ModuleRenderContext} ModuleRenderContext */
|
|
24
24
|
/** @typedef {import("../util/Hash")} Hash */
|
|
25
25
|
|
|
@@ -273,7 +273,7 @@ class AbstractLibraryPlugin {
|
|
|
273
273
|
|
|
274
274
|
/**
|
|
275
275
|
* @param {Chunk} chunk the chunk
|
|
276
|
-
* @param {
|
|
276
|
+
* @param {RuntimeRequirements} set runtime requirements
|
|
277
277
|
* @param {LibraryContext<T>} libraryContext context
|
|
278
278
|
* @returns {void}
|
|
279
279
|
*/
|
|
@@ -15,7 +15,6 @@ const AbstractLibraryPlugin = require("./AbstractLibraryPlugin");
|
|
|
15
15
|
/** @typedef {import("../../declarations/WebpackOptions").LibraryType} LibraryType */
|
|
16
16
|
/** @typedef {import("../Chunk")} Chunk */
|
|
17
17
|
/** @typedef {import("../Compilation").ChunkHashContext} ChunkHashContext */
|
|
18
|
-
/** @typedef {import("../Compiler")} Compiler */
|
|
19
18
|
/** @typedef {import("../javascript/JavascriptModulesPlugin").RenderContext} RenderContext */
|
|
20
19
|
/** @typedef {import("../util/Hash")} Hash */
|
|
21
20
|
/** @template T @typedef {import("./AbstractLibraryPlugin").LibraryContext<T>} LibraryContext<T> */
|
|
@@ -16,14 +16,21 @@ const AbstractLibraryPlugin = require("./AbstractLibraryPlugin");
|
|
|
16
16
|
/** @typedef {import("webpack-sources").Source} Source */
|
|
17
17
|
/** @typedef {import("../../declarations/WebpackOptions").LibraryOptions} LibraryOptions */
|
|
18
18
|
/** @typedef {import("../../declarations/WebpackOptions").LibraryType} LibraryType */
|
|
19
|
+
/** @typedef {import("../../declarations/WebpackOptions").LibraryExport} LibraryExport */
|
|
19
20
|
/** @typedef {import("../Chunk")} Chunk */
|
|
20
21
|
/** @typedef {import("../Compilation")} Compilation */
|
|
21
22
|
/** @typedef {import("../Compilation").ChunkHashContext} ChunkHashContext */
|
|
22
23
|
/** @typedef {import("../Module")} Module */
|
|
24
|
+
/** @typedef {import("../Module").RuntimeRequirements} RuntimeRequirements */
|
|
25
|
+
/** @typedef {import("../ExportsInfo").ExportInfoName} ExportInfoName */
|
|
23
26
|
/** @typedef {import("../javascript/JavascriptModulesPlugin").RenderContext} RenderContext */
|
|
24
27
|
/** @typedef {import("../javascript/JavascriptModulesPlugin").StartupRenderContext} StartupRenderContext */
|
|
25
28
|
/** @typedef {import("../util/Hash")} Hash */
|
|
26
|
-
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* @template T
|
|
32
|
+
* @typedef {import("./AbstractLibraryPlugin").LibraryContext<T>} LibraryContext<T>
|
|
33
|
+
*/
|
|
27
34
|
|
|
28
35
|
const KEYWORD_REGEX =
|
|
29
36
|
/^(await|break|case|catch|class|const|continue|debugger|default|delete|do|else|enum|export|extends|false|finally|for|function|if|implements|import|in|instanceof|interface|let|new|null|package|private|protected|public|return|super|switch|static|this|throw|try|true|typeof|var|void|while|with|yield)$/;
|
|
@@ -89,19 +96,23 @@ const accessWithInit = (accessor, existingLength, initLast = false) => {
|
|
|
89
96
|
return current;
|
|
90
97
|
};
|
|
91
98
|
|
|
99
|
+
/** @typedef {string[] | "global"} LibraryPrefix */
|
|
100
|
+
|
|
92
101
|
/**
|
|
93
102
|
* @typedef {object} AssignLibraryPluginOptions
|
|
94
103
|
* @property {LibraryType} type
|
|
95
|
-
* @property {
|
|
104
|
+
* @property {LibraryPrefix} prefix name prefix
|
|
96
105
|
* @property {string | false} declare declare name as variable
|
|
97
|
-
* @property {"error"|"static"|"copy"|"assign"} unnamed behavior for unnamed library name
|
|
98
|
-
* @property {"copy"|"assign"=} named behavior for named library name
|
|
106
|
+
* @property {"error" | "static" | "copy" | "assign"} unnamed behavior for unnamed library name
|
|
107
|
+
* @property {"copy" | "assign"=} named behavior for named library name
|
|
99
108
|
*/
|
|
100
109
|
|
|
110
|
+
/** @typedef {string | string[]} LibraryName */
|
|
111
|
+
|
|
101
112
|
/**
|
|
102
113
|
* @typedef {object} AssignLibraryPluginParsed
|
|
103
|
-
* @property {
|
|
104
|
-
* @property {
|
|
114
|
+
* @property {LibraryName} name
|
|
115
|
+
* @property {LibraryExport=} export
|
|
105
116
|
*/
|
|
106
117
|
|
|
107
118
|
/**
|
|
@@ -140,7 +151,7 @@ class AssignLibraryPlugin extends AbstractLibraryPlugin {
|
|
|
140
151
|
`Library name must be a string, string array or unset. ${AbstractLibraryPlugin.COMMON_LIBRARY_NAME_MESSAGE}`
|
|
141
152
|
);
|
|
142
153
|
}
|
|
143
|
-
const _name = /** @type {
|
|
154
|
+
const _name = /** @type {LibraryName} */ (name);
|
|
144
155
|
return {
|
|
145
156
|
name: _name,
|
|
146
157
|
export: library.export
|
|
@@ -175,7 +186,7 @@ class AssignLibraryPlugin extends AbstractLibraryPlugin {
|
|
|
175
186
|
|
|
176
187
|
/**
|
|
177
188
|
* @param {Compilation} compilation the compilation
|
|
178
|
-
* @returns {
|
|
189
|
+
* @returns {LibraryPrefix} the prefix
|
|
179
190
|
*/
|
|
180
191
|
_getPrefix(compilation) {
|
|
181
192
|
return this.prefix === "global"
|
|
@@ -187,7 +198,7 @@ class AssignLibraryPlugin extends AbstractLibraryPlugin {
|
|
|
187
198
|
* @param {AssignLibraryPluginParsed} options the library options
|
|
188
199
|
* @param {Chunk} chunk the chunk
|
|
189
200
|
* @param {Compilation} compilation the compilation
|
|
190
|
-
* @returns {
|
|
201
|
+
* @returns {string[]} the resolved full name
|
|
191
202
|
*/
|
|
192
203
|
_getResolvedFullName(options, chunk, compilation) {
|
|
193
204
|
const prefix = this._getPrefix(compilation);
|
|
@@ -196,7 +207,7 @@ class AssignLibraryPlugin extends AbstractLibraryPlugin {
|
|
|
196
207
|
...prefix,
|
|
197
208
|
...(Array.isArray(options.name) ? options.name : [options.name])
|
|
198
209
|
]
|
|
199
|
-
: prefix;
|
|
210
|
+
: /** @type {string[]} */ (prefix);
|
|
200
211
|
return fullName.map((n) =>
|
|
201
212
|
compilation.getPath(n, {
|
|
202
213
|
chunk
|
|
@@ -311,7 +322,7 @@ class AssignLibraryPlugin extends AbstractLibraryPlugin {
|
|
|
311
322
|
true
|
|
312
323
|
);
|
|
313
324
|
|
|
314
|
-
/** @type {
|
|
325
|
+
/** @type {ExportInfoName[]} */
|
|
315
326
|
const provided = [];
|
|
316
327
|
for (const exportInfo of exportsInfo.orderedExports) {
|
|
317
328
|
if (!exportInfo.provided) continue;
|
|
@@ -392,7 +403,7 @@ class AssignLibraryPlugin extends AbstractLibraryPlugin {
|
|
|
392
403
|
|
|
393
404
|
/**
|
|
394
405
|
* @param {Chunk} chunk the chunk
|
|
395
|
-
* @param {
|
|
406
|
+
* @param {RuntimeRequirements} set runtime requirements
|
|
396
407
|
* @param {LibraryContext<T>} libraryContext context
|
|
397
408
|
* @returns {void}
|
|
398
409
|
*/
|
|
@@ -5,11 +5,12 @@
|
|
|
5
5
|
|
|
6
6
|
"use strict";
|
|
7
7
|
|
|
8
|
-
/** @typedef {import("../../declarations/WebpackOptions").LibraryOptions} LibraryOptions */
|
|
9
8
|
/** @typedef {import("../../declarations/WebpackOptions").LibraryType} LibraryType */
|
|
10
9
|
/** @typedef {import("../Compiler")} Compiler */
|
|
11
10
|
|
|
12
|
-
/** @
|
|
11
|
+
/** @typedef {Set<LibraryType>} LibraryTypes */
|
|
12
|
+
|
|
13
|
+
/** @type {WeakMap<Compiler, LibraryTypes>} */
|
|
13
14
|
const enabledTypes = new WeakMap();
|
|
14
15
|
|
|
15
16
|
/**
|
|
@@ -19,7 +20,7 @@ const enabledTypes = new WeakMap();
|
|
|
19
20
|
|
|
20
21
|
/**
|
|
21
22
|
* @param {Compiler} compiler the compiler instance
|
|
22
|
-
* @returns {
|
|
23
|
+
* @returns {LibraryTypes} enabled types
|
|
23
24
|
*/
|
|
24
25
|
const getEnabledTypes = (compiler) => {
|
|
25
26
|
let set = enabledTypes.get(compiler);
|
|
@@ -87,13 +88,10 @@ class EnableLibraryPlugin {
|
|
|
87
88
|
|
|
88
89
|
if (typeof type === "string") {
|
|
89
90
|
const enableExportProperty = () => {
|
|
90
|
-
const
|
|
91
|
+
const ExportPropertyLibraryPlugin = require("./ExportPropertyLibraryPlugin");
|
|
91
92
|
|
|
92
|
-
new
|
|
93
|
-
type
|
|
94
|
-
nsObjectUsed: !["module", "modern-module"].includes(type),
|
|
95
|
-
runtimeExportsUsed: !["module", "modern-module"].includes(type),
|
|
96
|
-
renderStartupUsed: !["module", "modern-module"].includes(type)
|
|
93
|
+
new ExportPropertyLibraryPlugin({
|
|
94
|
+
type
|
|
97
95
|
}).apply(compiler);
|
|
98
96
|
};
|
|
99
97
|
switch (type) {
|
|
@@ -286,8 +284,6 @@ class EnableLibraryPlugin {
|
|
|
286
284
|
}
|
|
287
285
|
case "module":
|
|
288
286
|
case "modern-module": {
|
|
289
|
-
enableExportProperty();
|
|
290
|
-
|
|
291
287
|
const ModuleLibraryPlugin = require("./ModuleLibraryPlugin");
|
|
292
288
|
|
|
293
289
|
new ModuleLibraryPlugin({
|
|
@@ -15,23 +15,21 @@ const AbstractLibraryPlugin = require("./AbstractLibraryPlugin");
|
|
|
15
15
|
/** @typedef {import("webpack-sources").Source} Source */
|
|
16
16
|
/** @typedef {import("../../declarations/WebpackOptions").LibraryOptions} LibraryOptions */
|
|
17
17
|
/** @typedef {import("../../declarations/WebpackOptions").LibraryType} LibraryType */
|
|
18
|
+
/** @typedef {import("../../declarations/WebpackOptions").LibraryExport} LibraryExport */
|
|
18
19
|
/** @typedef {import("../Chunk")} Chunk */
|
|
19
|
-
/** @typedef {import("../Compiler")} Compiler */
|
|
20
20
|
/** @typedef {import("../Module")} Module */
|
|
21
|
+
/** @typedef {import("../Module").RuntimeRequirements} RuntimeRequirements */
|
|
21
22
|
/** @typedef {import("../javascript/JavascriptModulesPlugin").StartupRenderContext} StartupRenderContext */
|
|
22
23
|
/** @template T @typedef {import("./AbstractLibraryPlugin").LibraryContext<T>} LibraryContext<T> */
|
|
23
24
|
|
|
24
25
|
/**
|
|
25
26
|
* @typedef {object} ExportPropertyLibraryPluginParsed
|
|
26
|
-
* @property {
|
|
27
|
+
* @property {LibraryExport=} export
|
|
27
28
|
*/
|
|
28
29
|
|
|
29
30
|
/**
|
|
30
31
|
* @typedef {object} ExportPropertyLibraryPluginOptions
|
|
31
32
|
* @property {LibraryType} type
|
|
32
|
-
* @property {boolean} nsObjectUsed the namespace object is used
|
|
33
|
-
* @property {boolean} runtimeExportsUsed runtime exports are used
|
|
34
|
-
* @property {boolean} renderStartupUsed render startup is used
|
|
35
33
|
*/
|
|
36
34
|
/**
|
|
37
35
|
* @typedef {ExportPropertyLibraryPluginParsed} T
|
|
@@ -41,14 +39,11 @@ class ExportPropertyLibraryPlugin extends AbstractLibraryPlugin {
|
|
|
41
39
|
/**
|
|
42
40
|
* @param {ExportPropertyLibraryPluginOptions} options options
|
|
43
41
|
*/
|
|
44
|
-
constructor({ type
|
|
42
|
+
constructor({ type }) {
|
|
45
43
|
super({
|
|
46
44
|
pluginName: "ExportPropertyLibraryPlugin",
|
|
47
45
|
type
|
|
48
46
|
});
|
|
49
|
-
this.nsObjectUsed = nsObjectUsed;
|
|
50
|
-
this.runtimeExportsUsed = runtimeExportsUsed;
|
|
51
|
-
this.renderStartupUsed = renderStartupUsed;
|
|
52
47
|
}
|
|
53
48
|
|
|
54
49
|
/**
|
|
@@ -57,7 +52,7 @@ class ExportPropertyLibraryPlugin extends AbstractLibraryPlugin {
|
|
|
57
52
|
*/
|
|
58
53
|
parseOptions(library) {
|
|
59
54
|
return {
|
|
60
|
-
export:
|
|
55
|
+
export: library.export
|
|
61
56
|
};
|
|
62
57
|
}
|
|
63
58
|
|
|
@@ -82,25 +77,19 @@ class ExportPropertyLibraryPlugin extends AbstractLibraryPlugin {
|
|
|
82
77
|
exportsInfo.canMangleUse = false;
|
|
83
78
|
} else {
|
|
84
79
|
const exportsInfo = moduleGraph.getExportsInfo(module);
|
|
85
|
-
|
|
86
|
-
exportsInfo.setUsedInUnknownWay(runtime);
|
|
87
|
-
} else {
|
|
88
|
-
exportsInfo.setAllKnownExportsUsed(runtime);
|
|
89
|
-
}
|
|
80
|
+
exportsInfo.setUsedInUnknownWay(runtime);
|
|
90
81
|
}
|
|
91
82
|
moduleGraph.addExtraReason(module, "used as library export");
|
|
92
83
|
}
|
|
93
84
|
|
|
94
85
|
/**
|
|
95
86
|
* @param {Chunk} chunk the chunk
|
|
96
|
-
* @param {
|
|
87
|
+
* @param {RuntimeRequirements} set runtime requirements
|
|
97
88
|
* @param {LibraryContext<T>} libraryContext context
|
|
98
89
|
* @returns {void}
|
|
99
90
|
*/
|
|
100
91
|
runtimeRequirements(chunk, set, libraryContext) {
|
|
101
|
-
|
|
102
|
-
set.add(RuntimeGlobals.exports);
|
|
103
|
-
}
|
|
92
|
+
set.add(RuntimeGlobals.exports);
|
|
104
93
|
}
|
|
105
94
|
|
|
106
95
|
/**
|
|
@@ -111,7 +100,6 @@ class ExportPropertyLibraryPlugin extends AbstractLibraryPlugin {
|
|
|
111
100
|
* @returns {Source} source with library export
|
|
112
101
|
*/
|
|
113
102
|
renderStartup(source, module, renderContext, { options }) {
|
|
114
|
-
if (!this.renderStartupUsed) return source;
|
|
115
103
|
if (!options.export) return source;
|
|
116
104
|
const postfix = `${RuntimeGlobals.exports} = ${
|
|
117
105
|
RuntimeGlobals.exports
|
|
@@ -13,10 +13,13 @@ const AbstractLibraryPlugin = require("./AbstractLibraryPlugin");
|
|
|
13
13
|
/** @typedef {import("../../declarations/WebpackOptions").LibraryType} LibraryType */
|
|
14
14
|
/** @typedef {import("../Chunk")} Chunk */
|
|
15
15
|
/** @typedef {import("../Compilation").ChunkHashContext} ChunkHashContext */
|
|
16
|
-
/** @typedef {import("../Compiler")} Compiler */
|
|
17
16
|
/** @typedef {import("../javascript/JavascriptModulesPlugin").RenderContext} RenderContext */
|
|
18
17
|
/** @typedef {import("../util/Hash")} Hash */
|
|
19
|
-
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* @template T
|
|
21
|
+
* @typedef {import("./AbstractLibraryPlugin").LibraryContext<T>} LibraryContext<T>
|
|
22
|
+
*/
|
|
20
23
|
|
|
21
24
|
/**
|
|
22
25
|
* @typedef {object} JsonpLibraryPluginOptions
|
|
@@ -6,24 +6,24 @@
|
|
|
6
6
|
"use strict";
|
|
7
7
|
|
|
8
8
|
const { ConcatSource } = require("webpack-sources");
|
|
9
|
+
const { UsageState } = require("../ExportsInfo");
|
|
9
10
|
const RuntimeGlobals = require("../RuntimeGlobals");
|
|
10
11
|
const Template = require("../Template");
|
|
11
|
-
const CommonJsSelfReferenceDependency = require("../dependencies/CommonJsSelfReferenceDependency");
|
|
12
12
|
const ConcatenatedModule = require("../optimize/ConcatenatedModule");
|
|
13
13
|
const propertyAccess = require("../util/propertyAccess");
|
|
14
|
+
const { getEntryRuntime } = require("../util/runtime");
|
|
14
15
|
const AbstractLibraryPlugin = require("./AbstractLibraryPlugin");
|
|
15
16
|
|
|
16
17
|
/** @typedef {import("webpack-sources").Source} Source */
|
|
17
18
|
/** @typedef {import("../../declarations/WebpackOptions").LibraryOptions} LibraryOptions */
|
|
18
19
|
/** @typedef {import("../../declarations/WebpackOptions").LibraryType} LibraryType */
|
|
20
|
+
/** @typedef {import("../../declarations/WebpackOptions").LibraryExport} LibraryExport */
|
|
19
21
|
/** @typedef {import("../Chunk")} Chunk */
|
|
20
|
-
/** @typedef {import("../Compilation").ChunkHashContext} ChunkHashContext */
|
|
21
22
|
/** @typedef {import("../Compiler")} Compiler */
|
|
22
23
|
/** @typedef {import("../Module")} Module */
|
|
23
|
-
/** @typedef {import("../Module").
|
|
24
|
+
/** @typedef {import("../Module").RuntimeRequirements} RuntimeRequirements */
|
|
24
25
|
/** @typedef {import("../javascript/JavascriptModulesPlugin").StartupRenderContext} StartupRenderContext */
|
|
25
26
|
/** @typedef {import("../javascript/JavascriptModulesPlugin").ModuleRenderContext} ModuleRenderContext */
|
|
26
|
-
/** @typedef {import("../util/Hash")} Hash */
|
|
27
27
|
|
|
28
28
|
/**
|
|
29
29
|
* @template T
|
|
@@ -38,7 +38,7 @@ const AbstractLibraryPlugin = require("./AbstractLibraryPlugin");
|
|
|
38
38
|
/**
|
|
39
39
|
* @typedef {object} ModuleLibraryPluginParsed
|
|
40
40
|
* @property {string} name
|
|
41
|
-
* @property {
|
|
41
|
+
* @property {LibraryExport=} export
|
|
42
42
|
*/
|
|
43
43
|
|
|
44
44
|
const PLUGIN_NAME = "ModuleLibraryPlugin";
|
|
@@ -73,6 +73,47 @@ class ModuleLibraryPlugin extends AbstractLibraryPlugin {
|
|
|
73
73
|
});
|
|
74
74
|
}
|
|
75
75
|
|
|
76
|
+
/**
|
|
77
|
+
* @param {Module} module the exporting entry module
|
|
78
|
+
* @param {string} entryName the name of the entrypoint
|
|
79
|
+
* @param {LibraryContext<T>} libraryContext context
|
|
80
|
+
* @returns {void}
|
|
81
|
+
*/
|
|
82
|
+
finishEntryModule(
|
|
83
|
+
module,
|
|
84
|
+
entryName,
|
|
85
|
+
{ options, compilation, compilation: { moduleGraph } }
|
|
86
|
+
) {
|
|
87
|
+
const runtime = getEntryRuntime(compilation, entryName);
|
|
88
|
+
if (options.export) {
|
|
89
|
+
const exportsInfo = moduleGraph.getExportInfo(
|
|
90
|
+
module,
|
|
91
|
+
Array.isArray(options.export) ? options.export[0] : options.export
|
|
92
|
+
);
|
|
93
|
+
exportsInfo.setUsed(UsageState.Used, runtime);
|
|
94
|
+
exportsInfo.canMangleUse = false;
|
|
95
|
+
} else {
|
|
96
|
+
const exportsInfo = moduleGraph.getExportsInfo(module);
|
|
97
|
+
// If the entry module is commonjs, its exports cannot be mangled
|
|
98
|
+
if (module.buildMeta && module.buildMeta.treatAsCommonJs) {
|
|
99
|
+
exportsInfo.setUsedInUnknownWay(runtime);
|
|
100
|
+
} else {
|
|
101
|
+
exportsInfo.setAllKnownExportsUsed(runtime);
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
moduleGraph.addExtraReason(module, "used as library export");
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
/**
|
|
108
|
+
* @param {Chunk} chunk the chunk
|
|
109
|
+
* @param {RuntimeRequirements} set runtime requirements
|
|
110
|
+
* @param {LibraryContext<T>} libraryContext context
|
|
111
|
+
* @returns {void}
|
|
112
|
+
*/
|
|
113
|
+
runtimeRequirements(chunk, set, libraryContext) {
|
|
114
|
+
set.add(RuntimeGlobals.exports);
|
|
115
|
+
}
|
|
116
|
+
|
|
76
117
|
/**
|
|
77
118
|
* @param {LibraryOptions} library normalized library option
|
|
78
119
|
* @returns {T | false} preprocess as needed by overriding
|
|
@@ -101,21 +142,18 @@ class ModuleLibraryPlugin extends AbstractLibraryPlugin {
|
|
|
101
142
|
renderStartup(
|
|
102
143
|
source,
|
|
103
144
|
module,
|
|
104
|
-
{
|
|
145
|
+
{
|
|
146
|
+
moduleGraph,
|
|
147
|
+
chunk,
|
|
148
|
+
codeGenerationResults,
|
|
149
|
+
inlined,
|
|
150
|
+
inlinedInIIFE,
|
|
151
|
+
runtimeTemplate
|
|
152
|
+
},
|
|
105
153
|
{ options, compilation }
|
|
106
154
|
) {
|
|
107
155
|
const result = new ConcatSource(source);
|
|
108
156
|
|
|
109
|
-
if (!module.buildMeta || !module.buildMeta.exportsType) {
|
|
110
|
-
for (const dependency of module.dependencies) {
|
|
111
|
-
if (dependency instanceof CommonJsSelfReferenceDependency) {
|
|
112
|
-
result.add(`export { ${RuntimeGlobals.exports} as default }`);
|
|
113
|
-
break;
|
|
114
|
-
}
|
|
115
|
-
}
|
|
116
|
-
return result;
|
|
117
|
-
}
|
|
118
|
-
|
|
119
157
|
const exportsInfo = options.export
|
|
120
158
|
? [
|
|
121
159
|
moduleGraph.getExportInfo(
|
|
@@ -126,9 +164,7 @@ class ModuleLibraryPlugin extends AbstractLibraryPlugin {
|
|
|
126
164
|
: moduleGraph.getExportsInfo(module).orderedExports;
|
|
127
165
|
const definitions =
|
|
128
166
|
inlined && !inlinedInIIFE
|
|
129
|
-
? (module.buildMeta &&
|
|
130
|
-
/** @type {GenerationMeta} */ module.buildMeta.exportsFinalName) ||
|
|
131
|
-
{}
|
|
167
|
+
? (module.buildMeta && module.buildMeta.exportsFinalName) || {}
|
|
132
168
|
: {};
|
|
133
169
|
/** @type {string[]} */
|
|
134
170
|
const shortHandedExports = [];
|
|
@@ -136,54 +172,55 @@ class ModuleLibraryPlugin extends AbstractLibraryPlugin {
|
|
|
136
172
|
const exports = [];
|
|
137
173
|
const isAsync = moduleGraph.isAsync(module);
|
|
138
174
|
|
|
175
|
+
const treatAsCommonJs =
|
|
176
|
+
module.buildMeta && module.buildMeta.treatAsCommonJs;
|
|
177
|
+
const skipRenderDefaultExport = Boolean(treatAsCommonJs);
|
|
178
|
+
|
|
139
179
|
if (isAsync) {
|
|
140
180
|
result.add(
|
|
141
181
|
`${RuntimeGlobals.exports} = await ${RuntimeGlobals.exports};\n`
|
|
142
182
|
);
|
|
143
183
|
}
|
|
144
184
|
|
|
145
|
-
const
|
|
146
|
-
? "const"
|
|
147
|
-
: "var";
|
|
148
|
-
|
|
149
|
-
for (const exportInfo of exportsInfo) {
|
|
185
|
+
outer: for (const exportInfo of exportsInfo) {
|
|
150
186
|
if (!exportInfo.provided) continue;
|
|
151
187
|
|
|
152
|
-
|
|
188
|
+
const originalName = exportInfo.name;
|
|
153
189
|
|
|
154
|
-
|
|
190
|
+
if (skipRenderDefaultExport && originalName === "default") continue;
|
|
155
191
|
|
|
156
|
-
|
|
157
|
-
|
|
192
|
+
const target = exportInfo.findTarget(moduleGraph, (_m) => true);
|
|
193
|
+
if (target) {
|
|
194
|
+
const reexportsInfo = moduleGraph.getExportsInfo(target.module);
|
|
158
195
|
|
|
159
|
-
for (const reexportInfo of
|
|
196
|
+
for (const reexportInfo of reexportsInfo.orderedExports) {
|
|
160
197
|
if (
|
|
161
198
|
reexportInfo.provided === false &&
|
|
162
199
|
reexportInfo.name !== "default" &&
|
|
163
|
-
reexportInfo.name === /** @type {string[]} */ (
|
|
200
|
+
reexportInfo.name === /** @type {string[]} */ (target.export)[0]
|
|
164
201
|
) {
|
|
165
|
-
|
|
202
|
+
continue outer;
|
|
166
203
|
}
|
|
167
204
|
}
|
|
168
205
|
}
|
|
169
206
|
|
|
170
|
-
if (shouldContinue) continue;
|
|
171
|
-
|
|
172
|
-
const originalName = exportInfo.name;
|
|
173
207
|
const usedName =
|
|
174
208
|
/** @type {string} */
|
|
175
209
|
(exportInfo.getUsedName(originalName, chunk.runtime));
|
|
176
210
|
/** @type {string | undefined} */
|
|
177
211
|
const definition = definitions[usedName];
|
|
178
|
-
const finalName =
|
|
179
|
-
definition ||
|
|
180
|
-
`${RuntimeGlobals.exports}${Template.toIdentifier(originalName)}`;
|
|
181
212
|
|
|
182
|
-
|
|
213
|
+
/** @type {string | undefined} */
|
|
214
|
+
let finalName;
|
|
215
|
+
|
|
216
|
+
if (definition) {
|
|
217
|
+
finalName = definition;
|
|
218
|
+
} else {
|
|
219
|
+
finalName = `${RuntimeGlobals.exports}${Template.toIdentifier(originalName)}`;
|
|
183
220
|
result.add(
|
|
184
|
-
`${
|
|
185
|
-
usedName
|
|
186
|
-
|
|
221
|
+
`${runtimeTemplate.renderConst()} ${finalName} = ${RuntimeGlobals.exports}${propertyAccess(
|
|
222
|
+
[usedName]
|
|
223
|
+
)};\n`
|
|
187
224
|
);
|
|
188
225
|
}
|
|
189
226
|
|
|
@@ -201,7 +238,9 @@ class ModuleLibraryPlugin extends AbstractLibraryPlugin {
|
|
|
201
238
|
|
|
202
239
|
if (topLevelDeclarations && topLevelDeclarations.has(originalName)) {
|
|
203
240
|
const name = `${RuntimeGlobals.exports}${Template.toIdentifier(originalName)}`;
|
|
204
|
-
result.add(
|
|
241
|
+
result.add(
|
|
242
|
+
`${runtimeTemplate.renderConst()} ${name} = ${finalName};\n`
|
|
243
|
+
);
|
|
205
244
|
shortHandedExports.push(`${name} as ${originalName}`);
|
|
206
245
|
} else {
|
|
207
246
|
exports.push([originalName, finalName]);
|
|
@@ -218,12 +257,18 @@ class ModuleLibraryPlugin extends AbstractLibraryPlugin {
|
|
|
218
257
|
}
|
|
219
258
|
}
|
|
220
259
|
|
|
260
|
+
if (treatAsCommonJs) {
|
|
261
|
+
shortHandedExports.push(`${RuntimeGlobals.exports} as default`);
|
|
262
|
+
}
|
|
263
|
+
|
|
221
264
|
if (shortHandedExports.length > 0) {
|
|
222
265
|
result.add(`export { ${shortHandedExports.join(", ")} };\n`);
|
|
223
266
|
}
|
|
224
267
|
|
|
225
268
|
for (const [exportName, final] of exports) {
|
|
226
|
-
result.add(
|
|
269
|
+
result.add(
|
|
270
|
+
`export ${runtimeTemplate.renderConst()} ${exportName} = ${final};\n`
|
|
271
|
+
);
|
|
227
272
|
}
|
|
228
273
|
|
|
229
274
|
return result;
|
|
@@ -17,7 +17,6 @@ const AbstractLibraryPlugin = require("./AbstractLibraryPlugin");
|
|
|
17
17
|
/** @typedef {import("../../declarations/WebpackOptions").LibraryType} LibraryType */
|
|
18
18
|
/** @typedef {import("../Chunk")} Chunk */
|
|
19
19
|
/** @typedef {import("../Compilation").ChunkHashContext} ChunkHashContext */
|
|
20
|
-
/** @typedef {import("../Compiler")} Compiler */
|
|
21
20
|
/** @typedef {import("../javascript/JavascriptModulesPlugin").RenderContext} RenderContext */
|
|
22
21
|
/** @typedef {import("../util/Hash")} Hash */
|
|
23
22
|
/** @template T @typedef {import("./AbstractLibraryPlugin").LibraryContext<T>} LibraryContext<T> */
|
|
@@ -16,14 +16,12 @@ const AbstractLibraryPlugin = require("./AbstractLibraryPlugin");
|
|
|
16
16
|
/** @typedef {import("../../declarations/WebpackOptions").LibraryName} LibraryName */
|
|
17
17
|
/** @typedef {import("../../declarations/WebpackOptions").LibraryOptions} LibraryOptions */
|
|
18
18
|
/** @typedef {import("../../declarations/WebpackOptions").LibraryType} LibraryType */
|
|
19
|
-
/** @typedef {import("../Compiler")} Compiler */
|
|
20
19
|
/** @typedef {import("../javascript/JavascriptModulesPlugin").RenderContext} RenderContext */
|
|
21
20
|
/** @typedef {import("../ExternalModule").RequestRecord} RequestRecord */
|
|
22
|
-
|
|
21
|
+
|
|
23
22
|
/**
|
|
24
23
|
* @template T
|
|
25
|
-
* @typedef {import("./AbstractLibraryPlugin").LibraryContext<T>}
|
|
26
|
-
* LibraryContext<T>
|
|
24
|
+
* @typedef {import("./AbstractLibraryPlugin").LibraryContext<T>} LibraryContext<T>
|
|
27
25
|
*/
|
|
28
26
|
|
|
29
27
|
/**
|
|
@@ -33,9 +31,11 @@ const AbstractLibraryPlugin = require("./AbstractLibraryPlugin");
|
|
|
33
31
|
const accessorToObjectAccess = (accessor) =>
|
|
34
32
|
accessor.map((a) => `[${JSON.stringify(a)}]`).join("");
|
|
35
33
|
|
|
34
|
+
/** @typedef {string | string[]} Accessor */
|
|
35
|
+
|
|
36
36
|
/**
|
|
37
37
|
* @param {string|undefined} base the path prefix
|
|
38
|
-
* @param {
|
|
38
|
+
* @param {Accessor} accessor the accessor
|
|
39
39
|
* @param {string=} joinWith the element separator
|
|
40
40
|
* @returns {string} the path
|
|
41
41
|
*/
|
|
@@ -55,8 +55,6 @@ const accessorAccess = (base, accessor, joinWith = ", ") => {
|
|
|
55
55
|
.join(joinWith);
|
|
56
56
|
};
|
|
57
57
|
|
|
58
|
-
/** @typedef {string | string[] | LibraryCustomUmdObject} UmdLibraryPluginName */
|
|
59
|
-
|
|
60
58
|
/**
|
|
61
59
|
* @typedef {object} UmdLibraryPluginOptions
|
|
62
60
|
* @property {LibraryType} type
|
|
@@ -194,10 +192,9 @@ class UmdLibraryPlugin extends AbstractLibraryPlugin {
|
|
|
194
192
|
/** @type {RequestRecord} */
|
|
195
193
|
(request).root;
|
|
196
194
|
}
|
|
197
|
-
return `root${accessorToObjectAccess(
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
)}`;
|
|
195
|
+
return `root${accessorToObjectAccess([
|
|
196
|
+
...(Array.isArray(request) ? request : [request])
|
|
197
|
+
])}`;
|
|
201
198
|
})
|
|
202
199
|
.join(", ")
|
|
203
200
|
);
|
|
@@ -250,17 +247,14 @@ class UmdLibraryPlugin extends AbstractLibraryPlugin {
|
|
|
250
247
|
.join(", ");
|
|
251
248
|
|
|
252
249
|
/**
|
|
253
|
-
* @param {
|
|
250
|
+
* @param {Accessor} library library name
|
|
254
251
|
* @returns {string} stringified library name
|
|
255
252
|
*/
|
|
256
253
|
const libraryName = (library) =>
|
|
257
254
|
JSON.stringify(
|
|
258
255
|
replaceKeys(
|
|
259
256
|
/** @type {string} */
|
|
260
|
-
(
|
|
261
|
-
/** @type {string[]} */
|
|
262
|
-
([...(Array.isArray(library) ? library : [library])]).pop()
|
|
263
|
-
)
|
|
257
|
+
([...(Array.isArray(library) ? library : [library])].pop())
|
|
264
258
|
)
|
|
265
259
|
);
|
|
266
260
|
|
|
@@ -324,7 +318,7 @@ class UmdLibraryPlugin extends AbstractLibraryPlugin {
|
|
|
324
318
|
"commonjs"
|
|
325
319
|
)} else if(typeof exports === 'object')\n` +
|
|
326
320
|
` exports[${libraryName(
|
|
327
|
-
/** @type {
|
|
321
|
+
/** @type {Accessor} */
|
|
328
322
|
(names.commonjs || names.root)
|
|
329
323
|
)}] = factory(${externalsRequireArray(
|
|
330
324
|
"commonjs"
|
|
@@ -332,7 +326,7 @@ class UmdLibraryPlugin extends AbstractLibraryPlugin {
|
|
|
332
326
|
` ${replaceKeys(
|
|
333
327
|
accessorAccess(
|
|
334
328
|
"root",
|
|
335
|
-
/** @type {
|
|
329
|
+
/** @type {Accessor} */
|
|
336
330
|
(names.root || names.commonjs)
|
|
337
331
|
)
|
|
338
332
|
)} = factory(${externalsRootArray(externals)});\n`
|