@depup/webpack 5.109.0-depup.0 → 5.110.1-depup.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 +7 -7
- package/bin/webpack.js +12 -0
- package/changes.json +10 -10
- package/lib/APIPlugin.js +123 -17
- package/lib/AsyncDependenciesBlock.js +10 -7
- package/lib/AutomaticPrefetchPlugin.js +1 -1
- package/lib/BannerPlugin.js +10 -6
- package/lib/CacheFacade.js +6 -6
- package/lib/Chunk.js +14 -11
- package/lib/ChunkGraph.js +43 -32
- package/lib/ChunkGroup.js +7 -7
- package/lib/ChunkTemplate.js +35 -44
- package/lib/CircularModulesPlugin.js +205 -28
- package/lib/CleanPlugin.js +15 -16
- package/lib/CodeGenerationResults.js +11 -8
- package/lib/CompatibilityPlugin.js +38 -7
- package/lib/Compilation.js +709 -414
- package/lib/Compiler.js +69 -42
- package/lib/ConcatenationScope.js +117 -8
- package/lib/ConditionalInitFragment.js +3 -3
- package/lib/ConstPlugin.js +13 -11
- package/lib/ContextExclusionPlugin.js +1 -1
- package/lib/ContextModule.js +146 -54
- package/lib/ContextModuleFactory.js +46 -14
- package/lib/ContextReplacementPlugin.js +12 -14
- package/lib/DefinePlugin.js +168 -57
- package/lib/DependenciesBlock.js +9 -6
- package/lib/Dependency.js +36 -16
- package/lib/DependencyTemplate.js +11 -12
- package/lib/DependencyTemplates.js +3 -3
- package/lib/DotenvPlugin.js +50 -13
- package/lib/DynamicEntryPlugin.js +8 -4
- package/lib/EntryOptionPlugin.js +8 -4
- package/lib/EntryPlugin.js +2 -2
- package/lib/Entrypoint.js +6 -2
- package/lib/EnvironmentPlugin.js +2 -2
- package/lib/EvalDevToolModulePlugin.js +8 -4
- package/lib/EvalSourceMapDevToolPlugin.js +15 -8
- package/lib/ExportsInfo.js +123 -19
- package/lib/ExportsInfoApiPlugin.js +2 -4
- package/lib/ExternalModule.js +242 -84
- package/lib/ExternalModuleFactoryPlugin.js +97 -38
- package/lib/ExternalsPlugin.js +10 -6
- package/lib/FileSystemInfo.js +116 -42
- package/lib/FlagAllModulesAsUsedPlugin.js +2 -3
- package/lib/FlagDependencyExportsPlugin.js +76 -19
- package/lib/FlagDependencyUsagePlugin.js +63 -57
- package/lib/FlagEntryExportAsUsedPlugin.js +1 -1
- package/lib/Generator.js +36 -15
- package/lib/HotModuleReplacementPlugin.js +16 -44
- package/lib/IgnorePlugin.js +8 -4
- package/lib/IgnoreWarningsPlugin.js +2 -2
- package/lib/InitFragment.js +28 -36
- package/lib/JavascriptMetaInfoPlugin.js +35 -4
- package/lib/LazyBarrel.js +3 -4
- package/lib/LibraryTemplatePlugin.js +10 -6
- package/lib/LoaderOptionsPlugin.js +7 -3
- package/lib/LoaderTargetPlugin.js +1 -1
- package/lib/MainTemplate.js +49 -42
- package/lib/ManifestPlugin.js +12 -11
- package/lib/Module.js +62 -33
- package/lib/ModuleFactory.js +3 -3
- package/lib/ModuleFilenameHelpers.js +22 -6
- package/lib/ModuleGraph.js +195 -21
- package/lib/ModuleGraphConnection.js +6 -13
- package/lib/ModuleInfoHeaderPlugin.js +8 -10
- package/lib/ModuleTemplate.js +62 -63
- package/lib/MultiCompiler.js +130 -64
- package/lib/MultiStats.js +40 -9
- package/lib/MultiWatching.js +3 -3
- package/lib/NoEmitOnErrorsPlugin.js +1 -1
- package/lib/NodeStuffPlugin.js +29 -19
- package/lib/NormalModule.js +221 -156
- package/lib/NormalModuleFactory.js +563 -112
- package/lib/NormalModuleReplacementPlugin.js +5 -8
- package/lib/NullFactory.js +6 -2
- package/lib/OptionsApply.js +7 -3
- package/lib/Parser.js +7 -3
- package/lib/PlatformPlugin.js +2 -2
- package/lib/PrefetchPlugin.js +1 -1
- package/lib/ProgressPlugin.js +16 -13
- package/lib/ProvidePlugin.js +3 -5
- package/lib/RawModule.js +25 -17
- package/lib/RecordIdsPlugin.js +3 -3
- package/lib/RequestShortener.js +1 -1
- package/lib/ResolverFactory.js +2 -2
- package/lib/RuntimeGlobals.js +22 -10
- package/lib/RuntimeModule.js +29 -19
- package/lib/RuntimePlugin.js +346 -256
- package/lib/RuntimeTemplate.js +2792 -352
- package/lib/SelfModuleFactory.js +7 -3
- package/lib/SourceMapDevToolModuleOptionsPlugin.js +6 -2
- package/lib/SourceMapDevToolPlugin.js +30 -20
- package/lib/Stats.js +3 -4
- package/lib/Template.js +55 -25
- package/lib/TemplatedPathPlugin.js +96 -14
- package/lib/UseStrictPlugin.js +4 -6
- package/lib/WarnCaseSensitiveModulesPlugin.js +4 -4
- package/lib/WarnDeprecatedOptionPlugin.js +1 -1
- package/lib/WarnNoModeSetPlugin.js +1 -1
- package/lib/WatchIgnorePlugin.js +8 -6
- package/lib/Watching.js +8 -8
- package/lib/WebpackIsIncludedPlugin.js +2 -4
- package/lib/WebpackOptionsApply.js +308 -18
- package/lib/WebpackOptionsDefaulter.js +6 -2
- package/lib/asset/AssetBytesGenerator.js +12 -10
- package/lib/asset/AssetBytesParser.js +2 -4
- package/lib/asset/AssetGenerator.js +188 -95
- package/lib/asset/AssetModule.js +7 -3
- package/lib/asset/AssetModulesPlugin.js +110 -38
- package/lib/asset/AssetParser.js +9 -7
- package/lib/asset/AssetSourceGenerator.js +60 -13
- package/lib/asset/AssetSourceParser.js +2 -4
- package/lib/asset/RawDataUrlModule.js +24 -16
- package/lib/asset/WebManifestGenerator.js +8 -10
- package/lib/asset/WebManifestParser.js +24 -10
- package/lib/async-modules/AsyncModuleHelpers.js +2 -2
- package/lib/async-modules/AwaitDependenciesInitFragment.js +2 -2
- package/lib/async-modules/InferAsyncModulesPlugin.js +2 -2
- package/lib/async-modules/isGeneratorLowered.js +4 -4
- package/lib/buildChunkGraph.js +36 -27
- package/lib/bun/BunTargetPlugin.js +1 -1
- package/lib/cache/AddBuildDependenciesPlugin.js +1 -1
- package/lib/cache/AddManagedPathsPlugin.js +1 -1
- package/lib/cache/IdleFileCachePlugin.js +2 -2
- package/lib/cache/MemoryCachePlugin.js +18 -10
- package/lib/cache/MemoryWithGcCachePlugin.js +34 -22
- package/lib/cache/PackFileCacheStrategy.js +289 -28
- package/lib/cache/ResolverCachePlugin.js +38 -18
- package/lib/cache/getLazyHashedEtag.js +1 -2
- package/lib/cache/mergeEtags.js +1 -1
- package/lib/cli.js +1 -3
- package/lib/config/browserslistTargetHandler.js +41 -5
- package/lib/config/defaults.js +282 -81
- package/lib/config/defineConfig.js +10 -2
- package/lib/config/getClaimedAssetTypes.js +65 -0
- package/lib/config/normalization.js +36 -16
- package/lib/config/target.js +46 -3
- package/lib/container/ContainerEntryDependency.js +1 -1
- package/lib/container/ContainerEntryModule.js +24 -15
- package/lib/container/ContainerEntryModuleFactory.js +7 -3
- package/lib/container/ContainerPlugin.js +9 -10
- package/lib/container/ContainerReferencePlugin.js +6 -2
- package/lib/container/FallbackDependency.js +1 -1
- package/lib/container/FallbackModule.js +24 -17
- package/lib/container/FallbackModuleFactory.js +7 -3
- package/lib/container/HoistContainerReferencesPlugin.js +53 -66
- package/lib/container/ModuleFederationPlugin.js +7 -18
- package/lib/container/RemoteModule.js +27 -19
- package/lib/container/RemoteRuntimeModule.js +10 -8
- package/lib/container/moduleFederationHooks.js +32 -0
- package/lib/css/CssGenerator.js +178 -44
- package/lib/css/CssInjectStyleRuntimeModule.js +7 -5
- package/lib/css/CssLoadingRuntimeModule.js +82 -36
- package/lib/css/CssModule.js +10 -7
- package/lib/css/CssModulesPlugin.js +197 -106
- package/lib/css/CssParser.js +1248 -618
- package/lib/css/CssServerStylesRuntimeModule.js +54 -0
- package/lib/css/cssMinify.js +168 -0
- package/lib/css/data.js +5324 -0
- package/lib/css/syntax.js +10396 -952
- package/lib/debug/ProfilingPlugin.js +14 -9
- package/lib/deno/DenoTargetPlugin.js +1 -1
- package/lib/dependencies/AMDDefineDependency.js +112 -87
- package/lib/dependencies/AMDDefineDependencyParserPlugin.js +30 -17
- package/lib/dependencies/AMDPlugin.js +9 -7
- package/lib/dependencies/AMDRequireArrayDependency.js +5 -5
- package/lib/dependencies/AMDRequireContextDependency.js +2 -2
- package/lib/dependencies/AMDRequireDependenciesBlock.js +1 -1
- package/lib/dependencies/AMDRequireDependenciesBlockParserPlugin.js +25 -14
- package/lib/dependencies/AMDRequireDependency.js +8 -7
- package/lib/dependencies/AMDRequireItemDependency.js +1 -1
- package/lib/dependencies/AMDRuntimeModules.js +21 -1
- package/lib/dependencies/BuildTimeConstDependency.js +102 -0
- package/lib/dependencies/CachedConstDependency.js +11 -8
- package/lib/dependencies/CommonJsDependencyHelpers.js +67 -46
- package/lib/dependencies/CommonJsExportRequireDependency.js +140 -45
- package/lib/dependencies/CommonJsExportsDependency.js +53 -49
- package/lib/dependencies/CommonJsExportsParserPlugin.js +207 -25
- package/lib/dependencies/CommonJsFullRequireDependency.js +140 -26
- package/lib/dependencies/CommonJsImportsParserPlugin.js +100 -48
- package/lib/dependencies/CommonJsObjectExportDependency.js +188 -0
- package/lib/dependencies/CommonJsPlugin.js +35 -6
- package/lib/dependencies/CommonJsRequireContextDependency.js +5 -6
- package/lib/dependencies/CommonJsRequireDependency.js +156 -27
- package/lib/dependencies/CommonJsSelfReferenceDependency.js +63 -38
- package/lib/dependencies/ConstDependency.js +8 -9
- package/lib/dependencies/ContextDependency.js +12 -8
- package/lib/dependencies/ContextDependencyHelpers.js +14 -9
- package/lib/dependencies/ContextDependencyTemplateAsId.js +4 -4
- package/lib/dependencies/ContextDependencyTemplateAsRequireCall.js +4 -4
- package/lib/dependencies/ContextElementDependency.js +31 -12
- package/lib/dependencies/CreateRequireParserPlugin.js +12 -7
- package/lib/dependencies/CreateScriptUrlDependency.js +4 -4
- package/lib/dependencies/CssIcssExportDependency.js +56 -28
- package/lib/dependencies/CssIcssImportDependency.js +17 -13
- package/lib/dependencies/CssIcssSymbolDependency.js +9 -10
- package/lib/dependencies/CssImportDependency.js +18 -9
- package/lib/dependencies/CssUrlDependency.js +17 -13
- package/lib/dependencies/DllEntryDependency.js +1 -1
- package/lib/dependencies/DynamicExports.js +2 -2
- package/lib/dependencies/ExportBindingInitFragment.js +36 -9
- package/lib/dependencies/ExportsInfoDependency.js +7 -8
- package/lib/dependencies/ExternalModuleDependency.js +9 -5
- package/lib/dependencies/ExternalModuleInitFragment.js +2 -2
- package/lib/dependencies/ExternalModuleInitFragmentDependency.js +8 -5
- package/lib/dependencies/HarmonyAcceptDependency.js +5 -5
- package/lib/dependencies/HarmonyCompatibilityDependency.js +52 -17
- package/lib/dependencies/HarmonyDetectionParserPlugin.js +11 -7
- package/lib/dependencies/HarmonyEvaluatedImportSpecifierDependency.js +15 -11
- package/lib/dependencies/HarmonyExportDependencyParserPlugin.js +78 -12
- package/lib/dependencies/HarmonyExportExpressionDependency.js +23 -18
- package/lib/dependencies/HarmonyExportHeaderDependency.js +7 -7
- package/lib/dependencies/HarmonyExportImportedSpecifierDependency.js +159 -71
- package/lib/dependencies/HarmonyExportInitFragment.js +18 -6
- package/lib/dependencies/HarmonyExportSpecifierDependency.js +51 -14
- package/lib/dependencies/HarmonyExports.js +7 -4
- package/lib/dependencies/HarmonyImportDependency.js +28 -20
- package/lib/dependencies/HarmonyImportDependencyParserPlugin.js +31 -24
- package/lib/dependencies/HarmonyImportGuard.js +21 -30
- package/lib/dependencies/HarmonyImportSideEffectDependency.js +38 -9
- package/lib/dependencies/HarmonyImportSpecifierDependency.js +106 -55
- package/lib/dependencies/HarmonyModulesPlugin.js +7 -3
- package/lib/dependencies/HarmonyTopLevelThisParserPlugin.js +1 -3
- package/lib/dependencies/HtmlEntryDependency.js +37 -29
- package/lib/dependencies/HtmlInlineHtmlDependency.js +7 -8
- package/lib/dependencies/HtmlInlineScriptDependency.js +11 -8
- package/lib/dependencies/HtmlInlineStyleDependency.js +7 -10
- package/lib/dependencies/HtmlSourceDependency.js +22 -14
- package/lib/dependencies/ImportContextDependency.js +2 -2
- package/lib/dependencies/ImportDependency.js +24 -20
- package/lib/dependencies/ImportEagerDependency.js +6 -9
- package/lib/dependencies/ImportMetaContextDependency.js +2 -2
- package/lib/dependencies/ImportMetaContextDependencyParserPlugin.js +14 -13
- package/lib/dependencies/ImportMetaContextPlugin.js +7 -3
- package/lib/dependencies/ImportMetaGlobDependency.js +2 -2
- package/lib/dependencies/ImportMetaGlobDependencyParserPlugin.js +2 -3
- package/lib/dependencies/ImportMetaGlobHelpers.js +19 -22
- package/lib/dependencies/ImportMetaHotAcceptDependency.js +1 -1
- package/lib/dependencies/ImportMetaHotDeclineDependency.js +1 -1
- package/lib/dependencies/ImportMetaPlugin.js +154 -71
- package/lib/dependencies/ImportMetaResolveDependency.js +3 -4
- package/lib/dependencies/ImportParserPlugin.js +49 -35
- package/lib/dependencies/ImportPhase.js +12 -5
- package/lib/dependencies/ImportPlugin.js +7 -3
- package/lib/dependencies/ImportWeakDependency.js +6 -9
- package/lib/dependencies/JsonExportsDependency.js +11 -7
- package/lib/dependencies/LoaderDependency.js +2 -2
- package/lib/dependencies/LoaderImportDependency.js +2 -2
- package/lib/dependencies/LoaderPlugin.js +11 -7
- package/lib/dependencies/LocalModuleDependency.js +5 -5
- package/lib/dependencies/LocalModulesHelpers.js +1 -1
- package/lib/dependencies/ModuleDecoratorDependency.js +6 -7
- package/lib/dependencies/ModuleDependency.js +9 -6
- package/lib/dependencies/ModuleDependencyTemplateAsId.js +4 -4
- package/lib/dependencies/ModuleDependencyTemplateAsRequireId.js +3 -3
- package/lib/dependencies/ModuleHotAcceptDependency.js +1 -1
- package/lib/dependencies/ModuleHotDeclineDependency.js +1 -1
- package/lib/dependencies/ModuleInitFragmentDependency.js +24 -10
- package/lib/dependencies/NullDependency.js +3 -3
- package/lib/dependencies/ProvidedDependency.js +14 -10
- package/lib/dependencies/PureExpressionDependency.js +9 -10
- package/lib/dependencies/RequireContextDependency.js +2 -2
- package/lib/dependencies/RequireContextDependencyParserPlugin.js +2 -4
- package/lib/dependencies/RequireContextPlugin.js +8 -4
- package/lib/dependencies/RequireEnsureDependenciesBlock.js +2 -2
- package/lib/dependencies/RequireEnsureDependenciesBlockParserPlugin.js +5 -8
- package/lib/dependencies/RequireEnsureDependency.js +8 -7
- package/lib/dependencies/RequireEnsurePlugin.js +7 -3
- package/lib/dependencies/RequireHeaderDependency.js +51 -12
- package/lib/dependencies/RequireIncludeDependency.js +6 -6
- package/lib/dependencies/RequireIncludeDependencyParserPlugin.js +2 -3
- package/lib/dependencies/RequireIncludePlugin.js +7 -3
- package/lib/dependencies/RequireJsStuffPlugin.js +7 -3
- package/lib/dependencies/RequireResolveContextDependency.js +2 -2
- package/lib/dependencies/RequireResolveDependency.js +4 -4
- package/lib/dependencies/RequireResolveHeaderDependency.js +4 -4
- package/lib/dependencies/RuntimeRequirementsDependency.js +5 -6
- package/lib/dependencies/StaticExportsDependency.js +2 -2
- package/lib/dependencies/SystemPlugin.js +10 -6
- package/lib/dependencies/SystemRuntimeModule.js +10 -0
- package/lib/dependencies/TopLevelAwaitDependency.js +11 -7
- package/lib/dependencies/URLContextDependency.js +2 -2
- package/lib/dependencies/URLDependency.js +110 -64
- package/lib/dependencies/URLPlugin.js +7 -3
- package/lib/dependencies/UnsupportedDependency.js +4 -4
- package/lib/dependencies/WebAssemblyExportImportedDependency.js +3 -4
- package/lib/dependencies/WebAssemblyImportDependency.js +5 -5
- package/lib/dependencies/WebpackIsIncludedDependency.js +6 -6
- package/lib/dependencies/WorkerAndWorkletPlugin.js +46 -28
- package/lib/dependencies/WorkerDependency.js +28 -22
- package/lib/dependencies/WorkletDependency.js +15 -14
- package/lib/dependencies/getFunctionExpression.js +8 -4
- package/lib/dependencies/processExportInfo.js +5 -5
- package/lib/dll/DelegatedModule.js +34 -22
- package/lib/dll/DelegatedModuleFactoryPlugin.js +15 -7
- package/lib/dll/DelegatedPlugin.js +2 -2
- package/lib/dll/DllEntryPlugin.js +2 -2
- package/lib/dll/DllModule.js +22 -15
- package/lib/dll/DllModuleFactory.js +7 -3
- package/lib/dll/DllPlugin.js +7 -5
- package/lib/dll/DllReferencePlugin.js +10 -7
- package/lib/dll/LibManifestPlugin.js +5 -5
- package/lib/electron/ElectronTargetPlugin.js +53 -49
- package/lib/errors/AsyncChunkWaterfallWarning.js +36 -0
- package/lib/errors/AsyncDependencyToInitialChunkError.js +2 -2
- package/lib/errors/BroadContextsWarning.js +43 -0
- package/lib/errors/BuildCycleError.js +1 -1
- package/lib/errors/CacheEffectivenessWarning.js +55 -0
- package/lib/errors/ChunkRenderError.js +1 -1
- package/lib/errors/CircularDependenciesWarning.js +38 -0
- package/lib/errors/CodeGenerationError.js +1 -1
- package/lib/errors/CommentCompilationWarning.js +1 -1
- package/lib/errors/ConflictingResourceHintsWarning.js +35 -0
- package/lib/errors/DuplicateModulesWarning.js +45 -0
- package/lib/errors/DynamicExportsWarning.js +30 -0
- package/lib/errors/EmbeddedSourceMapsWarning.js +25 -0
- package/lib/errors/EntrypointOverlapWarning.js +45 -0
- package/lib/errors/EnvironmentNotSupportAsyncWarning.js +2 -2
- package/lib/errors/EvalUsageWarning.js +28 -0
- package/lib/errors/HookWebpackError.js +5 -5
- package/lib/errors/HotspotsWarning.js +57 -0
- package/lib/errors/IgnoreErrorModuleFactory.js +7 -3
- package/lib/errors/InlinedAssetsWarning.js +36 -0
- package/lib/errors/InvalidDependenciesModuleWarning.js +1 -1
- package/lib/errors/LargeModulesWarning.js +45 -0
- package/lib/errors/LegacyJavascriptWarning.js +48 -0
- package/lib/errors/MissingSideEffectsWarning.js +36 -0
- package/lib/errors/MixedExportsWarning.js +41 -0
- package/lib/errors/ModuleDependencyError.js +13 -16
- package/lib/errors/ModuleDependencyWarning.js +5 -15
- package/lib/errors/ModuleHashingError.js +1 -1
- package/lib/errors/ModuleNotFoundError.js +2 -2
- package/lib/errors/ModuleParseError.js +1 -2
- package/lib/errors/ModuleRestoreError.js +1 -1
- package/lib/errors/ModuleStoreError.js +1 -1
- package/lib/errors/NodeStuffInWebError.js +1 -1
- package/lib/errors/OsDependentRuleWarning.js +31 -0
- package/lib/errors/PureAnnotationsWarning.js +36 -0
- package/lib/errors/RedundantDynamicImportWarning.js +31 -0
- package/lib/errors/ScopeHoistingBailoutsWarning.js +41 -0
- package/lib/errors/SplitChunksCappedWarning.js +41 -0
- package/lib/errors/TinyChunksWarning.js +40 -0
- package/lib/errors/TopLevelThisWarning.js +34 -0
- package/lib/errors/UnsplitVendorsWarning.js +42 -0
- package/lib/errors/UnsupportedFeatureWarning.js +1 -1
- package/lib/errors/UnusedAliasesWarning.js +29 -0
- package/lib/errors/UnusedDefinesWarning.js +29 -0
- package/lib/errors/UnusedExternalsWarning.js +29 -0
- package/lib/errors/UnusedReexportsWarning.js +42 -0
- package/lib/errors/UnusedRuleWarning.js +29 -0
- package/lib/errors/WebpackError.js +9 -5
- package/lib/errors/deriveStackFromNestedError.js +90 -0
- package/lib/esm/ExportWebpackRequireRuntimeModule.js +2 -0
- package/lib/esm/ModuleChunkFormatPlugin.js +37 -19
- package/lib/esm/ModuleChunkLoadingPlugin.js +89 -51
- package/lib/esm/ModuleChunkLoadingRuntimeModule.js +170 -71
- package/lib/hmr/HotModuleReplacement.runtime.js +24 -5
- package/lib/hmr/HotModuleReplacementRuntimeModule.js +1 -1
- package/lib/hmr/LazyCompilationPlugin.js +45 -24
- package/lib/hmr/lazyCompilationBackend.js +28 -10
- package/lib/hmr/parserHooks.js +56 -0
- package/lib/html/HtmlGenerator.js +299 -79
- package/lib/html/HtmlModule.js +7 -3
- package/lib/html/HtmlModulesPlugin.js +312 -174
- package/lib/html/HtmlParser.js +31 -86
- package/lib/html/data.js +1928 -0
- package/lib/html/htmlMinify.js +288 -0
- package/lib/html/syntax.js +7819 -3331
- package/lib/ids/ChunkModuleIdRangePlugin.js +3 -3
- package/lib/ids/DeterministicChunkIdsPlugin.js +1 -1
- package/lib/ids/DeterministicModuleIdsPlugin.js +2 -2
- package/lib/ids/HashedModuleIdsPlugin.js +6 -2
- package/lib/ids/IdHelpers.js +31 -18
- package/lib/ids/NamedChunkIdsPlugin.js +1 -1
- package/lib/ids/NamedModuleIdsPlugin.js +1 -1
- package/lib/ids/NaturalChunkIdsPlugin.js +2 -2
- package/lib/ids/NaturalModuleIdsPlugin.js +1 -1
- package/lib/ids/OccurrenceChunkIdsPlugin.js +7 -3
- package/lib/ids/OccurrenceModuleIdsPlugin.js +7 -3
- package/lib/ids/SyncModuleIdsPlugin.js +4 -4
- package/lib/index.js +10 -0
- package/lib/javascript/ArrayPushCallbackChunkFormatPlugin.js +3 -3
- package/lib/javascript/BasicEvaluatedExpression.js +18 -14
- package/lib/javascript/ChunkFormatHelpers.js +6 -6
- package/lib/javascript/ChunkHelpers.js +1 -1
- package/lib/javascript/CommonJsChunkFormatPlugin.js +11 -5
- package/lib/javascript/EnableChunkLoadingPlugin.js +2 -2
- package/lib/javascript/JavascriptGenerator.js +65 -165
- package/lib/javascript/JavascriptModule.js +9 -3
- package/lib/javascript/JavascriptModulesPlugin.js +181 -162
- package/lib/javascript/JavascriptParser.js +291 -112
- package/lib/javascript/JavascriptParserHelpers.js +10 -7
- package/lib/javascript/ScopeAnalyzer.js +1094 -0
- package/lib/javascript/StartupHelpers.js +55 -9
- package/lib/javascript/syntax.js +3403 -300
- package/lib/json/JsonData.js +8 -4
- package/lib/json/JsonGenerator.js +38 -16
- package/lib/json/JsonModule.js +7 -3
- package/lib/json/JsonModulesPlugin.js +1 -1
- package/lib/json/JsonParser.js +5 -6
- package/lib/library/AbstractLibraryPlugin.js +20 -14
- package/lib/library/AmdLibraryPlugin.js +11 -7
- package/lib/library/AssignLibraryPlugin.js +19 -13
- package/lib/library/EnableLibraryPlugin.js +2 -2
- package/lib/library/ExportPropertyLibraryPlugin.js +15 -8
- package/lib/library/JsonpLibraryPlugin.js +11 -7
- package/lib/library/ModuleLibraryPlugin.js +256 -64
- package/lib/library/SystemLibraryPlugin.js +12 -8
- package/lib/library/UmdLibraryPlugin.js +62 -25
- package/lib/loaders/LoaderRunner.js +14 -1
- package/lib/loaders/loadLoader.js +8 -4
- package/lib/logging/createConsoleLogger.js +7 -4
- package/lib/node/CommonJsChunkLoadingPlugin.js +36 -22
- package/lib/node/NodeEnvironmentPlugin.js +17 -3
- package/lib/node/NodeSourcePlugin.js +1 -1
- package/lib/node/NodeTargetPlugin.js +4 -3
- package/lib/node/NodeTemplatePlugin.js +1 -1
- package/lib/node/NodeWatchFileSystem.js +70 -9
- package/lib/node/ReadFileChunkLoadingRuntimeModule.js +35 -38
- package/lib/node/ReadFileCompileAsyncWasmPlugin.js +81 -20
- package/lib/node/ReadFileCompileWasmPlugin.js +37 -17
- package/lib/node/RequireChunkLoadingRuntimeModule.js +35 -38
- package/lib/node/nodeConsole.js +7 -3
- package/lib/optimize/AggressiveMergingPlugin.js +21 -17
- package/lib/optimize/AggressiveSplittingPlugin.js +9 -6
- package/lib/optimize/ConcatenatedModule.js +996 -477
- package/lib/optimize/ConstExportsPlugin.js +11 -7
- package/lib/optimize/EnsureChunkConditionsPlugin.js +3 -3
- package/lib/optimize/FlagIncludedChunksPlugin.js +3 -4
- package/lib/optimize/InlineExports.js +9 -5
- package/lib/optimize/InnerGraph.js +28 -12
- package/lib/optimize/InnerGraphPlugin.js +23 -18
- package/lib/optimize/LimitChunkCountPlugin.js +7 -3
- package/lib/optimize/MangleExportsPlugin.js +7 -8
- package/lib/optimize/MergeDuplicateChunksPlugin.js +7 -3
- package/lib/optimize/MinChunkSizePlugin.js +7 -3
- package/lib/optimize/ModuleConcatenationPlugin.js +124 -59
- package/lib/optimize/RealContentHashPlugin.js +20 -13
- package/lib/optimize/RemoveEmptyChunksPlugin.js +2 -2
- package/lib/optimize/RemoveParentModulesPlugin.js +4 -4
- package/lib/optimize/RuntimeChunkPlugin.js +2 -2
- package/lib/optimize/SideEffectsFlagPlugin.js +262 -39
- package/lib/optimize/SplitChunksPlugin.js +232 -68
- package/lib/performance/AssetsOverSizeLimitWarning.js +10 -2
- package/lib/performance/AsyncChunkWaterfallsPlugin.js +136 -0
- package/lib/performance/BroadContextsPlugin.js +142 -0
- package/lib/performance/CacheEffectivenessPlugin.js +125 -0
- package/lib/performance/ConflictingResourceHintsPlugin.js +99 -0
- package/lib/performance/DuplicateModulesPlugin.js +93 -0
- package/lib/performance/DuplicatePackagesPlugin.js +119 -0
- package/lib/performance/DuplicatePackagesWarning.js +84 -0
- package/lib/performance/DynamicExportsPlugin.js +120 -0
- package/lib/performance/EmbeddedSourceMapsPlugin.js +71 -0
- package/lib/performance/EntrypointOverlapPlugin.js +122 -0
- package/lib/performance/EntrypointsOverSizeLimitWarning.js +1 -1
- package/lib/performance/EvalUsagePlugin.js +115 -0
- package/lib/performance/HotspotsPlugin.js +296 -0
- package/lib/performance/InlinedAssetsPlugin.js +99 -0
- package/lib/performance/LargeModulesPlugin.js +126 -0
- package/lib/performance/LegacyJavascriptPlugin.js +139 -0
- package/lib/performance/MissingSideEffectsPlugin.js +138 -0
- package/lib/performance/MixedExportsPlugin.js +136 -0
- package/lib/performance/OsDependentRuleWarningPlugin.js +178 -0
- package/lib/performance/PureAnnotationsPlugin.js +219 -0
- package/lib/performance/RedundantDynamicImportsPlugin.js +225 -0
- package/lib/performance/RuntimeInLargeChunkWarning.js +27 -0
- package/lib/performance/ScopeHoistingBailoutsPlugin.js +164 -0
- package/lib/performance/SizeLimitsPlugin.js +139 -7
- package/lib/performance/SplitChunksCappedPlugin.js +99 -0
- package/lib/performance/TinyChunksPlugin.js +128 -0
- package/lib/performance/TopLevelThisPlugin.js +208 -0
- package/lib/performance/UnsplitVendorsPlugin.js +112 -0
- package/lib/performance/UnusedAliasesPlugin.js +253 -0
- package/lib/performance/UnusedDefinesPlugin.js +87 -0
- package/lib/performance/UnusedExternalsPlugin.js +110 -0
- package/lib/performance/UnusedReexportsPlugin.js +159 -0
- package/lib/performance/UnusedRuleWarningPlugin.js +105 -0
- package/lib/performance/getModuleSize.js +22 -0
- package/lib/performance/getSourceModules.js +22 -0
- package/lib/performance/hasOnlyUnusedExports.js +40 -0
- package/lib/prefetch/ChunkPrefetchFunctionRuntimeModule.js +24 -10
- package/lib/prefetch/ChunkPrefetchPreloadPlugin.js +63 -46
- package/lib/prefetch/ChunkPrefetchStartupRuntimeModule.js +2 -3
- package/lib/prefetch/ChunkPrefetchTriggerRuntimeModule.js +2 -2
- package/lib/prefetch/ChunkPreloadTriggerRuntimeModule.js +2 -2
- package/lib/prefetch/ResourceHintPlugin.js +377 -136
- package/lib/prefetch/ResourceHintRuntimeModule.js +1 -21
- package/lib/prefetch/StartupAssetHintRuntimeModule.js +10 -133
- package/lib/prefetch/parseResourceHintOptions.js +31 -4
- package/lib/rules/BasicEffectRulePlugin.js +2 -2
- package/lib/rules/BasicMatcherRulePlugin.js +8 -4
- package/lib/rules/GlobMatcherRulePlugin.js +68 -0
- package/lib/rules/ObjectMatcherRulePlugin.js +12 -5
- package/lib/rules/RuleSetCompiler.js +146 -12
- package/lib/rules/UseEffectRulePlugin.js +18 -11
- package/lib/runtime/AsyncModuleGeneratorRuntimeModule.js +11 -1
- package/lib/runtime/AsyncModuleRuntimeModule.js +1 -1
- package/lib/runtime/AutoPublicPathRuntimeModule.js +15 -20
- package/lib/runtime/BaseUriRuntimeModule.js +33 -7
- package/lib/runtime/ChunkNameRuntimeModule.js +10 -0
- package/lib/runtime/CompatGetDefaultExportRuntimeModule.js +11 -1
- package/lib/runtime/CompatRuntimeModule.js +5 -3
- package/lib/runtime/ConcatenationWrapRuntimeModule.js +90 -0
- package/lib/runtime/ConstructRequireRuntimeModule.js +52 -0
- package/lib/runtime/CreateFakeNamespaceObjectRuntimeModule.js +8 -6
- package/lib/runtime/CreateScriptRuntimeModule.js +11 -1
- package/lib/runtime/CreateScriptUrlRuntimeModule.js +11 -1
- package/lib/runtime/DefinePropertyGettersRuntimeModule.js +56 -38
- package/lib/runtime/EnsureChunkRuntimeModule.js +18 -2
- package/lib/runtime/GetChunkFilenameRuntimeModule.js +62 -37
- package/lib/runtime/GetFullHashRuntimeModule.js +12 -2
- package/lib/runtime/GetMainFilenameRuntimeModule.js +12 -2
- package/lib/runtime/GetTrustedTypesPolicyRuntimeModule.js +2 -2
- package/lib/runtime/GetWorkletBootstrapRuntimeModule.js +16 -3
- package/lib/runtime/GlobalRuntimeModule.js +18 -0
- package/lib/runtime/HasOwnPropertyRuntimeModule.js +12 -2
- package/lib/runtime/LoadScriptRuntimeModule.js +2 -2
- package/lib/runtime/MakeDeferredNamespaceObjectRuntime.js +23 -6
- package/lib/runtime/MakeNamespaceObjectRuntimeModule.js +22 -6
- package/lib/runtime/NonceRuntimeModule.js +10 -0
- package/lib/runtime/OnChunksLoadedRuntimeModule.js +5 -3
- package/lib/runtime/PublicPathRuntimeModule.js +12 -2
- package/lib/runtime/RelativeUrlRuntimeModule.js +11 -1
- package/lib/runtime/RuntimeIdRuntimeModule.js +12 -2
- package/lib/runtime/SetAnonymousDefaultNameRuntimeModule.js +11 -1
- package/lib/runtime/StartupChunkDependenciesPlugin.js +18 -9
- package/lib/runtime/StartupChunkDependenciesRuntimeModule.js +3 -3
- package/lib/runtime/StartupEntrypointRuntimeModule.js +21 -4
- package/lib/runtime/SystemContextRuntimeModule.js +10 -0
- package/lib/runtime/ToBinaryRuntimeModule.js +1 -1
- package/lib/runtime/WorkerRuntimeModule.js +11 -1
- package/lib/runtime/baseUri.js +63 -0
- package/lib/schemes/DataUriPlugin.js +1 -1
- package/lib/schemes/FileUriPlugin.js +1 -1
- package/lib/schemes/HttpUriPlugin.js +24 -15
- package/lib/schemes/VirtualUrlPlugin.js +13 -7
- package/lib/serialization/AggregateErrorSerializer.js +1 -1
- package/lib/serialization/BinaryMiddleware.js +274 -942
- package/lib/serialization/ErrorObjectSerializer.js +1 -1
- package/lib/serialization/FileMiddleware.js +305 -66
- package/lib/serialization/ObjectMiddleware.js +139 -114
- package/lib/serialization/PlainObjectSerializer.js +19 -16
- package/lib/sharing/ConsumeSharedModule.js +30 -21
- package/lib/sharing/ConsumeSharedPlugin.js +18 -10
- package/lib/sharing/ConsumeSharedRuntimeModule.js +6 -9
- package/lib/sharing/ProvideSharedModule.js +25 -16
- package/lib/sharing/ProvideSharedModuleFactory.js +7 -3
- package/lib/sharing/ProvideSharedPlugin.js +8 -4
- package/lib/sharing/SharePlugin.js +17 -5
- package/lib/sharing/ShareRuntimeModule.js +4 -4
- package/lib/sharing/resolveMatchedConfigs.js +9 -6
- package/lib/sharing/utils.js +1 -3
- package/lib/stats/DefaultStatsFactoryPlugin.js +253 -226
- package/lib/stats/DefaultStatsPresetPlugin.js +17 -8
- package/lib/stats/DefaultStatsPrinterPlugin.js +60 -192
- package/lib/stats/StatsFactory.js +56 -35
- package/lib/stats/StatsPrinter.js +16 -12
- package/lib/typescript/TypeScriptPlugin.js +12 -14
- package/lib/url/URLParserPlugin.js +26 -13
- package/lib/util/AsyncQueue.js +4 -3
- package/lib/util/Hash.js +5 -1
- package/lib/util/LazySet.js +35 -22
- package/lib/util/LocConverter.js +36 -13
- package/lib/util/SourceProcessor.js +1050 -24
- package/lib/util/StringXor.js +1 -1
- package/lib/util/chainedImports.js +9 -5
- package/lib/util/cleverMerge.js +1 -1
- package/lib/util/comparators.js +45 -14
- package/lib/util/concatenate.js +203 -77
- package/lib/util/conventions.js +5 -1
- package/lib/util/createHash.js +2 -2
- package/lib/util/createHooksRegistry.js +8 -10
- package/lib/util/dataURL.js +225 -1
- package/lib/util/extractSourceMap.js +4 -3
- package/lib/util/findCaseMismatch.js +139 -0
- package/lib/util/formatLocation.js +1 -2
- package/lib/util/fs.js +22 -5
- package/lib/util/globUtils.js +298 -24
- package/lib/util/hash/BatchedHash.js +5 -1
- package/lib/util/hash/BulkUpdateHash.js +5 -1
- package/lib/util/hash/DebugHash.js +5 -1
- package/lib/util/hash/hash-digest.js +6 -2
- package/lib/util/identifier.js +25 -1
- package/lib/util/implicitTypeLoaderFallback.js +1 -1
- package/lib/util/internalSerializables.js +6 -0
- package/lib/util/lazyModule.js +56 -0
- package/lib/util/makeSerializable.js +7 -3
- package/lib/util/matchAlias.js +25 -0
- package/lib/util/mimeTypes.js +11 -5
- package/lib/util/nonNumericOnlyHash.js +4 -3
- package/lib/util/parseJson.js +5 -3
- package/lib/util/preloadModuleType.js +32 -0
- package/lib/util/registerExternalSerializer.js +7 -5
- package/lib/util/runtime.js +2 -2
- package/lib/util/semver.js +1 -1
- package/lib/util/serialization.js +28 -28
- package/lib/util/source.js +2 -2
- package/lib/util/traverseDestructuringAssignmentProperties.js +6 -2
- package/lib/wasm/EnableWasmLoadingPlugin.js +10 -8
- package/lib/wasm/wasmModuleFilename.js +54 -0
- package/lib/wasm-async/AsyncWasmCompileRuntimeModule.js +41 -21
- package/lib/wasm-async/AsyncWasmLoadingRuntimeModule.js +43 -21
- package/lib/wasm-async/AsyncWasmModule.js +3 -3
- package/lib/wasm-async/AsyncWebAssemblyGenerator.js +4 -5
- package/lib/wasm-async/AsyncWebAssemblyJavascriptGenerator.js +57 -17
- package/lib/wasm-async/AsyncWebAssemblyModulesPlugin.js +34 -18
- package/lib/wasm-async/AsyncWebAssemblyParser.js +9 -8
- package/lib/wasm-async/UniversalCompileAsyncWasmPlugin.js +34 -8
- package/lib/wasm-sync/SyncWasmModule.js +2 -2
- package/lib/wasm-sync/WasmChunkLoadingRuntimeModule.js +18 -13
- package/lib/wasm-sync/WasmFinalizeExportsPlugin.js +4 -5
- package/lib/wasm-sync/WebAssemblyGenerator.js +18 -17
- package/lib/wasm-sync/WebAssemblyInInitialChunkError.js +4 -4
- package/lib/wasm-sync/WebAssemblyJavascriptGenerator.js +7 -7
- package/lib/wasm-sync/WebAssemblyModulesPlugin.js +24 -11
- package/lib/wasm-sync/WebAssemblyParser.js +4 -6
- package/lib/wasm-sync/WebAssemblyUtils.js +2 -2
- package/lib/web/FetchCompileAsyncWasmPlugin.js +101 -19
- package/lib/web/FetchCompileWasmPlugin.js +46 -16
- package/lib/web/JsonpChunkLoadingPlugin.js +47 -23
- package/lib/web/JsonpChunkLoadingRuntimeModule.js +50 -20
- package/lib/web/JsonpTemplatePlugin.js +2 -2
- package/lib/webpack.js +22 -11
- package/lib/webworker/ImportScriptsChunkLoadingPlugin.js +60 -26
- package/lib/webworker/ImportScriptsChunkLoadingRuntimeModule.js +30 -32
- package/lib/webworker/WebWorkerTemplatePlugin.js +1 -1
- package/module.d.ts +1 -0
- package/package.json +37 -30
- package/schemas/WebpackOptions.check.js +1 -1
- package/schemas/WebpackOptions.json +780 -91
- package/schemas/plugins/HtmlParserOptions.check.js +1 -1
- package/schemas/plugins/container/ContainerPlugin.check.js +1 -1
- package/schemas/plugins/container/ContainerPlugin.json +10 -0
- package/schemas/plugins/container/ModuleFederationPlugin.check.js +1 -1
- package/schemas/plugins/container/ModuleFederationPlugin.json +10 -0
- package/schemas/plugins/css/CssAutoOrModuleParserOptions.check.js +1 -1
- package/schemas/plugins/css/CssModuleParserOptions.check.js +1 -1
- package/schemas/plugins/css/CssParserOptions.check.js +1 -1
- package/types.d.ts +4013 -738
- package/lib/runtime/CommonJsWrapRuntimeModule.js +0 -37
|
@@ -14,38 +14,29 @@ const {
|
|
|
14
14
|
} = require("../ModuleSourceTypeConstants");
|
|
15
15
|
const RuntimeGlobals = require("../RuntimeGlobals");
|
|
16
16
|
const Template = require("../Template");
|
|
17
|
+
const CssModulesPlugin = require("../css/CssModulesPlugin");
|
|
17
18
|
const WebpackError = require("../errors/WebpackError");
|
|
18
19
|
const { getUndoPath } = require("../util/identifier");
|
|
19
20
|
const memoize = require("../util/memoize");
|
|
20
21
|
const { PUBLIC_PATH_AUTO } = require("../util/publicPathPlaceholder");
|
|
21
|
-
const {
|
|
22
|
+
const { VOID } = require("./data");
|
|
22
23
|
|
|
24
|
+
const getCreateNodeHash = memoize(() => require("crypto").createHash);
|
|
25
|
+
|
|
26
|
+
const getCssSyntax = memoize(() => require("../css/syntax"));
|
|
27
|
+
|
|
28
|
+
const getHtmlSyntax = memoize(() => require("./syntax"));
|
|
29
|
+
|
|
30
|
+
// Lazy: the dependency templates need this module's sentinel helpers on every
|
|
31
|
+
// build, but the HTML tokenizer is only reached once HTML is actually emitted.
|
|
23
32
|
// Lazy so loading the HTML generator doesn't pull in the whole CSS pipeline.
|
|
24
|
-
|
|
33
|
+
|
|
25
34
|
// The CSS tokenizer, used to locate `url(...)` when rebasing inlined stylesheets.
|
|
26
|
-
const getCssSyntax = memoize(() => require("../css/syntax"));
|
|
27
35
|
// node's crypto — real SHA hashes for Content-Security-Policy source lists
|
|
28
36
|
// (the wasm hashes are xxhash, unusable for CSP), loaded only when CSP is on.
|
|
29
|
-
const getCreateNodeHash = memoize(() => require("crypto").createHash);
|
|
30
37
|
|
|
31
38
|
// HTML void elements — serialized without a closing tag when a tag descriptor
|
|
32
39
|
// (`output.html` `injectTags`) doesn't say otherwise.
|
|
33
|
-
const VOID_TAGS = new Set([
|
|
34
|
-
"area",
|
|
35
|
-
"base",
|
|
36
|
-
"br",
|
|
37
|
-
"col",
|
|
38
|
-
"embed",
|
|
39
|
-
"hr",
|
|
40
|
-
"img",
|
|
41
|
-
"input",
|
|
42
|
-
"link",
|
|
43
|
-
"meta",
|
|
44
|
-
"param",
|
|
45
|
-
"source",
|
|
46
|
-
"track",
|
|
47
|
-
"wbr"
|
|
48
|
-
]);
|
|
49
40
|
|
|
50
41
|
/**
|
|
51
42
|
* Serializes an attribute map: `true` → bare attribute, `false`/`undefined`/
|
|
@@ -56,6 +47,7 @@ const VOID_TAGS = new Set([
|
|
|
56
47
|
const serializeAttrs = (attrs) => {
|
|
57
48
|
let out = "";
|
|
58
49
|
if (attrs) {
|
|
50
|
+
const { escapeAttribute } = getHtmlSyntax();
|
|
59
51
|
for (const name of Object.keys(attrs)) {
|
|
60
52
|
const value = attrs[name];
|
|
61
53
|
if (value === false || value === undefined || value === null) continue;
|
|
@@ -77,9 +69,7 @@ const serializeAttrs = (attrs) => {
|
|
|
77
69
|
const serializeTag = (tag) => {
|
|
78
70
|
const attrs = serializeAttrs(tag.attrs);
|
|
79
71
|
const isVoid =
|
|
80
|
-
tag.voidTag !== undefined
|
|
81
|
-
? tag.voidTag
|
|
82
|
-
: VOID_TAGS.has(tag.tag.toLowerCase());
|
|
72
|
+
tag.voidTag !== undefined ? tag.voidTag : VOID.has(tag.tag.toLowerCase());
|
|
83
73
|
return isVoid
|
|
84
74
|
? `<${tag.tag}${attrs}>`
|
|
85
75
|
: `<${tag.tag}${attrs}>${tag.children || ""}</${tag.tag}>`;
|
|
@@ -134,11 +124,10 @@ const metaIsCsp = (attrs) => {
|
|
|
134
124
|
return false;
|
|
135
125
|
};
|
|
136
126
|
|
|
137
|
-
/** @
|
|
138
|
-
/** @
|
|
127
|
+
/** @import { Source } from "webpack-sources" */
|
|
128
|
+
/** @import { HtmlGeneratorOptions } from "../../declarations/WebpackOptions" */
|
|
139
129
|
/** @typedef {import("../../declarations/WebpackOptions").OutputHtmlOptions["csp"]} CspOption */
|
|
140
|
-
/** @
|
|
141
|
-
/** @typedef {import("./HtmlModulesPlugin").HtmlMutableTag} HtmlMutableTag */
|
|
130
|
+
/** @import { HtmlTagDescriptor, HtmlMutableTag } from "./HtmlModulesPlugin" */
|
|
142
131
|
/** @typedef {"head" | "body"} HtmlTagLocation */
|
|
143
132
|
/**
|
|
144
133
|
* @typedef {object} HtmlTagSpan
|
|
@@ -152,24 +141,26 @@ const metaIsCsp = (attrs) => {
|
|
|
152
141
|
*/
|
|
153
142
|
/** @typedef {{ headOpen: number, headEnd: number, bodyOpen: number, bodyEnd: number }} HtmlAnchors */
|
|
154
143
|
/** @typedef {{ tags: HtmlMutableTag[], spans: (HtmlTagSpan | null)[], originals: (string | null)[], descriptors: (HtmlTagDescriptor | null)[], anchors: HtmlAnchors }} HtmlModel */
|
|
155
|
-
/** @
|
|
156
|
-
/** @
|
|
144
|
+
/** @import Chunk from "../Chunk" */
|
|
145
|
+
/** @import Compilation, { DependencyConstructor } from "../Compilation" */
|
|
157
146
|
/** @typedef {boolean | string[] | ((asset: { chunk: Chunk, filename: string }) => string[] | false)} HtmlIntegrity */
|
|
158
|
-
/** @
|
|
159
|
-
/** @
|
|
160
|
-
/** @
|
|
161
|
-
/** @
|
|
162
|
-
/**
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
/** @
|
|
171
|
-
/** @
|
|
172
|
-
/** @
|
|
147
|
+
/** @import CodeGenerationResults from "../CodeGenerationResults" */
|
|
148
|
+
/** @import Dependency from "../Dependency" */
|
|
149
|
+
/** @import { DependencyTemplateContext } from "../DependencyTemplate" */
|
|
150
|
+
/** @import { GenerateContext, UpdateHashContext } from "../Generator" */
|
|
151
|
+
/**
|
|
152
|
+
* @import Module, {
|
|
153
|
+
* SourceType,
|
|
154
|
+
* SourceTypes,
|
|
155
|
+
* ConcatenationBailoutReasonContext,
|
|
156
|
+
* RuntimeRequirements
|
|
157
|
+
* } from "../Module"
|
|
158
|
+
*/
|
|
159
|
+
/** @import ModuleGraph from "../ModuleGraph" */
|
|
160
|
+
/** @import NormalModule from "../NormalModule" */
|
|
161
|
+
/** @import { HtmlModuleBuildInfo } from "./HtmlModule" */
|
|
162
|
+
/** @import RuntimeTemplate from "../RuntimeTemplate" */
|
|
163
|
+
/** @import Hash from "../util/Hash" */
|
|
173
164
|
/**
|
|
174
165
|
* @template T
|
|
175
166
|
* @typedef {import("../InitFragment")<T>} InitFragment
|
|
@@ -201,6 +192,27 @@ const getChunksById = (compilation) => {
|
|
|
201
192
|
return chunksById;
|
|
202
193
|
};
|
|
203
194
|
|
|
195
|
+
/** @type {WeakMap<Compilation, Map<string, Module>>} */
|
|
196
|
+
const modulesByIdentifierCache = new WeakMap();
|
|
197
|
+
|
|
198
|
+
/**
|
|
199
|
+
* `module.identifier()` → module lookup, memoized per compilation so the asset
|
|
200
|
+
* URL sentinel resolver doesn't re-scan the whole module graph per HTML module.
|
|
201
|
+
* @param {Compilation} compilation compilation
|
|
202
|
+
* @returns {Map<string, Module>} modules keyed by identifier
|
|
203
|
+
*/
|
|
204
|
+
const getModulesByIdentifier = (compilation) => {
|
|
205
|
+
let modulesByIdentifier = modulesByIdentifierCache.get(compilation);
|
|
206
|
+
if (modulesByIdentifier === undefined) {
|
|
207
|
+
modulesByIdentifier = new Map();
|
|
208
|
+
for (const module of compilation.modules) {
|
|
209
|
+
modulesByIdentifier.set(module.identifier(), module);
|
|
210
|
+
}
|
|
211
|
+
modulesByIdentifierCache.set(compilation, modulesByIdentifier);
|
|
212
|
+
}
|
|
213
|
+
return modulesByIdentifier;
|
|
214
|
+
};
|
|
215
|
+
|
|
204
216
|
// Hoisted so `resolveChunkUrlSentinels` (per chunk × module) doesn't allocate a
|
|
205
217
|
// fresh `RegExp` each call. `String#replace` resets `lastIndex`, so sharing the
|
|
206
218
|
// global-flag instance is safe under these synchronous, non-reentrant calls.
|
|
@@ -222,15 +234,23 @@ const HTML_PAGE_URL_SENTINEL_REGEXP =
|
|
|
222
234
|
const ASSET_URL_SENTINEL_REGEXP =
|
|
223
235
|
/__WEBPACK_HTML_ASSET_URL__([0-9a-f]+)__END__/g;
|
|
224
236
|
|
|
237
|
+
// Compilations whose HTML modules must emit SRI sentinels (see
|
|
238
|
+
// `enableIntegritySentinels`).
|
|
239
|
+
/** @type {WeakSet<Compilation>} */
|
|
240
|
+
const integritySentinelCompilations = new WeakSet();
|
|
241
|
+
|
|
225
242
|
// Matches the whole ` integrity="<sentinel>"` so the attribute can be dropped
|
|
226
|
-
// entirely when the per-asset `integrity` function returns `false`.
|
|
243
|
+
// entirely when the per-asset `integrity` function returns `false`. Minification
|
|
244
|
+
// runs first and may have unquoted the value (§13.1.2.3), so the quote is
|
|
245
|
+
// optional and back-referenced to keep the pair matched; the replacement always
|
|
246
|
+
// re-quotes, since an SRI list carries spaces and `=` padding.
|
|
227
247
|
const INTEGRITY_SENTINEL_REGEXP =
|
|
228
|
-
/ integrity="__WEBPACK_HTML_INTEGRITY__([0-9a-f]+)__([a-z]+)__END__
|
|
248
|
+
/ integrity=(["']?)__WEBPACK_HTML_INTEGRITY__([0-9a-f]+)__([a-z]+)__END__\1/g;
|
|
229
249
|
|
|
230
250
|
// Same attribute, but tolerant of the `\"` escaping the surrounding quotes get
|
|
231
251
|
// when the HTML lives inside a JS string literal — used only to strip it there.
|
|
232
252
|
const INTEGRITY_SENTINEL_STRIP_REGEXP =
|
|
233
|
-
/ integrity
|
|
253
|
+
/ integrity=(\\?["']|)__WEBPACK_HTML_INTEGRITY__[0-9a-f]+__[a-z]+__END__\1/g;
|
|
234
254
|
|
|
235
255
|
// The trailing `(?:__<hash>)?` is the inlined chunk's content hash, embedded by
|
|
236
256
|
// `embedInlineChunkHashes` so the host HTML's bytes (and its `[contenthash]`,
|
|
@@ -331,7 +351,7 @@ class HtmlGenerator extends Generator {
|
|
|
331
351
|
// handling included), mirroring the CSS branch.
|
|
332
352
|
let filenameTemplate;
|
|
333
353
|
if (contentHashType === "css") {
|
|
334
|
-
filenameTemplate =
|
|
354
|
+
filenameTemplate = CssModulesPlugin.getChunkFilenameTemplate(
|
|
335
355
|
chunk,
|
|
336
356
|
outputOptions
|
|
337
357
|
);
|
|
@@ -413,9 +433,7 @@ class HtmlGenerator extends Generator {
|
|
|
413
433
|
*/
|
|
414
434
|
static resolveAssetUrlSentinels(content, compilation) {
|
|
415
435
|
if (!content.includes("__WEBPACK_HTML_ASSET_URL__")) return content;
|
|
416
|
-
|
|
417
|
-
const byIdentifier = new Map();
|
|
418
|
-
for (const m of compilation.modules) byIdentifier.set(m.identifier(), m);
|
|
436
|
+
const byIdentifier = getModulesByIdentifier(compilation);
|
|
419
437
|
const codeGenerationResults =
|
|
420
438
|
/** @type {import("../CodeGenerationResults")} */
|
|
421
439
|
(compilation.codeGenerationResults);
|
|
@@ -443,6 +461,26 @@ class HtmlGenerator extends Generator {
|
|
|
443
461
|
});
|
|
444
462
|
}
|
|
445
463
|
|
|
464
|
+
/**
|
|
465
|
+
* Turns SRI sentinel emission on for this compilation. Tags are generated
|
|
466
|
+
* once per HTML module, but one module can back several pages with different
|
|
467
|
+
* `integrity` options, so HtmlModulesPlugin flags the compilation when any
|
|
468
|
+
* page wants SRI and each page resolves or strips the sentinels on emit.
|
|
469
|
+
* @param {Compilation} compilation compilation
|
|
470
|
+
* @returns {void}
|
|
471
|
+
*/
|
|
472
|
+
static enableIntegritySentinels(compilation) {
|
|
473
|
+
integritySentinelCompilations.add(compilation);
|
|
474
|
+
}
|
|
475
|
+
|
|
476
|
+
/**
|
|
477
|
+
* @param {Compilation} compilation compilation
|
|
478
|
+
* @returns {boolean} true when SRI sentinels must be emitted
|
|
479
|
+
*/
|
|
480
|
+
static hasIntegritySentinels(compilation) {
|
|
481
|
+
return integritySentinelCompilations.has(compilation);
|
|
482
|
+
}
|
|
483
|
+
|
|
446
484
|
/**
|
|
447
485
|
* Emit a sentinel for a chunk's SRI hash. Resolved late (after
|
|
448
486
|
* `RealContentHashPlugin`) by `resolveChunkIntegritySentinels`, since the
|
|
@@ -489,7 +527,7 @@ class HtmlGenerator extends Generator {
|
|
|
489
527
|
const chunksById = getChunksById(compilation);
|
|
490
528
|
return content.replace(
|
|
491
529
|
INTEGRITY_SENTINEL_REGEXP,
|
|
492
|
-
(_, hexId, contentHashType) => {
|
|
530
|
+
(_, _quote, hexId, contentHashType) => {
|
|
493
531
|
const chunkId = Buffer.from(hexId, "hex").toString("utf8");
|
|
494
532
|
const chunk = chunksById.get(chunkId);
|
|
495
533
|
if (!chunk) return "";
|
|
@@ -640,6 +678,7 @@ class HtmlGenerator extends Generator {
|
|
|
640
678
|
// `skip.text` populates `contentEnd` (raw-text body end) without
|
|
641
679
|
// materializing text nodes; `</script` stays escaped, so CSP hashes match
|
|
642
680
|
// the exact bytes the browser sees.
|
|
681
|
+
const { NodeType, SourceProcessor } = getHtmlSyntax();
|
|
643
682
|
new SourceProcessor()
|
|
644
683
|
.use({
|
|
645
684
|
[NodeType.Element]: {
|
|
@@ -648,11 +687,23 @@ class HtmlGenerator extends Generator {
|
|
|
648
687
|
if (name === "head") {
|
|
649
688
|
if (headOpen < 0) headOpen = headEnd = path.tagEnd();
|
|
650
689
|
headDepth++;
|
|
690
|
+
} else if (name === "body") {
|
|
691
|
+
if (bodyOpen < 0) bodyOpen = bodyEnd = path.tagEnd();
|
|
692
|
+
bodyDepth++;
|
|
693
|
+
}
|
|
694
|
+
},
|
|
695
|
+
// Collected on exit: an element's `end` is only final once it
|
|
696
|
+
// closes, and the streamed walk enters it while it is still open.
|
|
697
|
+
// `script` / `style` / `link` / `meta` never nest in each other, so
|
|
698
|
+
// exiting keeps them in source order.
|
|
699
|
+
exit: (path) => {
|
|
700
|
+
const name = path.tagName();
|
|
701
|
+
if (name === "head") {
|
|
702
|
+
if (headDepth > 0) headDepth--;
|
|
651
703
|
return;
|
|
652
704
|
}
|
|
653
705
|
if (name === "body") {
|
|
654
|
-
if (
|
|
655
|
-
bodyDepth++;
|
|
706
|
+
if (bodyDepth > 0) bodyDepth--;
|
|
656
707
|
return;
|
|
657
708
|
}
|
|
658
709
|
const end = path.end();
|
|
@@ -693,14 +744,6 @@ class HtmlGenerator extends Generator {
|
|
|
693
744
|
});
|
|
694
745
|
originals.push(snapshotAttrs(attrs));
|
|
695
746
|
descriptors.push(null);
|
|
696
|
-
},
|
|
697
|
-
exit: (path) => {
|
|
698
|
-
const name = path.tagName();
|
|
699
|
-
if (name === "head") {
|
|
700
|
-
if (headDepth > 0) headDepth--;
|
|
701
|
-
} else if (name === "body" && bodyDepth > 0) {
|
|
702
|
-
bodyDepth--;
|
|
703
|
-
}
|
|
704
747
|
}
|
|
705
748
|
}
|
|
706
749
|
})
|
|
@@ -743,14 +786,16 @@ class HtmlGenerator extends Generator {
|
|
|
743
786
|
* `*-prepend`), or had its `attrs` changed; and — when `csp` is set and the
|
|
744
787
|
* page declares no CSP — a strict `<meta http-equiv="Content-Security-Policy">`
|
|
745
788
|
* is injected with a hash of every inline `<script>`/`<style>` (page's own and
|
|
746
|
-
* injected) plus an optional placeholder `nonce` on each. Edits
|
|
747
|
-
*
|
|
789
|
+
* injected) plus an optional placeholder `nonce` on each. Edits are applied
|
|
790
|
+
* in one ascending pass; at a shared offset an insert is emitted before a
|
|
791
|
+
* delete/replace's text.
|
|
748
792
|
* @param {string} content the collected HTML (inline content already resolved)
|
|
749
793
|
* @param {HtmlModel} model the value from `collectHtml` after the hooks
|
|
750
794
|
* @param {CspOption} csp the `output.html.csp` option
|
|
751
795
|
* @returns {string} the rendered HTML
|
|
752
796
|
*/
|
|
753
797
|
static renderHtml(content, model, csp) {
|
|
798
|
+
const { escapeAttribute } = getHtmlSyntax();
|
|
754
799
|
const { tags, spans, originals, descriptors, anchors } = model;
|
|
755
800
|
// CSP setup: an author-declared policy (page's own or injected) wins.
|
|
756
801
|
const options = csp ? (csp === true ? {} : csp) : undefined;
|
|
@@ -950,14 +995,20 @@ class HtmlGenerator extends Generator {
|
|
|
950
995
|
edits.push({ start: pos, end: pos, text, insert: true });
|
|
951
996
|
}
|
|
952
997
|
if (edits.length === 0) return content;
|
|
998
|
+
// Ascending single pass over the (non-overlapping) edits — O(page + edits)
|
|
999
|
+
// instead of two full-page copies per edit; the tie-break reproduces the
|
|
1000
|
+
// former right-to-left order (insert text lands before a replacement's).
|
|
953
1001
|
edits.sort(
|
|
954
|
-
(a, b) =>
|
|
1002
|
+
(a, b) => a.start - b.start || Number(b.insert) - Number(a.insert)
|
|
955
1003
|
);
|
|
956
|
-
let result =
|
|
1004
|
+
let result = "";
|
|
1005
|
+
let cursor = 0;
|
|
957
1006
|
for (const edit of edits) {
|
|
958
|
-
result
|
|
1007
|
+
result += content.slice(cursor, edit.start);
|
|
1008
|
+
result += edit.text;
|
|
1009
|
+
if (edit.end > cursor) cursor = edit.end;
|
|
959
1010
|
}
|
|
960
|
-
return result;
|
|
1011
|
+
return result + content.slice(cursor);
|
|
961
1012
|
}
|
|
962
1013
|
|
|
963
1014
|
/**
|
|
@@ -1273,8 +1324,18 @@ class HtmlGenerator extends Generator {
|
|
|
1273
1324
|
);
|
|
1274
1325
|
}
|
|
1275
1326
|
|
|
1276
|
-
// JS export: resolve `[webpack/auto]` to root-relative URLs.
|
|
1277
|
-
|
|
1327
|
+
// JS export: resolve `[webpack/auto]` to root-relative URLs. No `.html`
|
|
1328
|
+
// asset carries this markup, so an asset-level minimizer never sees it.
|
|
1329
|
+
const embedded =
|
|
1330
|
+
generateContext.runtimeTemplate.compilation._resolveEmbeddedSource(
|
|
1331
|
+
new RawSource(this._renderHtml(module, generateContext, "")),
|
|
1332
|
+
{ type: HTML_TYPE, hostType: JAVASCRIPT_TYPE, module }
|
|
1333
|
+
);
|
|
1334
|
+
const embeddedSource = embedded.source();
|
|
1335
|
+
const generated =
|
|
1336
|
+
typeof embeddedSource === "string"
|
|
1337
|
+
? embeddedSource
|
|
1338
|
+
: embeddedSource.toString("utf8");
|
|
1278
1339
|
|
|
1279
1340
|
/** @type {string} */
|
|
1280
1341
|
let sourceContent;
|
|
@@ -1329,13 +1390,21 @@ class HtmlGenerator extends Generator {
|
|
|
1329
1390
|
* exactly as a full page reload would render them.
|
|
1330
1391
|
*
|
|
1331
1392
|
* `<head>` changes beyond `<title>` (a new `<meta>`, a swapped
|
|
1332
|
-
* `<link rel=icon>`, an inline `<style>` block, …)
|
|
1333
|
-
*
|
|
1334
|
-
*
|
|
1335
|
-
*
|
|
1336
|
-
*
|
|
1337
|
-
*
|
|
1338
|
-
*
|
|
1393
|
+
* `<link rel=icon>`, an inline `<style>` block, …) are applied as a
|
|
1394
|
+
* delta against the previous evaluation's authored head. Replacing
|
|
1395
|
+
* `document.head.innerHTML` wholesale would tear down the runtime
|
|
1396
|
+
* scripts and stylesheet links webpack injects there on initial load;
|
|
1397
|
+
* a delta cannot, since those appear in neither authored head. An
|
|
1398
|
+
* added `<script>` is re-created before it is inserted, so it runs the
|
|
1399
|
+
* way the reload this replaces would have run it, and every addition
|
|
1400
|
+
* lands at its authored position rather than at the end. Two edits are
|
|
1401
|
+
* still worth reloading for: a removed `<script>` the browser *executed*,
|
|
1402
|
+
* since one that has run cannot be un-run (a removed data block such as
|
|
1403
|
+
* `application/ld+json` never ran, so it is patched like any other
|
|
1404
|
+
* element), and a reordering of elements the delta cannot
|
|
1405
|
+
* express — fine in a dev-server context because the regular
|
|
1406
|
+
* (non-hot-update) `page.html` chunk is re-emitted on every rebuild,
|
|
1407
|
+
* so the reloaded page picks up the new head.
|
|
1339
1408
|
* @param {NormalModule} module module
|
|
1340
1409
|
* @param {string} html the rewritten HTML content (with placeholders resolved)
|
|
1341
1410
|
* @param {boolean} extracting whether the HTML module is being extracted as a real `.html` file
|
|
@@ -1344,6 +1413,7 @@ class HtmlGenerator extends Generator {
|
|
|
1344
1413
|
*/
|
|
1345
1414
|
_renderHmrShim(module, html, extracting, runtimeTemplate) {
|
|
1346
1415
|
const declare = runtimeTemplate.renderConst();
|
|
1416
|
+
const mutable = runtimeTemplate.renderLet();
|
|
1347
1417
|
const acceptBlock = extracting
|
|
1348
1418
|
? [
|
|
1349
1419
|
"module.hot.accept();",
|
|
@@ -1389,10 +1459,151 @@ class HtmlGenerator extends Generator {
|
|
|
1389
1459
|
'return head === null ? "" : __webpack_mask_comments__(head).replace(/<title[^>]*>[\\s\\S]*?<\\/title>/i, "").trim();'
|
|
1390
1460
|
]
|
|
1391
1461
|
)};`,
|
|
1462
|
+
// The authored head's elements, parsed but detached.
|
|
1463
|
+
`${declare} __webpack_head_children__ = ${runtimeTemplate.basicFunction(
|
|
1464
|
+
"html",
|
|
1465
|
+
[
|
|
1466
|
+
`${declare} container = document.createElement("head");`,
|
|
1467
|
+
"container.innerHTML = html;",
|
|
1468
|
+
"return Array.prototype.slice.call(container.children);"
|
|
1469
|
+
]
|
|
1470
|
+
)};`,
|
|
1471
|
+
// A `<script>` parsed out of a string carries the already-started flag,
|
|
1472
|
+
// so appending that element would never run it. A fresh one with the
|
|
1473
|
+
// same attributes and body does — which is what the reload this
|
|
1474
|
+
// replaces would have done.
|
|
1475
|
+
`${declare} __webpack_revive_script__ = ${runtimeTemplate.basicFunction(
|
|
1476
|
+
"node",
|
|
1477
|
+
[
|
|
1478
|
+
'if (node.nodeName !== "SCRIPT") return node;',
|
|
1479
|
+
`${declare} script = document.createElement("script");`,
|
|
1480
|
+
`${declare} attributes = node.attributes;`,
|
|
1481
|
+
`for (${mutable} i = 0; i < attributes.length; i++) {`,
|
|
1482
|
+
Template.indent(
|
|
1483
|
+
"script.setAttribute(attributes[i].name, attributes[i].value);"
|
|
1484
|
+
),
|
|
1485
|
+
"}",
|
|
1486
|
+
"script.textContent = node.textContent;",
|
|
1487
|
+
"return script;"
|
|
1488
|
+
]
|
|
1489
|
+
)};`,
|
|
1490
|
+
// Apply only the difference between the two authored heads, keyed on
|
|
1491
|
+
// serialized markup: the runtime's own injected `<script>` / `<link>`
|
|
1492
|
+
// are in neither string, so replacing `document.head` wholesale would
|
|
1493
|
+
// tear them down while a delta never touches them. Reports whether it
|
|
1494
|
+
// could — the caller reloads when it could not.
|
|
1495
|
+
`${declare} __webpack_patch_head__ = ${runtimeTemplate.basicFunction(
|
|
1496
|
+
"oldHtml, newHtml",
|
|
1497
|
+
[
|
|
1498
|
+
"if (!document.head) return false;",
|
|
1499
|
+
`${declare} oldChildren = __webpack_head_children__(oldHtml);`,
|
|
1500
|
+
`${declare} newChildren = __webpack_head_children__(newHtml);`,
|
|
1501
|
+
`${declare} count = ${runtimeTemplate.basicFunction("nodes", [
|
|
1502
|
+
`${declare} counts = {};`,
|
|
1503
|
+
`for (${mutable} i = 0; i < nodes.length; i++) {`,
|
|
1504
|
+
Template.indent([
|
|
1505
|
+
`${declare} key = "$" + nodes[i].outerHTML;`,
|
|
1506
|
+
"counts[key] = (counts[key] || 0) + 1;"
|
|
1507
|
+
]),
|
|
1508
|
+
"}",
|
|
1509
|
+
"return counts;"
|
|
1510
|
+
])};`,
|
|
1511
|
+
// An element present the same number of times on both sides is
|
|
1512
|
+
// untouched; whatever is left over on one side is the delta.
|
|
1513
|
+
`${declare} surplus = ${runtimeTemplate.basicFunction(
|
|
1514
|
+
"nodes, others",
|
|
1515
|
+
[
|
|
1516
|
+
`${declare} counts = count(others);`,
|
|
1517
|
+
`${declare} out = [];`,
|
|
1518
|
+
`for (${mutable} i = 0; i < nodes.length; i++) {`,
|
|
1519
|
+
Template.indent([
|
|
1520
|
+
`${declare} key = "$" + nodes[i].outerHTML;`,
|
|
1521
|
+
"if (counts[key] > 0) counts[key]--; else out.push(nodes[i]);"
|
|
1522
|
+
]),
|
|
1523
|
+
"}",
|
|
1524
|
+
"return out;"
|
|
1525
|
+
]
|
|
1526
|
+
)};`,
|
|
1527
|
+
`${declare} removed = surplus(oldChildren, newChildren);`,
|
|
1528
|
+
`${declare} added = surplus(newChildren, oldChildren);`,
|
|
1529
|
+
"if (removed.length === 0 && added.length === 0) return true;",
|
|
1530
|
+
// A script that has run cannot be un-run, so dropping one is the
|
|
1531
|
+
// one edit still worth a reload — but only a script that ran. A
|
|
1532
|
+
// `type` that is neither a JavaScript MIME type nor `module` /
|
|
1533
|
+
// `importmap` / `speculationrules` makes the element a data block
|
|
1534
|
+
// (`application/ld+json`, `text/template`, …) the browser never
|
|
1535
|
+
// executed, so removing it is as safe as removing a `<meta>`.
|
|
1536
|
+
// Every JavaScript MIME essence ends in `script`, and a type
|
|
1537
|
+
// nothing here recognizes falls back to the reload.
|
|
1538
|
+
`if (removed.some(${runtimeTemplate.basicFunction("node", [
|
|
1539
|
+
'if (node.nodeName !== "SCRIPT") return false;',
|
|
1540
|
+
`${declare} type = (node.getAttribute("type") || "").trim().toLowerCase();`,
|
|
1541
|
+
'return type === "" || type.indexOf("script") !== -1 || type === "module" || type === "importmap" || type === "speculationrules";'
|
|
1542
|
+
])})) return false;`,
|
|
1543
|
+
// Resolve every removal before mutating, so a node the page
|
|
1544
|
+
// dropped on its own leaves the head as it was.
|
|
1545
|
+
`${declare} live = [];`,
|
|
1546
|
+
`for (${mutable} i = 0; i < removed.length; i++) {`,
|
|
1547
|
+
Template.indent([
|
|
1548
|
+
`${declare} key = removed[i].outerHTML;`,
|
|
1549
|
+
`${mutable} match = null;`,
|
|
1550
|
+
`for (${mutable} j = 0; j < document.head.children.length; j++) {`,
|
|
1551
|
+
Template.indent([
|
|
1552
|
+
`${declare} child = document.head.children[j];`,
|
|
1553
|
+
"if (child.outerHTML === key && live.indexOf(child) === -1) { match = child; break; }"
|
|
1554
|
+
]),
|
|
1555
|
+
"}",
|
|
1556
|
+
"if (match === null) return false;",
|
|
1557
|
+
"live.push(match);"
|
|
1558
|
+
]),
|
|
1559
|
+
"}",
|
|
1560
|
+
`for (${mutable} i = 0; i < live.length; i++) document.head.removeChild(live[i]);`,
|
|
1561
|
+
// Pair each retained element with its live node, scanning only
|
|
1562
|
+
// forward: an authored element that has moved relative to the
|
|
1563
|
+
// others finds no match from there on, and a reorder the delta
|
|
1564
|
+
// cannot express falls back to the reload. Injected nodes simply
|
|
1565
|
+
// never match, so they neither anchor nor block anything.
|
|
1566
|
+
`${declare} liveByNew = [];`,
|
|
1567
|
+
`${mutable} searchFrom = 0;`,
|
|
1568
|
+
`for (${mutable} i = 0; i < newChildren.length; i++) {`,
|
|
1569
|
+
Template.indent([
|
|
1570
|
+
"if (added.indexOf(newChildren[i]) !== -1) { liveByNew.push(null); continue; }",
|
|
1571
|
+
`${declare} key = newChildren[i].outerHTML;`,
|
|
1572
|
+
`${mutable} match = null;`,
|
|
1573
|
+
`for (${mutable} j = searchFrom; j < document.head.children.length; j++) {`,
|
|
1574
|
+
Template.indent([
|
|
1575
|
+
`${declare} child = document.head.children[j];`,
|
|
1576
|
+
"if (child.outerHTML === key) { match = child; searchFrom = j + 1; break; }"
|
|
1577
|
+
]),
|
|
1578
|
+
"}",
|
|
1579
|
+
"if (match === null) return false;",
|
|
1580
|
+
"liveByNew.push(match);"
|
|
1581
|
+
]),
|
|
1582
|
+
"}",
|
|
1583
|
+
// Back to front, so the element an addition must precede is
|
|
1584
|
+
// already placed by the time it is needed.
|
|
1585
|
+
`for (${mutable} i = newChildren.length - 1; i >= 0; i--) {`,
|
|
1586
|
+
Template.indent([
|
|
1587
|
+
"if (liveByNew[i] !== null) continue;",
|
|
1588
|
+
`${mutable} anchor = null;`,
|
|
1589
|
+
`for (${mutable} j = i + 1; j < newChildren.length; j++) {`,
|
|
1590
|
+
Template.indent(
|
|
1591
|
+
"if (liveByNew[j] !== null) { anchor = liveByNew[j]; break; }"
|
|
1592
|
+
),
|
|
1593
|
+
"}",
|
|
1594
|
+
`${declare} node = __webpack_revive_script__(newChildren[i]);`,
|
|
1595
|
+
"if (anchor === null) document.head.appendChild(node);",
|
|
1596
|
+
"else document.head.insertBefore(node, anchor);",
|
|
1597
|
+
"liveByNew[i] = node;"
|
|
1598
|
+
]),
|
|
1599
|
+
"}",
|
|
1600
|
+
"return true;"
|
|
1601
|
+
]
|
|
1602
|
+
)};`,
|
|
1392
1603
|
"if (module.hot.data && typeof document !== 'undefined') {",
|
|
1393
1604
|
Template.indent([
|
|
1394
1605
|
`${declare} __webpack_new_head__ = __webpack_extract_head__();`,
|
|
1395
|
-
"if (module.hot.data.__webpack_head__ !== undefined && __webpack_new_head__ !== module.hot.data.__webpack_head__ && typeof window !== 'undefined' && window.location && typeof window.location.reload === 'function') {",
|
|
1606
|
+
"if (module.hot.data.__webpack_head__ !== undefined && __webpack_new_head__ !== module.hot.data.__webpack_head__ && !__webpack_patch_head__(module.hot.data.__webpack_head__, __webpack_new_head__) && typeof window !== 'undefined' && window.location && typeof window.location.reload === 'function') {",
|
|
1396
1607
|
Template.indent("window.location.reload();"),
|
|
1397
1608
|
"} else {",
|
|
1398
1609
|
Template.indent([
|
|
@@ -1437,7 +1648,7 @@ class HtmlGenerator extends Generator {
|
|
|
1437
1648
|
.replace(/-{2,}/g, (m) => `${"-".repeat(m.length - 1)} `);
|
|
1438
1649
|
return new RawSource(`<!-- webpack error: ${safe} -->`);
|
|
1439
1650
|
}
|
|
1440
|
-
return new RawSource(
|
|
1651
|
+
return new RawSource(Generator.throwBuildErrorCode(error));
|
|
1441
1652
|
}
|
|
1442
1653
|
|
|
1443
1654
|
/**
|
|
@@ -1464,6 +1675,15 @@ class HtmlGenerator extends Generator {
|
|
|
1464
1675
|
if (updateHashContext.module.hot) {
|
|
1465
1676
|
hash.update("hot");
|
|
1466
1677
|
}
|
|
1678
|
+
// A `renderEmbeddedSource` tap has to reach the codegen cache key, or a
|
|
1679
|
+
// changed option replays the output from before it.
|
|
1680
|
+
const { runtimeTemplate } = updateHashContext;
|
|
1681
|
+
if (runtimeTemplate) {
|
|
1682
|
+
runtimeTemplate.compilation.hooks.embeddedSourceHash.call(
|
|
1683
|
+
updateHashContext.module,
|
|
1684
|
+
hash
|
|
1685
|
+
);
|
|
1686
|
+
}
|
|
1467
1687
|
}
|
|
1468
1688
|
}
|
|
1469
1689
|
|
package/lib/html/HtmlModule.js
CHANGED
|
@@ -7,9 +7,13 @@
|
|
|
7
7
|
const NormalModule = require("../NormalModule");
|
|
8
8
|
const makeSerializable = require("../util/makeSerializable");
|
|
9
9
|
|
|
10
|
-
/**
|
|
11
|
-
|
|
12
|
-
|
|
10
|
+
/**
|
|
11
|
+
* @import {
|
|
12
|
+
* NormalModuleBuildInfo,
|
|
13
|
+
* NormalModuleCreateData
|
|
14
|
+
* } from "../NormalModule"
|
|
15
|
+
*/
|
|
16
|
+
/** @import { HtmlEntryInfo } from "./HtmlModulesPlugin" */
|
|
13
17
|
|
|
14
18
|
/**
|
|
15
19
|
* Defines the build info properties specific to html modules.
|