webpack 5.101.3 → 5.102.1
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 +37 -27
- package/lib/ChunkGroup.js +8 -10
- package/lib/ChunkTemplate.js +1 -1
- package/lib/CleanPlugin.js +3 -3
- package/lib/CodeGenerationResults.js +3 -2
- package/lib/CompatibilityPlugin.js +29 -12
- package/lib/Compilation.js +209 -196
- package/lib/Compiler.js +36 -35
- package/lib/ConcatenationScope.js +6 -1
- package/lib/ConditionalInitFragment.js +1 -1
- package/lib/ConstPlugin.js +6 -5
- package/lib/ContextExclusionPlugin.js +0 -1
- package/lib/ContextModule.js +25 -21
- package/lib/ContextModuleFactory.js +30 -11
- package/lib/ContextReplacementPlugin.js +38 -15
- package/lib/DefinePlugin.js +5 -9
- package/lib/DelegatedModule.js +7 -11
- package/lib/DependenciesBlock.js +0 -2
- package/lib/Dependency.js +9 -11
- package/lib/DependencyTemplates.js +2 -4
- 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 +105 -90
- 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 +42 -25
- 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 +146 -89
- package/lib/NormalModuleFactory.js +132 -42
- 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 +22 -12
- package/lib/SourceMapDevToolModuleOptionsPlugin.js +2 -2
- package/lib/SourceMapDevToolPlugin.js +11 -18
- 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 +167 -0
- package/lib/asset/AssetBytesParser.js +37 -0
- package/lib/asset/AssetGenerator.js +22 -37
- 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/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/cache/getLazyHashedEtag.js +1 -1
- package/lib/config/browserslistTargetHandler.js +77 -76
- package/lib/config/defaults.js +162 -23
- package/lib/config/normalization.js +18 -3
- package/lib/config/target.js +1 -1
- 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 +13 -19
- package/lib/css/CssParser.js +3 -3
- package/lib/css/walkCssTokens.js +2 -2
- 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 +4 -7
- 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 +33 -14
- package/lib/dependencies/HarmonyImportDependencyParserPlugin.js +20 -23
- package/lib/dependencies/HarmonyImportSideEffectDependency.js +0 -4
- package/lib/dependencies/HarmonyImportSpecifierDependency.js +46 -31
- package/lib/dependencies/HarmonyModulesPlugin.js +3 -3
- package/lib/dependencies/ImportContextDependency.js +13 -0
- 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 +3 -2
- package/lib/dependencies/ImportParserPlugin.js +288 -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 +4 -12
- 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/HashedModuleIdsPlugin.js +5 -7
- package/lib/ids/IdHelpers.js +1 -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 +46 -24
- package/lib/javascript/JavascriptParser.js +120 -55
- 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 +15 -6
- 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/RealContentHashPlugin.js +5 -3
- 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/FileMiddleware.js +1 -1
- package/lib/serialization/NullPrototypeObjectSerializer.js +5 -3
- package/lib/serialization/ObjectMiddleware.js +31 -20
- 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 +179 -95
- 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/Hash.js +35 -5
- 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 +1 -2
- package/lib/util/createHash.js +85 -15
- 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/hash/BatchedHash.js +47 -8
- package/lib/util/hash/wasm-hash.js +53 -13
- 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 -10
- 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 -13
- 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 +21 -21
- package/schemas/WebpackOptions.check.js +1 -1
- package/schemas/WebpackOptions.json +93 -96
- 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/ids/HashedModuleIdsPlugin.check.d.ts +7 -0
- package/schemas/plugins/ids/HashedModuleIdsPlugin.check.js +6 -0
- package/schemas/plugins/{HashedModuleIdsPlugin.json → ids/HashedModuleIdsPlugin.json} +15 -2
- package/schemas/plugins/schemes/VirtualUrlPlugin.json +3 -3
- package/types.d.ts +1699 -706
- package/SECURITY.md +0 -9
- package/schemas/plugins/HashedModuleIdsPlugin.check.d.ts +0 -7
- package/schemas/plugins/HashedModuleIdsPlugin.check.js +0 -6
|
@@ -73,9 +73,8 @@ const DefaultStatsPrinterPlugin = require("./stats/DefaultStatsPrinterPlugin");
|
|
|
73
73
|
|
|
74
74
|
const { cleverMerge } = require("./util/cleverMerge");
|
|
75
75
|
|
|
76
|
-
/** @typedef {import("../declarations/WebpackOptions").WebpackOptionsNormalized} WebpackOptions */
|
|
77
76
|
/** @typedef {import("../declarations/WebpackOptions").WebpackPluginFunction} WebpackPluginFunction */
|
|
78
|
-
/** @typedef {import("
|
|
77
|
+
/** @typedef {import("./config/defaults").WebpackOptionsNormalizedWithDefaults} WebpackOptions */
|
|
79
78
|
/** @typedef {import("./Compiler")} Compiler */
|
|
80
79
|
/** @typedef {import("./util/fs").InputFileSystem} InputFileSystem */
|
|
81
80
|
/** @typedef {import("./util/fs").IntermediateFileSystem} IntermediateFileSystem */
|
|
@@ -93,7 +92,7 @@ class WebpackOptionsApply extends OptionsApply {
|
|
|
93
92
|
* @returns {WebpackOptions} options object
|
|
94
93
|
*/
|
|
95
94
|
process(options, compiler) {
|
|
96
|
-
compiler.outputPath =
|
|
95
|
+
compiler.outputPath = options.output.path;
|
|
97
96
|
compiler.recordsInputPath = options.recordsInputPath || null;
|
|
98
97
|
compiler.recordsOutputPath = options.recordsOutputPath || null;
|
|
99
98
|
compiler.name = options.name;
|
|
@@ -111,115 +110,92 @@ class WebpackOptionsApply extends OptionsApply {
|
|
|
111
110
|
const NodeTargetPlugin = require("./node/NodeTargetPlugin");
|
|
112
111
|
|
|
113
112
|
new NodeTargetPlugin().apply(compiler);
|
|
114
|
-
}
|
|
115
|
-
if (options.externalsPresets.electronMain) {
|
|
116
|
-
// @ts-expect-error https://github.com/microsoft/TypeScript/issues/41697
|
|
117
|
-
const ElectronTargetPlugin = require("./electron/ElectronTargetPlugin");
|
|
118
|
-
|
|
119
|
-
new ElectronTargetPlugin("main").apply(compiler);
|
|
120
|
-
}
|
|
121
|
-
if (options.externalsPresets.electronPreload) {
|
|
122
|
-
// @ts-expect-error https://github.com/microsoft/TypeScript/issues/41697
|
|
123
|
-
const ElectronTargetPlugin = require("./electron/ElectronTargetPlugin");
|
|
124
113
|
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
const ElectronTargetPlugin = require("./electron/ElectronTargetPlugin");
|
|
114
|
+
// Handle external CSS `@import` and `url()`
|
|
115
|
+
if (options.experiments.css) {
|
|
116
|
+
// @ts-expect-error https://github.com/microsoft/TypeScript/issues/41697
|
|
117
|
+
const ExternalsPlugin = require("./ExternalsPlugin");
|
|
130
118
|
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
119
|
+
new ExternalsPlugin(
|
|
120
|
+
"module",
|
|
121
|
+
({ request, dependencyType, contextInfo }, callback) => {
|
|
122
|
+
if (
|
|
123
|
+
/\.css(\?|$)/.test(contextInfo.issuer) &&
|
|
124
|
+
/^(\/\/|https?:\/\/|#)/.test(request)
|
|
125
|
+
) {
|
|
126
|
+
if (dependencyType === "url") {
|
|
127
|
+
return callback(null, `asset ${request}`);
|
|
128
|
+
} else if (
|
|
129
|
+
dependencyType === "css-import" &&
|
|
130
|
+
options.experiments.css
|
|
131
|
+
) {
|
|
132
|
+
return callback(null, `css-import ${request}`);
|
|
133
|
+
}
|
|
134
|
+
}
|
|
141
135
|
|
|
142
|
-
|
|
136
|
+
callback();
|
|
137
|
+
}
|
|
138
|
+
).apply(compiler);
|
|
139
|
+
}
|
|
143
140
|
}
|
|
144
|
-
if (options.externalsPresets.
|
|
145
|
-
|
|
146
|
-
const ExternalsPlugin = require("./ExternalsPlugin");
|
|
141
|
+
if (options.externalsPresets.webAsync || options.externalsPresets.web) {
|
|
142
|
+
const type = options.externalsPresets.webAsync ? "import" : "module";
|
|
147
143
|
|
|
148
|
-
new ExternalsPlugin("node-commonjs", "nw.gui").apply(compiler);
|
|
149
|
-
}
|
|
150
|
-
if (options.externalsPresets.webAsync) {
|
|
151
144
|
// @ts-expect-error https://github.com/microsoft/TypeScript/issues/41697
|
|
152
145
|
const ExternalsPlugin = require("./ExternalsPlugin");
|
|
153
146
|
|
|
154
|
-
new ExternalsPlugin(
|
|
155
|
-
if (
|
|
156
|
-
if (
|
|
147
|
+
new ExternalsPlugin(type, ({ request, dependencyType }, callback) => {
|
|
148
|
+
if (/^(\/\/|https?:\/\/|#|std:|jsr:|npm:)/.test(request)) {
|
|
149
|
+
if (dependencyType === "url") {
|
|
157
150
|
return callback(null, `asset ${request}`);
|
|
158
|
-
}
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
return callback(null, `css-import ${request}`);
|
|
162
|
-
}
|
|
163
|
-
} else if (
|
|
164
|
-
options.experiments.css &&
|
|
165
|
-
/^(\/\/|https?:\/\/|std:)/.test(/** @type {string} */ (request))
|
|
166
|
-
) {
|
|
167
|
-
if (/^\.css(\?|$)/.test(/** @type {string} */ (request))) {
|
|
168
|
-
return callback(null, `css-import ${request}`);
|
|
169
|
-
}
|
|
170
|
-
return callback(null, `import ${request}`);
|
|
171
|
-
}
|
|
172
|
-
callback();
|
|
173
|
-
}).apply(compiler);
|
|
174
|
-
} else if (options.externalsPresets.web) {
|
|
175
|
-
// @ts-expect-error https://github.com/microsoft/TypeScript/issues/41697
|
|
176
|
-
const ExternalsPlugin = require("./ExternalsPlugin");
|
|
177
|
-
|
|
178
|
-
new ExternalsPlugin("module", ({ request, dependencyType }, callback) => {
|
|
179
|
-
if (dependencyType === "url") {
|
|
180
|
-
if (/^(\/\/|https?:\/\/|#)/.test(/** @type {string} */ (request))) {
|
|
181
|
-
return callback(null, `asset ${request}`);
|
|
182
|
-
}
|
|
183
|
-
} else if (options.experiments.css && dependencyType === "css-import") {
|
|
184
|
-
if (/^(\/\/|https?:\/\/|#)/.test(/** @type {string} */ (request))) {
|
|
185
|
-
return callback(null, `css-import ${request}`);
|
|
186
|
-
}
|
|
187
|
-
} else if (
|
|
188
|
-
/^(\/\/|https?:\/\/|std:)/.test(/** @type {string} */ (request))
|
|
189
|
-
) {
|
|
190
|
-
if (
|
|
191
|
-
options.experiments.css &&
|
|
192
|
-
/^\.css((\?)|$)/.test(/** @type {string} */ (request))
|
|
151
|
+
} else if (
|
|
152
|
+
dependencyType === "css-import" &&
|
|
153
|
+
options.experiments.css
|
|
193
154
|
) {
|
|
194
155
|
return callback(null, `css-import ${request}`);
|
|
156
|
+
} else if (/^(\/\/|https?:\/\/|std:|jsr:|npm:)/.test(request)) {
|
|
157
|
+
return callback(null, `${type} ${request}`);
|
|
195
158
|
}
|
|
196
|
-
return callback(null, `module ${request}`);
|
|
197
159
|
}
|
|
160
|
+
|
|
198
161
|
callback();
|
|
199
162
|
}).apply(compiler);
|
|
200
|
-
}
|
|
163
|
+
}
|
|
164
|
+
if (options.externalsPresets.electron) {
|
|
165
|
+
if (options.externalsPresets.electronMain) {
|
|
166
|
+
// @ts-expect-error https://github.com/microsoft/TypeScript/issues/41697
|
|
167
|
+
const ElectronTargetPlugin = require("./electron/ElectronTargetPlugin");
|
|
168
|
+
|
|
169
|
+
new ElectronTargetPlugin("main").apply(compiler);
|
|
170
|
+
}
|
|
171
|
+
if (options.externalsPresets.electronPreload) {
|
|
172
|
+
// @ts-expect-error https://github.com/microsoft/TypeScript/issues/41697
|
|
173
|
+
const ElectronTargetPlugin = require("./electron/ElectronTargetPlugin");
|
|
174
|
+
|
|
175
|
+
new ElectronTargetPlugin("preload").apply(compiler);
|
|
176
|
+
}
|
|
177
|
+
if (options.externalsPresets.electronRenderer) {
|
|
178
|
+
// @ts-expect-error https://github.com/microsoft/TypeScript/issues/41697
|
|
179
|
+
const ElectronTargetPlugin = require("./electron/ElectronTargetPlugin");
|
|
180
|
+
|
|
181
|
+
new ElectronTargetPlugin("renderer").apply(compiler);
|
|
182
|
+
}
|
|
183
|
+
if (
|
|
184
|
+
!options.externalsPresets.electronMain &&
|
|
185
|
+
!options.externalsPresets.electronPreload &&
|
|
186
|
+
!options.externalsPresets.electronRenderer
|
|
187
|
+
) {
|
|
188
|
+
// @ts-expect-error https://github.com/microsoft/TypeScript/issues/41697
|
|
189
|
+
const ElectronTargetPlugin = require("./electron/ElectronTargetPlugin");
|
|
190
|
+
|
|
191
|
+
new ElectronTargetPlugin().apply(compiler);
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
if (options.externalsPresets.nwjs) {
|
|
201
195
|
// @ts-expect-error https://github.com/microsoft/TypeScript/issues/41697
|
|
202
196
|
const ExternalsPlugin = require("./ExternalsPlugin");
|
|
203
197
|
|
|
204
|
-
new ExternalsPlugin("
|
|
205
|
-
if (dependencyType === "url") {
|
|
206
|
-
if (/^(\/\/|https?:\/\/|#)/.test(/** @type {string} */ (request))) {
|
|
207
|
-
return callback(null, `asset ${request}`);
|
|
208
|
-
}
|
|
209
|
-
} else if (dependencyType === "css-import") {
|
|
210
|
-
if (/^(\/\/|https?:\/\/|#)/.test(/** @type {string} */ (request))) {
|
|
211
|
-
return callback(null, `css-import ${request}`);
|
|
212
|
-
}
|
|
213
|
-
} else if (
|
|
214
|
-
/^(\/\/|https?:\/\/|std:)/.test(/** @type {string} */ (request))
|
|
215
|
-
) {
|
|
216
|
-
if (/^\.css(\?|$)/.test(/** @type {string} */ (request))) {
|
|
217
|
-
return callback(null, `css-import ${request}`);
|
|
218
|
-
}
|
|
219
|
-
return callback(null, `module ${request}`);
|
|
220
|
-
}
|
|
221
|
-
callback();
|
|
222
|
-
}).apply(compiler);
|
|
198
|
+
new ExternalsPlugin("node-commonjs", "nw.gui").apply(compiler);
|
|
223
199
|
}
|
|
224
200
|
|
|
225
201
|
new ChunkPrefetchPreloadPlugin().apply(compiler);
|
|
@@ -446,11 +422,7 @@ class WebpackOptionsApply extends OptionsApply {
|
|
|
446
422
|
}
|
|
447
423
|
|
|
448
424
|
new EntryOptionPlugin().apply(compiler);
|
|
449
|
-
compiler.hooks.entryOption.call(
|
|
450
|
-
/** @type {string} */
|
|
451
|
-
(options.context),
|
|
452
|
-
options.entry
|
|
453
|
-
);
|
|
425
|
+
compiler.hooks.entryOption.call(options.context, options.entry);
|
|
454
426
|
|
|
455
427
|
new RuntimePlugin().apply(compiler);
|
|
456
428
|
|
|
@@ -461,7 +433,6 @@ class WebpackOptionsApply extends OptionsApply {
|
|
|
461
433
|
|
|
462
434
|
new CompatibilityPlugin().apply(compiler);
|
|
463
435
|
new HarmonyModulesPlugin({
|
|
464
|
-
topLevelAwait: options.experiments.topLevelAwait,
|
|
465
436
|
deferImport: options.experiments.deferImport
|
|
466
437
|
}).apply(compiler);
|
|
467
438
|
if (options.amd !== false) {
|
|
@@ -478,9 +449,7 @@ class WebpackOptionsApply extends OptionsApply {
|
|
|
478
449
|
|
|
479
450
|
new NodeStuffPlugin(options.node).apply(compiler);
|
|
480
451
|
}
|
|
481
|
-
new APIPlugin(
|
|
482
|
-
module: options.output.module
|
|
483
|
-
}).apply(compiler);
|
|
452
|
+
new APIPlugin().apply(compiler);
|
|
484
453
|
new ExportsInfoApiPlugin().apply(compiler);
|
|
485
454
|
new WebpackIsIncludedPlugin().apply(compiler);
|
|
486
455
|
new ConstPlugin().apply(compiler);
|
|
@@ -703,9 +672,7 @@ class WebpackOptionsApply extends OptionsApply {
|
|
|
703
672
|
}).apply(compiler);
|
|
704
673
|
}
|
|
705
674
|
if (options.optimization.minimize) {
|
|
706
|
-
for (const minimizer of
|
|
707
|
-
options.optimization.minimizer
|
|
708
|
-
)) {
|
|
675
|
+
for (const minimizer of options.optimization.minimizer) {
|
|
709
676
|
if (typeof minimizer === "function") {
|
|
710
677
|
/** @type {WebpackPluginFunction} */
|
|
711
678
|
(minimizer).call(compiler, compiler);
|
|
@@ -810,7 +777,7 @@ class WebpackOptionsApply extends OptionsApply {
|
|
|
810
777
|
fs:
|
|
811
778
|
/** @type {IntermediateFileSystem} */
|
|
812
779
|
(compiler.intermediateFileSystem),
|
|
813
|
-
context:
|
|
780
|
+
context: options.context,
|
|
814
781
|
cacheLocation:
|
|
815
782
|
/** @type {string} */
|
|
816
783
|
(cacheOptions.cacheLocation),
|
|
@@ -0,0 +1,167 @@
|
|
|
1
|
+
/*
|
|
2
|
+
MIT License http://www.opensource.org/licenses/mit-license.php
|
|
3
|
+
Author Alexander Akait @alexander-akait
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
"use strict";
|
|
7
|
+
|
|
8
|
+
const { RawSource } = require("webpack-sources");
|
|
9
|
+
const ConcatenationScope = require("../ConcatenationScope");
|
|
10
|
+
const Generator = require("../Generator");
|
|
11
|
+
const {
|
|
12
|
+
CSS_URL_TYPES,
|
|
13
|
+
JS_AND_CSS_URL_TYPES,
|
|
14
|
+
JS_TYPES,
|
|
15
|
+
NO_TYPES
|
|
16
|
+
} = require("../ModuleSourceTypesConstants");
|
|
17
|
+
const RuntimeGlobals = require("../RuntimeGlobals");
|
|
18
|
+
|
|
19
|
+
/** @typedef {import("webpack-sources").Source} Source */
|
|
20
|
+
/** @typedef {import("../Generator").GenerateContext} GenerateContext */
|
|
21
|
+
/** @typedef {import("../Module").ConcatenationBailoutReasonContext} ConcatenationBailoutReasonContext */
|
|
22
|
+
/** @typedef {import("../Module").SourceTypes} SourceTypes */
|
|
23
|
+
/** @typedef {import("../ModuleGraph")} ModuleGraph */
|
|
24
|
+
/** @typedef {import("../NormalModule")} NormalModule */
|
|
25
|
+
|
|
26
|
+
class AssetSourceGenerator extends Generator {
|
|
27
|
+
/**
|
|
28
|
+
* @param {ModuleGraph} moduleGraph the module graph
|
|
29
|
+
*/
|
|
30
|
+
constructor(moduleGraph) {
|
|
31
|
+
super();
|
|
32
|
+
|
|
33
|
+
this._moduleGraph = moduleGraph;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* @param {NormalModule} module module for which the code should be generated
|
|
38
|
+
* @param {GenerateContext} generateContext context for generate
|
|
39
|
+
* @returns {Source | null} generated code
|
|
40
|
+
*/
|
|
41
|
+
generate(
|
|
42
|
+
module,
|
|
43
|
+
{ type, concatenationScope, getData, runtimeTemplate, runtimeRequirements }
|
|
44
|
+
) {
|
|
45
|
+
const originalSource = module.originalSource();
|
|
46
|
+
const data = getData ? getData() : undefined;
|
|
47
|
+
|
|
48
|
+
switch (type) {
|
|
49
|
+
case "javascript": {
|
|
50
|
+
if (!originalSource) {
|
|
51
|
+
return new RawSource("");
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
const encodedSource = originalSource.buffer().toString("base64");
|
|
55
|
+
|
|
56
|
+
runtimeRequirements.add(RuntimeGlobals.requireScope);
|
|
57
|
+
runtimeRequirements.add(RuntimeGlobals.toBinary);
|
|
58
|
+
|
|
59
|
+
let sourceContent;
|
|
60
|
+
if (concatenationScope) {
|
|
61
|
+
concatenationScope.registerNamespaceExport(
|
|
62
|
+
ConcatenationScope.NAMESPACE_OBJECT_EXPORT
|
|
63
|
+
);
|
|
64
|
+
sourceContent = `${runtimeTemplate.renderConst()} ${
|
|
65
|
+
ConcatenationScope.NAMESPACE_OBJECT_EXPORT
|
|
66
|
+
} = ${RuntimeGlobals.toBinary}(${JSON.stringify(encodedSource)});`;
|
|
67
|
+
} else {
|
|
68
|
+
runtimeRequirements.add(RuntimeGlobals.module);
|
|
69
|
+
sourceContent = `${RuntimeGlobals.module}.exports = ${RuntimeGlobals.toBinary}(${JSON.stringify(
|
|
70
|
+
encodedSource
|
|
71
|
+
)});`;
|
|
72
|
+
}
|
|
73
|
+
return new RawSource(sourceContent);
|
|
74
|
+
}
|
|
75
|
+
case "css-url": {
|
|
76
|
+
if (!originalSource) {
|
|
77
|
+
return null;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
const encodedSource = originalSource.buffer().toString("base64");
|
|
81
|
+
|
|
82
|
+
if (data) {
|
|
83
|
+
data.set("url", {
|
|
84
|
+
[type]: `data:application/octet-stream;base64,${encodedSource}`
|
|
85
|
+
});
|
|
86
|
+
}
|
|
87
|
+
return null;
|
|
88
|
+
}
|
|
89
|
+
default:
|
|
90
|
+
return null;
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
/**
|
|
95
|
+
* @param {Error} error the error
|
|
96
|
+
* @param {NormalModule} module module for which the code should be generated
|
|
97
|
+
* @param {GenerateContext} generateContext context for generate
|
|
98
|
+
* @returns {Source | null} generated code
|
|
99
|
+
*/
|
|
100
|
+
generateError(error, module, generateContext) {
|
|
101
|
+
switch (generateContext.type) {
|
|
102
|
+
case "javascript": {
|
|
103
|
+
return new RawSource(
|
|
104
|
+
`throw new Error(${JSON.stringify(error.message)});`
|
|
105
|
+
);
|
|
106
|
+
}
|
|
107
|
+
default:
|
|
108
|
+
return null;
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
/**
|
|
113
|
+
* @param {NormalModule} module module for which the bailout reason should be determined
|
|
114
|
+
* @param {ConcatenationBailoutReasonContext} context context
|
|
115
|
+
* @returns {string | undefined} reason why this module can't be concatenated, undefined when it can be concatenated
|
|
116
|
+
*/
|
|
117
|
+
getConcatenationBailoutReason(module, context) {
|
|
118
|
+
return undefined;
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
/**
|
|
122
|
+
* @param {NormalModule} module fresh module
|
|
123
|
+
* @returns {SourceTypes} available types (do not mutate)
|
|
124
|
+
*/
|
|
125
|
+
getTypes(module) {
|
|
126
|
+
/** @type {Set<string>} */
|
|
127
|
+
const sourceTypes = new Set();
|
|
128
|
+
const connections = this._moduleGraph.getIncomingConnections(module);
|
|
129
|
+
|
|
130
|
+
for (const connection of connections) {
|
|
131
|
+
if (!connection.originModule) {
|
|
132
|
+
continue;
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
sourceTypes.add(connection.originModule.type.split("/")[0]);
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
if (sourceTypes.size > 0) {
|
|
139
|
+
if (sourceTypes.has("javascript") && sourceTypes.has("css")) {
|
|
140
|
+
return JS_AND_CSS_URL_TYPES;
|
|
141
|
+
} else if (sourceTypes.has("css")) {
|
|
142
|
+
return CSS_URL_TYPES;
|
|
143
|
+
}
|
|
144
|
+
return JS_TYPES;
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
return NO_TYPES;
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
/**
|
|
151
|
+
* @param {NormalModule} module the module
|
|
152
|
+
* @param {string=} type source type
|
|
153
|
+
* @returns {number} estimate size of the module
|
|
154
|
+
*/
|
|
155
|
+
getSize(module, type) {
|
|
156
|
+
const originalSource = module.originalSource();
|
|
157
|
+
|
|
158
|
+
if (!originalSource) {
|
|
159
|
+
return 0;
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
// Example: m.exports="abcd"
|
|
163
|
+
return originalSource.size() + 12;
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
module.exports = AssetSourceGenerator;
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
/*
|
|
2
|
+
MIT License http://www.opensource.org/licenses/mit-license.php
|
|
3
|
+
Author Alexander Akait @alexander-akait
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
"use strict";
|
|
7
|
+
|
|
8
|
+
const Parser = require("../Parser");
|
|
9
|
+
|
|
10
|
+
/** @typedef {import("../Module").BuildInfo} BuildInfo */
|
|
11
|
+
/** @typedef {import("../Module").BuildMeta} BuildMeta */
|
|
12
|
+
/** @typedef {import("../Parser").ParserState} ParserState */
|
|
13
|
+
/** @typedef {import("../Parser").PreparsedAst} PreparsedAst */
|
|
14
|
+
|
|
15
|
+
class AssetBytesParser extends Parser {
|
|
16
|
+
/**
|
|
17
|
+
* @param {string | Buffer | PreparsedAst} source the source to parse
|
|
18
|
+
* @param {ParserState} state the parser state
|
|
19
|
+
* @returns {ParserState} the parser state
|
|
20
|
+
*/
|
|
21
|
+
parse(source, state) {
|
|
22
|
+
if (typeof source === "object" && !Buffer.isBuffer(source)) {
|
|
23
|
+
throw new Error("AssetBytesParser doesn't accept preparsed AST");
|
|
24
|
+
}
|
|
25
|
+
const { module } = state;
|
|
26
|
+
/** @type {BuildInfo} */
|
|
27
|
+
(module.buildInfo).strict = true;
|
|
28
|
+
/** @type {BuildMeta} */
|
|
29
|
+
(module.buildMeta).exportsType = "default";
|
|
30
|
+
/** @type {BuildMeta} */
|
|
31
|
+
(state.module.buildMeta).defaultObject = false;
|
|
32
|
+
|
|
33
|
+
return state;
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
module.exports = AssetBytesParser;
|
|
@@ -6,7 +6,6 @@
|
|
|
6
6
|
"use strict";
|
|
7
7
|
|
|
8
8
|
const path = require("path");
|
|
9
|
-
const mimeTypes = require("mime-types");
|
|
10
9
|
const { RawSource } = require("webpack-sources");
|
|
11
10
|
const ConcatenationScope = require("../ConcatenationScope");
|
|
12
11
|
const Generator = require("../Generator");
|
|
@@ -25,41 +24,38 @@ const RuntimeGlobals = require("../RuntimeGlobals");
|
|
|
25
24
|
const CssUrlDependency = require("../dependencies/CssUrlDependency");
|
|
26
25
|
const createHash = require("../util/createHash");
|
|
27
26
|
const { makePathsRelative } = require("../util/identifier");
|
|
27
|
+
const memoize = require("../util/memoize");
|
|
28
28
|
const nonNumericOnlyHash = require("../util/nonNumericOnlyHash");
|
|
29
29
|
|
|
30
|
+
const getMimeTypes = memoize(() => require("mime-types"));
|
|
31
|
+
|
|
30
32
|
/** @typedef {import("webpack-sources").Source} Source */
|
|
31
33
|
/** @typedef {import("../../declarations/WebpackOptions").AssetGeneratorDataUrlOptions} AssetGeneratorDataUrlOptions */
|
|
32
34
|
/** @typedef {import("../../declarations/WebpackOptions").AssetGeneratorOptions} AssetGeneratorOptions */
|
|
33
35
|
/** @typedef {import("../../declarations/WebpackOptions").AssetModuleFilename} AssetModuleFilename */
|
|
34
36
|
/** @typedef {import("../../declarations/WebpackOptions").AssetModuleOutputPath} AssetModuleOutputPath */
|
|
35
37
|
/** @typedef {import("../../declarations/WebpackOptions").AssetResourceGeneratorOptions} AssetResourceGeneratorOptions */
|
|
36
|
-
/** @typedef {import("../../declarations/WebpackOptions").HashFunction} HashFunction */
|
|
37
38
|
/** @typedef {import("../../declarations/WebpackOptions").RawPublicPath} RawPublicPath */
|
|
38
39
|
/** @typedef {import("../ChunkGraph")} ChunkGraph */
|
|
39
|
-
/** @typedef {import("../Compilation")} Compilation */
|
|
40
40
|
/** @typedef {import("../Compilation").AssetInfo} AssetInfo */
|
|
41
|
-
/** @typedef {import("../Compilation").InterpolatedPathAndAssetInfo} InterpolatedPathAndAssetInfo */
|
|
42
|
-
/** @typedef {import("../Compiler")} Compiler */
|
|
43
41
|
/** @typedef {import("../Generator").GenerateContext} GenerateContext */
|
|
44
42
|
/** @typedef {import("../Generator").UpdateHashContext} UpdateHashContext */
|
|
45
|
-
/** @typedef {import("../Module")}
|
|
43
|
+
/** @typedef {import("../Module").NameForCondition} NameForCondition */
|
|
46
44
|
/** @typedef {import("../Module").BuildInfo} BuildInfo */
|
|
47
|
-
/** @typedef {import("../Module").BuildMeta} BuildMeta */
|
|
48
45
|
/** @typedef {import("../Module").ConcatenationBailoutReasonContext} ConcatenationBailoutReasonContext */
|
|
49
46
|
/** @typedef {import("../Module").SourceTypes} SourceTypes */
|
|
50
47
|
/** @typedef {import("../ModuleGraph")} ModuleGraph */
|
|
51
48
|
/** @typedef {import("../NormalModule")} NormalModule */
|
|
52
49
|
/** @typedef {import("../RuntimeTemplate")} RuntimeTemplate */
|
|
53
|
-
/** @typedef {import("../TemplatedPathPlugin").TemplatePath} TemplatePath */
|
|
54
50
|
/** @typedef {import("../util/Hash")} Hash */
|
|
55
51
|
/** @typedef {import("../util/runtime").RuntimeSpec} RuntimeSpec */
|
|
56
52
|
|
|
57
53
|
/**
|
|
58
54
|
* @template T
|
|
59
55
|
* @template U
|
|
60
|
-
* @param {null | string |
|
|
61
|
-
* @param {null | string |
|
|
62
|
-
* @returns {
|
|
56
|
+
* @param {null | string | T[] | Set<T> | undefined} a a
|
|
57
|
+
* @param {null | string | U[] | Set<U> | undefined} b b
|
|
58
|
+
* @returns {T[] & U[]} array
|
|
63
59
|
*/
|
|
64
60
|
const mergeMaybeArrays = (a, b) => {
|
|
65
61
|
const set = new Set();
|
|
@@ -220,7 +216,8 @@ class AssetGenerator extends Generator {
|
|
|
220
216
|
static getSourceFileName(module, runtimeTemplate) {
|
|
221
217
|
return makePathsRelative(
|
|
222
218
|
runtimeTemplate.compilation.compiler.context,
|
|
223
|
-
|
|
219
|
+
/** @type {string} */
|
|
220
|
+
(module.getResource()),
|
|
224
221
|
runtimeTemplate.compilation.compiler.root
|
|
225
222
|
).replace(/^\.\//, "");
|
|
226
223
|
}
|
|
@@ -231,10 +228,7 @@ class AssetGenerator extends Generator {
|
|
|
231
228
|
* @returns {[string, string]} return full hash and non-numeric full hash
|
|
232
229
|
*/
|
|
233
230
|
static getFullContentHash(module, runtimeTemplate) {
|
|
234
|
-
const hash = createHash(
|
|
235
|
-
/** @type {HashFunction} */
|
|
236
|
-
(runtimeTemplate.outputOptions.hashFunction)
|
|
237
|
-
);
|
|
231
|
+
const hash = createHash(runtimeTemplate.outputOptions.hashFunction);
|
|
238
232
|
|
|
239
233
|
if (runtimeTemplate.outputOptions.hashSalt) {
|
|
240
234
|
hash.update(runtimeTemplate.outputOptions.hashSalt);
|
|
@@ -250,15 +244,13 @@ class AssetGenerator extends Generator {
|
|
|
250
244
|
hash.update(module.error.toString());
|
|
251
245
|
}
|
|
252
246
|
|
|
253
|
-
const fullContentHash =
|
|
254
|
-
|
|
247
|
+
const fullContentHash = hash.digest(
|
|
248
|
+
runtimeTemplate.outputOptions.hashDigest
|
|
255
249
|
);
|
|
256
250
|
|
|
257
|
-
/** @type {string} */
|
|
258
251
|
const contentHash = nonNumericOnlyHash(
|
|
259
252
|
fullContentHash,
|
|
260
|
-
|
|
261
|
-
(runtimeTemplate.outputOptions.hashDigestLength)
|
|
253
|
+
runtimeTemplate.outputOptions.hashDigestLength
|
|
262
254
|
);
|
|
263
255
|
|
|
264
256
|
return [fullContentHash, contentHash];
|
|
@@ -279,8 +271,7 @@ class AssetGenerator extends Generator {
|
|
|
279
271
|
) {
|
|
280
272
|
const assetModuleFilename =
|
|
281
273
|
generatorOptions.filename ||
|
|
282
|
-
|
|
283
|
-
(runtimeTemplate.outputOptions.assetModuleFilename);
|
|
274
|
+
runtimeTemplate.outputOptions.assetModuleFilename;
|
|
284
275
|
|
|
285
276
|
const sourceFilename = AssetGenerator.getSourceFileName(
|
|
286
277
|
module,
|
|
@@ -381,13 +372,9 @@ class AssetGenerator extends Generator {
|
|
|
381
372
|
const path =
|
|
382
373
|
compilation.outputOptions.publicPath === "auto"
|
|
383
374
|
? CssUrlDependency.PUBLIC_PATH_AUTO
|
|
384
|
-
: compilation.getAssetPath(
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
{
|
|
388
|
-
hash: compilation.hash
|
|
389
|
-
}
|
|
390
|
-
);
|
|
375
|
+
: compilation.getAssetPath(compilation.outputOptions.publicPath, {
|
|
376
|
+
hash: compilation.hash
|
|
377
|
+
});
|
|
391
378
|
|
|
392
379
|
assetPath = path + filename;
|
|
393
380
|
}
|
|
@@ -425,7 +412,7 @@ class AssetGenerator extends Generator {
|
|
|
425
412
|
(this.dataUrlOptions).mimetype;
|
|
426
413
|
if (mimeType === undefined) {
|
|
427
414
|
const ext = path.extname(
|
|
428
|
-
/** @type {
|
|
415
|
+
/** @type {NameForCondition} */
|
|
429
416
|
(module.nameForCondition())
|
|
430
417
|
);
|
|
431
418
|
if (
|
|
@@ -436,7 +423,7 @@ class AssetGenerator extends Generator {
|
|
|
436
423
|
module.resourceResolveData.mimetype +
|
|
437
424
|
module.resourceResolveData.parameters;
|
|
438
425
|
} else if (ext) {
|
|
439
|
-
mimeType =
|
|
426
|
+
mimeType = getMimeTypes().lookup(ext);
|
|
440
427
|
|
|
441
428
|
if (typeof mimeType !== "string") {
|
|
442
429
|
throw new Error(
|
|
@@ -471,7 +458,7 @@ class AssetGenerator extends Generator {
|
|
|
471
458
|
|
|
472
459
|
if (typeof this.dataUrlOptions === "function") {
|
|
473
460
|
encodedSource = this.dataUrlOptions.call(null, source.source(), {
|
|
474
|
-
filename:
|
|
461
|
+
filename: /** @type {string} */ (module.getResource()),
|
|
475
462
|
module
|
|
476
463
|
});
|
|
477
464
|
} else {
|
|
@@ -619,7 +606,7 @@ class AssetGenerator extends Generator {
|
|
|
619
606
|
);
|
|
620
607
|
|
|
621
608
|
return new RawSource(
|
|
622
|
-
`${runtimeTemplate.
|
|
609
|
+
`${runtimeTemplate.renderConst()} ${
|
|
623
610
|
ConcatenationScope.NAMESPACE_OBJECT_EXPORT
|
|
624
611
|
} = ${content};`
|
|
625
612
|
);
|
|
@@ -794,9 +781,7 @@ class AssetGenerator extends Generator {
|
|
|
794
781
|
}
|
|
795
782
|
|
|
796
783
|
const assetModuleFilename =
|
|
797
|
-
this.filename ||
|
|
798
|
-
/** @type {AssetModuleFilename} */
|
|
799
|
-
(runtimeTemplate.outputOptions.assetModuleFilename);
|
|
784
|
+
this.filename || runtimeTemplate.outputOptions.assetModuleFilename;
|
|
800
785
|
const { path: filename, info } =
|
|
801
786
|
runtimeTemplate.compilation.getAssetPathWithInfo(
|
|
802
787
|
assetModuleFilename,
|