webpack 5.107.1 → 5.108.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/hot/dev-server.js +2 -0
- package/lib/APIPlugin.js +8 -4
- package/lib/CacheFacade.js +7 -0
- package/lib/Chunk.js +4 -0
- package/lib/ChunkGraph.js +30 -9
- package/lib/CircularModulesPlugin.js +190 -0
- package/lib/CleanPlugin.js +2 -1
- package/lib/Compilation.js +396 -65
- package/lib/Compiler.js +52 -14
- package/lib/ConcatenationScope.js +10 -3
- package/lib/ContextExclusionPlugin.js +1 -0
- package/lib/ContextModule.js +92 -47
- package/lib/ContextModuleFactory.js +45 -38
- package/lib/ContextReplacementPlugin.js +4 -0
- package/lib/DefinePlugin.js +89 -15
- package/lib/Dependency.js +111 -7
- package/lib/EntryOptionPlugin.js +39 -2
- package/lib/EntryPlugin.js +2 -0
- package/lib/ExportsInfo.js +314 -73
- package/lib/ExternalModule.js +82 -34
- package/lib/ExternalModuleFactoryPlugin.js +1 -0
- package/lib/ExternalsPlugin.js +1 -0
- package/lib/FileSystemInfo.js +173 -23
- package/lib/FlagAllModulesAsUsedPlugin.js +1 -5
- package/lib/FlagDependencyExportsPlugin.js +23 -0
- package/lib/FlagDependencyUsagePlugin.js +87 -5
- package/lib/FlagEntryExportAsUsedPlugin.js +2 -0
- package/lib/Generator.js +8 -0
- package/lib/HotModuleReplacementPlugin.js +65 -28
- package/lib/IgnorePlugin.js +1 -0
- package/lib/InitFragment.js +5 -0
- package/lib/JavascriptMetaInfoPlugin.js +7 -5
- package/lib/LazyBarrel.js +361 -0
- package/lib/LoaderTargetPlugin.js +1 -0
- package/lib/Module.js +21 -42
- package/lib/ModuleGraph.js +3 -2
- package/lib/ModuleProfile.js +27 -1
- package/lib/ModuleTemplate.js +2 -0
- package/lib/MultiCompiler.js +16 -0
- package/lib/MultiStats.js +1 -0
- package/lib/MultiWatching.js +2 -0
- package/lib/NodeStuffPlugin.js +22 -17
- package/lib/NormalModule.js +557 -77
- package/lib/NormalModuleReplacementPlugin.js +2 -0
- package/lib/PrefetchPlugin.js +2 -0
- package/lib/ProgressPlugin.js +9 -1
- package/lib/ProvidePlugin.js +1 -0
- package/lib/RawModule.js +20 -16
- package/lib/RecordIdsPlugin.js +1 -0
- package/lib/RuntimeGlobals.js +5 -0
- package/lib/RuntimePlugin.js +58 -26
- package/lib/RuntimeTemplate.js +278 -21
- package/lib/SelfModuleFactory.js +1 -0
- package/lib/SourceMapDevToolPlugin.js +105 -30
- package/lib/Stats.js +1 -0
- package/lib/Template.js +8 -2
- package/lib/TemplatedPathPlugin.js +473 -131
- package/lib/WarnCaseSensitiveModulesPlugin.js +1 -0
- package/lib/WarnDeprecatedOptionPlugin.js +4 -0
- package/lib/WarnNoModeSetPlugin.js +1 -0
- package/lib/WatchIgnorePlugin.js +1 -0
- package/lib/Watching.js +9 -0
- package/lib/WebpackOptionsApply.js +50 -5
- package/lib/asset/AssetBytesGenerator.js +11 -3
- package/lib/asset/AssetGenerator.js +47 -22
- package/lib/asset/AssetModule.js +47 -0
- package/lib/asset/AssetModulesPlugin.js +14 -14
- package/lib/asset/AssetParser.js +2 -2
- package/lib/asset/AssetSourceGenerator.js +8 -0
- package/lib/asset/RawDataUrlModule.js +12 -13
- package/lib/buildChunkGraph.js +88 -9
- package/lib/bun/BunTargetPlugin.js +48 -0
- package/lib/cache/AddBuildDependenciesPlugin.js +1 -0
- package/lib/cache/AddManagedPathsPlugin.js +3 -0
- package/lib/cache/IdleFileCachePlugin.js +4 -0
- package/lib/cache/MemoryWithGcCachePlugin.js +1 -0
- package/lib/cache/PackFileCacheStrategy.js +1 -0
- package/lib/cache/ResolverCachePlugin.js +2 -0
- package/lib/cache/getLazyHashedEtag.js +9 -2
- package/lib/cache/mergeEtags.js +2 -0
- package/lib/cli.js +109 -19
- package/lib/config/browserslistTargetHandler.js +99 -0
- package/lib/config/defaults.js +147 -7
- package/lib/config/defineConfig.js +31 -0
- package/lib/config/normalization.js +5 -0
- package/lib/config/target.js +181 -2
- package/lib/container/ContainerEntryModule.js +15 -14
- package/lib/container/ContainerExposedDependency.js +2 -2
- package/lib/container/ContainerReferencePlugin.js +1 -1
- package/lib/container/FallbackDependency.js +5 -7
- package/lib/container/FallbackModule.js +10 -9
- package/lib/container/RemoteModule.js +20 -10
- package/lib/container/RemoteRuntimeModule.js +14 -12
- package/lib/css/CssGenerator.js +353 -327
- package/lib/css/CssInjectStyleRuntimeModule.js +36 -8
- package/lib/css/CssLoadingRuntimeModule.js +118 -47
- package/lib/css/CssModule.js +52 -23
- package/lib/css/CssModulesPlugin.js +107 -124
- package/lib/css/CssParser.js +2759 -2205
- package/lib/css/syntax.js +2859 -0
- package/lib/debug/ProfilingPlugin.js +2 -0
- package/lib/deno/DenoTargetPlugin.js +47 -0
- package/lib/dependencies/AMDDefineDependency.js +22 -17
- package/lib/dependencies/AMDDefineDependencyParserPlugin.js +1 -0
- package/lib/dependencies/AMDRequireArrayDependency.js +7 -11
- package/lib/dependencies/AMDRequireContextDependency.js +7 -11
- package/lib/dependencies/AMDRequireDependenciesBlockParserPlugin.js +1 -0
- package/lib/dependencies/AMDRequireDependency.js +24 -20
- package/lib/dependencies/CachedConstDependency.js +3 -0
- package/lib/dependencies/CommonJsDependencyHelpers.js +1 -0
- package/lib/dependencies/CommonJsExportRequireDependency.js +79 -31
- package/lib/dependencies/CommonJsExportsDependency.js +21 -16
- package/lib/dependencies/CommonJsExportsParserPlugin.js +230 -7
- package/lib/dependencies/CommonJsFullRequireDependency.js +27 -19
- package/lib/dependencies/CommonJsImportsParserPlugin.js +51 -16
- package/lib/dependencies/CommonJsPlugin.js +1 -1
- package/lib/dependencies/CommonJsRequireContextDependency.js +10 -13
- package/lib/dependencies/CommonJsRequireDependency.js +42 -11
- package/lib/dependencies/CommonJsSelfReferenceDependency.js +22 -14
- package/lib/dependencies/ConstDependency.js +16 -11
- package/lib/dependencies/ContextDependency.js +4 -0
- package/lib/dependencies/ContextDependencyTemplateAsId.js +1 -1
- package/lib/dependencies/ContextElementDependency.js +23 -14
- package/lib/dependencies/CreateRequireParserPlugin.js +1 -0
- package/lib/dependencies/CreateScriptUrlDependency.js +5 -7
- package/lib/dependencies/CriticalDependencyWarning.js +1 -0
- package/lib/dependencies/CssIcssExportDependency.js +512 -574
- package/lib/dependencies/CssIcssImportDependency.js +9 -9
- package/lib/dependencies/CssIcssSymbolDependency.js +22 -15
- package/lib/dependencies/CssImportDependency.js +25 -1
- package/lib/dependencies/CssUrlDependency.js +23 -14
- package/lib/dependencies/DllEntryDependency.js +9 -13
- package/lib/dependencies/ExportBindingInitFragment.js +164 -0
- package/lib/dependencies/ExportsInfoDependency.js +12 -12
- package/lib/dependencies/ExternalModuleDependency.js +8 -5
- package/lib/dependencies/ExternalModuleInitFragment.js +7 -5
- package/lib/dependencies/ExternalModuleInitFragmentDependency.js +13 -10
- package/lib/dependencies/HarmonyAcceptDependency.js +11 -11
- package/lib/dependencies/HarmonyAcceptImportDependency.js +1 -0
- package/lib/dependencies/HarmonyDetectionParserPlugin.js +47 -22
- package/lib/dependencies/HarmonyEvaluatedImportSpecifierDependency.js +28 -2
- package/lib/dependencies/HarmonyExportDependencyParserPlugin.js +46 -22
- package/lib/dependencies/HarmonyExportExpressionDependency.js +107 -30
- package/lib/dependencies/HarmonyExportHeaderDependency.js +7 -9
- package/lib/dependencies/HarmonyExportImportedSpecifierDependency.js +109 -31
- package/lib/dependencies/HarmonyExportInitFragment.js +22 -20
- package/lib/dependencies/HarmonyExportSpecifierDependency.js +83 -18
- package/lib/dependencies/HarmonyExports.js +4 -1
- package/lib/dependencies/HarmonyImportDependency.js +24 -0
- package/lib/dependencies/HarmonyImportDependencyParserPlugin.js +110 -74
- package/lib/dependencies/HarmonyImportGuard.js +254 -0
- package/lib/dependencies/HarmonyImportSideEffectDependency.js +18 -1
- package/lib/dependencies/HarmonyImportSpecifierDependency.js +118 -14
- package/lib/dependencies/HarmonyLinkingError.js +1 -0
- package/lib/dependencies/HarmonyModulesPlugin.js +1 -0
- package/lib/dependencies/{HtmlScriptSrcDependency.js → HtmlEntryDependency.js} +267 -154
- package/lib/dependencies/HtmlInlineHtmlDependency.js +107 -0
- package/lib/dependencies/HtmlInlineScriptDependency.js +20 -27
- package/lib/dependencies/HtmlInlineStyleDependency.js +62 -11
- package/lib/dependencies/HtmlSourceDependency.js +18 -0
- package/lib/dependencies/ImportContextDependency.js +5 -9
- package/lib/dependencies/ImportDependency.js +44 -2
- package/lib/dependencies/ImportMetaHotAcceptDependency.js +1 -0
- package/lib/dependencies/ImportMetaHotDeclineDependency.js +1 -0
- package/lib/dependencies/ImportMetaPlugin.js +74 -30
- package/lib/dependencies/ImportParserPlugin.js +19 -0
- package/lib/dependencies/ImportWeakDependency.js +1 -0
- package/lib/dependencies/JsonExportsDependency.js +9 -9
- package/lib/dependencies/LoaderImportDependency.js +1 -0
- package/lib/dependencies/LocalModule.js +11 -12
- package/lib/dependencies/LocalModuleDependency.js +11 -13
- package/lib/dependencies/ModuleDecoratorDependency.js +9 -9
- package/lib/dependencies/ModuleDependency.js +7 -0
- package/lib/dependencies/ModuleHotAcceptDependency.js +1 -0
- package/lib/dependencies/ModuleHotDeclineDependency.js +1 -0
- package/lib/dependencies/ModuleInitFragmentDependency.js +15 -11
- package/lib/dependencies/ProvidedDependency.js +31 -27
- package/lib/dependencies/PureExpressionDependency.js +7 -9
- package/lib/dependencies/RequireEnsureDependency.js +12 -13
- package/lib/dependencies/RequireHeaderDependency.js +3 -4
- package/lib/dependencies/RequireIncludeDependencyParserPlugin.js +3 -0
- package/lib/dependencies/RequireResolveContextDependency.js +7 -11
- package/lib/dependencies/RequireResolveDependency.js +1 -0
- package/lib/dependencies/RequireResolveHeaderDependency.js +3 -5
- package/lib/dependencies/RuntimeRequirementsDependency.js +6 -7
- package/lib/dependencies/StaticExportsDependency.js +10 -10
- package/lib/dependencies/SystemPlugin.js +2 -0
- package/lib/dependencies/URLContextDependency.js +5 -7
- package/lib/dependencies/URLDependency.js +14 -16
- package/lib/dependencies/UnsupportedDependency.js +8 -13
- package/lib/dependencies/WebAssemblyExportImportedDependency.js +11 -16
- package/lib/dependencies/WebAssemblyImportDependency.js +14 -16
- package/lib/dependencies/WebpackIsIncludedDependency.js +1 -0
- package/lib/dependencies/WorkerDependency.js +19 -8
- package/lib/dependencies/WorkerPlugin.js +40 -10
- package/lib/dependencies/processExportInfo.js +13 -11
- package/lib/dll/DelegatedModule.js +29 -15
- package/lib/dll/DelegatedModuleFactoryPlugin.js +1 -0
- package/lib/dll/DelegatedPlugin.js +1 -0
- package/lib/dll/DllEntryPlugin.js +3 -0
- package/lib/dll/DllModule.js +3 -2
- package/lib/dll/DllPlugin.js +16 -0
- package/lib/dll/DllReferencePlugin.js +3 -0
- package/lib/dll/LibManifestPlugin.js +1 -0
- package/lib/electron/ElectronTargetPlugin.js +22 -4
- package/lib/errors/ConcurrentCompilationError.js +1 -0
- package/lib/errors/HookWebpackError.js +11 -13
- package/lib/errors/IgnoreErrorModuleFactory.js +1 -0
- package/lib/errors/InvalidDependenciesModuleWarning.js +2 -0
- package/lib/errors/JSONParseError.js +9 -8
- package/lib/errors/ModuleBuildError.js +16 -13
- package/lib/errors/ModuleDependencyError.js +8 -1
- package/lib/errors/ModuleDependencyWarning.js +8 -1
- package/lib/errors/ModuleError.js +5 -11
- package/lib/errors/ModuleHashingError.js +4 -0
- package/lib/errors/ModuleNotFoundError.js +3 -0
- package/lib/errors/ModuleParseError.js +5 -11
- package/lib/errors/ModuleRestoreError.js +2 -0
- package/lib/errors/ModuleStoreError.js +3 -0
- package/lib/errors/ModuleWarning.js +7 -11
- package/lib/errors/NodeStuffInWebError.js +1 -0
- package/lib/errors/NonErrorEmittedError.js +2 -0
- package/lib/errors/UnhandledSchemeError.js +1 -0
- package/lib/esm/ModuleChunkLoadingPlugin.js +0 -1
- package/lib/esm/ModuleChunkLoadingRuntimeModule.js +28 -23
- package/lib/hmr/HotModuleReplacement.runtime.js +175 -30
- package/lib/hmr/HotModuleReplacementRuntimeModule.js +7 -0
- package/lib/hmr/JavascriptHotModuleReplacement.runtime.js +173 -26
- package/lib/hmr/LazyCompilationPlugin.js +134 -6
- package/lib/html/HtmlGenerator.js +292 -50
- package/lib/html/HtmlModule.js +40 -0
- package/lib/html/HtmlModulesPlugin.js +287 -60
- package/lib/html/HtmlParser.js +1108 -1099
- package/lib/html/{walkHtmlTokens.js → syntax.js} +4701 -212
- package/lib/ids/IdHelpers.js +4 -2
- package/lib/index.js +19 -0
- package/lib/javascript/BasicEvaluatedExpression.js +1 -0
- package/lib/javascript/EnableChunkLoadingPlugin.js +1 -0
- package/lib/javascript/JavascriptGenerator.js +6 -2
- package/lib/javascript/JavascriptModule.js +54 -0
- package/lib/javascript/JavascriptModulesPlugin.js +257 -102
- package/lib/javascript/JavascriptParser.js +286 -159
- package/lib/json/JsonModule.js +40 -0
- package/lib/json/JsonModulesPlugin.js +7 -0
- package/lib/json/JsonParser.js +4 -2
- package/lib/library/AssignLibraryPlugin.js +5 -3
- package/lib/library/ExportPropertyLibraryPlugin.js +1 -0
- package/lib/library/FalseIIFEUmdWarning.js +1 -0
- package/lib/library/ModuleLibraryPlugin.js +54 -29
- package/lib/library/SystemLibraryPlugin.js +3 -3
- package/lib/node/NodeTargetPlugin.js +1 -0
- package/lib/node/NodeWatchFileSystem.js +38 -22
- package/lib/node/ReadFileChunkLoadingRuntimeModule.js +10 -9
- package/lib/node/RequireChunkLoadingRuntimeModule.js +18 -16
- package/lib/optimize/ConcatenatedModule.js +397 -78
- package/lib/optimize/ConstExportsPlugin.js +211 -0
- package/lib/optimize/InlineExports.js +178 -0
- package/lib/optimize/InnerGraph.js +372 -275
- package/lib/optimize/InnerGraphPlugin.js +196 -99
- package/lib/optimize/ModuleConcatenationPlugin.js +56 -25
- package/lib/optimize/RealContentHashPlugin.js +14 -1
- package/lib/optimize/SideEffectsFlagPlugin.js +234 -64
- package/lib/runtime/AsyncModuleRuntimeModule.js +32 -30
- package/lib/runtime/AutoPublicPathRuntimeModule.js +11 -5
- package/lib/runtime/CompatGetDefaultExportRuntimeModule.js +1 -1
- package/lib/runtime/CreateFakeNamespaceObjectRuntimeModule.js +6 -4
- package/lib/runtime/DefinePropertyGettersRuntimeModule.js +33 -4
- package/lib/runtime/GetChunkFilenameRuntimeModule.js +82 -3
- package/lib/runtime/GetTrustedTypesPolicyRuntimeModule.js +1 -1
- package/lib/runtime/HasOwnPropertyRuntimeModule.js +1 -1
- package/lib/runtime/LoadScriptRuntimeModule.js +18 -13
- package/lib/runtime/MakeDeferredNamespaceObjectRuntime.js +39 -26
- package/lib/runtime/MakeNamespaceObjectRuntimeModule.js +1 -1
- package/lib/runtime/OnChunksLoadedRuntimeModule.js +4 -4
- package/lib/runtime/RelativeUrlRuntimeModule.js +3 -2
- package/lib/runtime/StartupChunkDependenciesRuntimeModule.js +1 -1
- package/lib/runtime/StartupEntrypointRuntimeModule.js +4 -3
- package/lib/runtime/WorkerRuntimeModule.js +33 -0
- package/lib/schemes/HttpUriPlugin.js +3 -2
- package/lib/serialization/AggregateErrorSerializer.js +7 -6
- package/lib/serialization/ArraySerializer.js +4 -8
- package/lib/serialization/BinaryMiddleware.js +538 -468
- package/lib/serialization/DateObjectSerializer.js +2 -2
- package/lib/serialization/ErrorObjectSerializer.js +7 -6
- package/lib/serialization/MapObjectSerializer.js +5 -9
- package/lib/serialization/NullPrototypeObjectSerializer.js +7 -9
- package/lib/serialization/ObjectMiddleware.js +50 -13
- package/lib/serialization/PlainObjectSerializer.js +9 -8
- package/lib/serialization/RegExpObjectSerializer.js +2 -2
- package/lib/serialization/Serializer.js +1 -0
- package/lib/serialization/SetObjectSerializer.js +4 -8
- package/lib/sharing/ConsumeSharedModule.js +6 -7
- package/lib/sharing/ConsumeSharedPlugin.js +1 -0
- package/lib/sharing/ConsumeSharedRuntimeModule.js +46 -41
- package/lib/sharing/ProvideSharedDependency.js +30 -15
- package/lib/sharing/ProvideSharedModule.js +30 -11
- package/lib/sharing/ProvideSharedPlugin.js +4 -2
- package/lib/sharing/SharePlugin.js +3 -0
- package/lib/sharing/ShareRuntimeModule.js +18 -16
- package/lib/sharing/resolveMatchedConfigs.js +2 -1
- package/lib/sharing/utils.js +1 -1
- package/lib/stats/DefaultStatsFactoryPlugin.js +4 -6
- package/lib/stats/DefaultStatsPrinterPlugin.js +14 -14
- package/lib/stats/StatsFactory.js +11 -9
- package/lib/stats/StatsPrinter.js +9 -2
- package/lib/url/URLParserPlugin.js +5 -2
- package/lib/util/AsyncQueue.js +10 -0
- package/lib/util/LazyBucketSortedSet.js +5 -0
- package/lib/util/LazySet.js +6 -4
- package/lib/util/LocConverter.js +11 -1
- package/lib/util/Semaphore.js +1 -0
- package/lib/util/SourceProcessor.js +106 -0
- package/lib/util/TupleSet.js +1 -0
- package/lib/util/WeakTupleMap.js +27 -1
- package/lib/util/chainedImports.js +3 -3
- package/lib/util/comparators.js +2 -2
- package/lib/util/concatenate.js +31 -7
- package/lib/util/createHash.js +0 -1
- package/lib/util/deterministicGrouping.js +19 -12
- package/lib/util/extractSourceMap.js +1 -1
- package/lib/util/findGraphRoots.js +2 -0
- package/lib/util/fs.js +16 -6
- package/lib/util/hash/DebugHash.js +1 -0
- package/lib/util/hash/hash-digest.js +24 -15
- package/lib/util/identifier.js +7 -0
- package/lib/util/internalSerializables.js +11 -2
- package/lib/util/magicComment.js +42 -0
- package/lib/util/makeSerializable.js +1 -0
- package/lib/util/nonNumericOnlyHash.js +30 -1
- package/lib/util/property.js +7 -1
- package/lib/util/publicPathPlaceholder.js +64 -0
- package/lib/util/registerExternalSerializer.js +4 -4
- package/lib/wasm-async/AsyncWasmModule.js +77 -0
- package/lib/wasm-async/AsyncWebAssemblyJavascriptGenerator.js +1 -1
- package/lib/wasm-async/AsyncWebAssemblyModulesPlugin.js +1 -96
- package/lib/wasm-async/AsyncWebAssemblyParser.js +1 -1
- package/lib/wasm-async/UniversalCompileAsyncWasmPlugin.js +1 -1
- package/lib/wasm-sync/SyncWasmModule.js +39 -0
- package/lib/wasm-sync/UnsupportedWebAssemblyFeatureError.js +1 -0
- package/lib/wasm-sync/WasmChunkLoadingRuntimeModule.js +6 -3
- package/lib/wasm-sync/WasmFinalizeExportsPlugin.js +2 -1
- package/lib/wasm-sync/WebAssemblyGenerator.js +1 -0
- package/lib/wasm-sync/WebAssemblyInInitialChunkError.js +2 -0
- package/lib/wasm-sync/WebAssemblyModulesPlugin.js +10 -0
- package/lib/wasm-sync/WebAssemblyParser.js +7 -3
- package/lib/web/JsonpChunkLoadingRuntimeModule.js +45 -39
- package/lib/webworker/ImportScriptsChunkLoadingRuntimeModule.js +11 -10
- package/package.json +36 -28
- package/schemas/WebpackOptions.check.js +1 -1
- package/schemas/WebpackOptions.json +212 -3
- package/schemas/plugins/HtmlGeneratorOptions.check.js +1 -1
- package/schemas/plugins/HtmlParserOptions.check.d.ts +7 -0
- package/schemas/plugins/HtmlParserOptions.check.js +6 -0
- package/schemas/plugins/HtmlParserOptions.json +3 -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 +1592 -314
- package/lib/css/walkCssTokens.js +0 -2020
- package/lib/util/AppendOnlyStackedSet.js +0 -93
|
@@ -9,8 +9,8 @@ const {
|
|
|
9
9
|
CSS_TYPE,
|
|
10
10
|
JAVASCRIPT_TYPE
|
|
11
11
|
} = require("../ModuleSourceTypeConstants");
|
|
12
|
+
const HtmlGenerator = require("../html/HtmlGenerator");
|
|
12
13
|
const makeSerializable = require("../util/makeSerializable");
|
|
13
|
-
const CssUrlDependency = require("./CssUrlDependency");
|
|
14
14
|
const ModuleDependency = require("./ModuleDependency");
|
|
15
15
|
|
|
16
16
|
/** @typedef {import("webpack-sources").ReplaceSource} ReplaceSource */
|
|
@@ -20,21 +20,28 @@ const ModuleDependency = require("./ModuleDependency");
|
|
|
20
20
|
/** @typedef {import("../DependencyTemplate").DependencyTemplateContext} DependencyTemplateContext */
|
|
21
21
|
/** @typedef {import("../Entrypoint")} Entrypoint */
|
|
22
22
|
/** @typedef {import("../javascript/JavascriptParser").Range} Range */
|
|
23
|
-
/** @typedef {
|
|
24
|
-
/** @typedef {import("../serialization/ObjectMiddleware").ObjectSerializerContext} ObjectSerializerContext */
|
|
23
|
+
/** @typedef {"script" | "script-module" | "modulepreload" | "stylesheet"} HtmlEntryElementKind */
|
|
25
24
|
|
|
26
|
-
/** @typedef {"
|
|
25
|
+
/** @typedef {import("../serialization/ObjectMiddleware").ObjectDeserializerContext<[string, string, HtmlEntryElementKind, number, number, boolean, string, number, boolean, number, (Range | null), (Range | null)]>} ObjectDeserializerContext */
|
|
26
|
+
/** @typedef {import("../serialization/ObjectMiddleware").ObjectSerializerContext<[string, string, HtmlEntryElementKind, number, number, boolean, string, number, boolean, number, (Range | null), (Range | null)]>} ObjectSerializerContext */
|
|
27
27
|
|
|
28
|
-
class
|
|
28
|
+
class HtmlEntryDependency extends ModuleDependency {
|
|
29
29
|
/**
|
|
30
|
-
* Creates an instance of
|
|
30
|
+
* Creates an instance of HtmlEntryDependency.
|
|
31
31
|
* @param {string} request request
|
|
32
32
|
* @param {Range} range range of the attribute value in the source
|
|
33
33
|
* @param {string} entryName name of the entry this script src is bundled into
|
|
34
34
|
* @param {string=} category dependency category used for resolving and grouping
|
|
35
|
-
* @param {
|
|
35
|
+
* @param {HtmlEntryElementKind=} elementKind shape of the originating HTML element; used when expanding sibling tags for split/runtime chunks
|
|
36
36
|
* @param {number=} tagStart position of the opening `<` of the originating tag in the source; sibling tags emitted for additional entry chunks are inserted right before this
|
|
37
37
|
* @param {number=} tagOpenEnd position of the character immediately after the opening tag's `>` in the source; combined with `tagStart` this lets the template clone the original opening tag verbatim (preserving attributes like `nonce`, `crossorigin`, `referrerpolicy`, `defer`, `async`) when generating sibling tags
|
|
38
|
+
* @param {boolean=} tagIsNative whether the originating element is the native tag for `elementKind` (`<script>` / `<link>`); decided at parse time from the tag name so the template needn't re-parse the source text. A custom element mapped to a `script`/`stylesheet` source `type` is non-native and gets a freshly synthesized sibling tag instead of a verbatim clone
|
|
39
|
+
* @param {string=} copyableAttrsText the originating tag's `nonce`/`crossorigin`/`referrerpolicy` attribute source spans (leading-space-prefixed, in that fixed order), captured at parse time so synthesized sibling `<link>`/`<script>` tags carry the same CSP/fetch policy without the template re-parsing the tag text; empty when none are present
|
|
40
|
+
* @param {number=} tagNameEnd position right after the originating tag's name (e.g. after `<script`), captured at parse time so the template can insert a `crossorigin` attribute without re-scanning the tag text for the name boundary
|
|
41
|
+
* @param {boolean=} hasOwnCrossOrigin whether the originating tag already carries a `crossorigin` attribute; when true the author's value wins and `output.crossOriginLoading` is not applied
|
|
42
|
+
* @param {number=} cssAnchor source offset of the first `<script>` tag; a later entry's injected stylesheet `<link>`s are inserted here so CSS loads before any script. -1 when the document has no script
|
|
43
|
+
* @param {Range | null=} integrityRange source span of the originating tag's `integrity` attribute (offsets relative to `tagStart`, leading whitespace and quotes included), captured at parse time so cloned sibling tags can drop it without re-parsing; null when absent
|
|
44
|
+
* @param {Range | null=} typeValueRange source span of the originating tag's `type` attribute value (offsets relative to `tagStart`), captured at parse time so `script-module` sibling clones can force `type="module"` in place; null when there is no value to rewrite (a `type="module"` is then inserted instead)
|
|
38
45
|
*/
|
|
39
46
|
constructor(
|
|
40
47
|
request,
|
|
@@ -43,23 +50,45 @@ class HtmlScriptSrcDependency extends ModuleDependency {
|
|
|
43
50
|
category,
|
|
44
51
|
elementKind,
|
|
45
52
|
tagStart,
|
|
46
|
-
tagOpenEnd
|
|
53
|
+
tagOpenEnd,
|
|
54
|
+
tagIsNative,
|
|
55
|
+
copyableAttrsText,
|
|
56
|
+
tagNameEnd,
|
|
57
|
+
hasOwnCrossOrigin,
|
|
58
|
+
cssAnchor,
|
|
59
|
+
integrityRange,
|
|
60
|
+
typeValueRange
|
|
47
61
|
) {
|
|
48
62
|
super(request);
|
|
49
63
|
this.range = range;
|
|
64
|
+
/** @type {string} */
|
|
50
65
|
this.entryName = entryName;
|
|
51
66
|
/** @type {string} */
|
|
52
67
|
this._category = category || "commonjs";
|
|
53
|
-
/** @type {
|
|
54
|
-
this.elementKind = elementKind || "script
|
|
68
|
+
/** @type {HtmlEntryElementKind} */
|
|
69
|
+
this.elementKind = elementKind || "script";
|
|
55
70
|
/** @type {number} */
|
|
56
71
|
this.tagStart = tagStart === undefined ? -1 : tagStart;
|
|
57
72
|
/** @type {number} */
|
|
58
73
|
this.tagOpenEnd = tagOpenEnd === undefined ? -1 : tagOpenEnd;
|
|
74
|
+
/** @type {boolean} */
|
|
75
|
+
this.tagIsNative = tagIsNative !== false;
|
|
76
|
+
/** @type {string} */
|
|
77
|
+
this.copyableAttrsText = copyableAttrsText || "";
|
|
78
|
+
/** @type {number} */
|
|
79
|
+
this.tagNameEnd = tagNameEnd === undefined ? -1 : tagNameEnd;
|
|
80
|
+
/** @type {boolean} */
|
|
81
|
+
this.hasOwnCrossOrigin = hasOwnCrossOrigin === true;
|
|
82
|
+
/** @type {number} */
|
|
83
|
+
this.cssAnchor = cssAnchor === undefined ? -1 : cssAnchor;
|
|
84
|
+
/** @type {Range | null} */
|
|
85
|
+
this.integrityRange = integrityRange || null;
|
|
86
|
+
/** @type {Range | null} */
|
|
87
|
+
this.typeValueRange = typeValueRange || null;
|
|
59
88
|
}
|
|
60
89
|
|
|
61
90
|
get type() {
|
|
62
|
-
return "html
|
|
91
|
+
return "html entry";
|
|
63
92
|
}
|
|
64
93
|
|
|
65
94
|
get category() {
|
|
@@ -71,12 +100,19 @@ class HtmlScriptSrcDependency extends ModuleDependency {
|
|
|
71
100
|
* @param {ObjectSerializerContext} context context
|
|
72
101
|
*/
|
|
73
102
|
serialize(context) {
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
103
|
+
context
|
|
104
|
+
.write(this.entryName)
|
|
105
|
+
.write(this._category)
|
|
106
|
+
.write(this.elementKind)
|
|
107
|
+
.write(this.tagStart)
|
|
108
|
+
.write(this.tagOpenEnd)
|
|
109
|
+
.write(this.tagIsNative)
|
|
110
|
+
.write(this.copyableAttrsText)
|
|
111
|
+
.write(this.tagNameEnd)
|
|
112
|
+
.write(this.hasOwnCrossOrigin)
|
|
113
|
+
.write(this.cssAnchor)
|
|
114
|
+
.write(this.integrityRange)
|
|
115
|
+
.write(this.typeValueRange);
|
|
80
116
|
super.serialize(context);
|
|
81
117
|
}
|
|
82
118
|
|
|
@@ -85,49 +121,33 @@ class HtmlScriptSrcDependency extends ModuleDependency {
|
|
|
85
121
|
* @param {ObjectDeserializerContext} context context
|
|
86
122
|
*/
|
|
87
123
|
deserialize(context) {
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
this._category = read();
|
|
91
|
-
|
|
92
|
-
this.
|
|
93
|
-
|
|
94
|
-
|
|
124
|
+
this.entryName = context.read();
|
|
125
|
+
const c1 = context.rest;
|
|
126
|
+
this._category = c1.read();
|
|
127
|
+
const c2 = c1.rest;
|
|
128
|
+
this.elementKind = c2.read();
|
|
129
|
+
const c3 = c2.rest;
|
|
130
|
+
this.tagStart = c3.read();
|
|
131
|
+
const c4 = c3.rest;
|
|
132
|
+
this.tagOpenEnd = c4.read();
|
|
133
|
+
const c5 = c4.rest;
|
|
134
|
+
this.tagIsNative = c5.read();
|
|
135
|
+
const c6 = c5.rest;
|
|
136
|
+
this.copyableAttrsText = c6.read();
|
|
137
|
+
const c7 = c6.rest;
|
|
138
|
+
this.tagNameEnd = c7.read();
|
|
139
|
+
const c8 = c7.rest;
|
|
140
|
+
this.hasOwnCrossOrigin = c8.read();
|
|
141
|
+
const c9 = c8.rest;
|
|
142
|
+
this.cssAnchor = c9.read();
|
|
143
|
+
const c10 = c9.rest;
|
|
144
|
+
this.integrityRange = c10.read();
|
|
145
|
+
const c11 = c10.rest;
|
|
146
|
+
this.typeValueRange = c11.read();
|
|
147
|
+
super.deserialize(c11.rest);
|
|
95
148
|
}
|
|
96
149
|
}
|
|
97
150
|
|
|
98
|
-
/**
|
|
99
|
-
* @param {Chunk} chunk a chunk
|
|
100
|
-
* @param {import("../Compilation")} compilation compilation
|
|
101
|
-
* @param {"javascript" | "css"} contentHashType which content hash to plug into the filename template
|
|
102
|
-
* @returns {string} chunk filename path (no public-path prefix)
|
|
103
|
-
*/
|
|
104
|
-
const getChunkFilename = (chunk, compilation, contentHashType) => {
|
|
105
|
-
const outputOptions = compilation.outputOptions;
|
|
106
|
-
let filenameTemplate;
|
|
107
|
-
if (contentHashType === "css") {
|
|
108
|
-
// For a CSS-typed chunk, use the same template the CSS pipeline
|
|
109
|
-
// will use when it actually emits the `.css` file, so the `<link
|
|
110
|
-
// rel="stylesheet" href>` URL we write into the HTML matches the
|
|
111
|
-
// asset on disk.
|
|
112
|
-
filenameTemplate =
|
|
113
|
-
require("../css/CssModulesPlugin").getChunkFilenameTemplate(
|
|
114
|
-
chunk,
|
|
115
|
-
outputOptions
|
|
116
|
-
);
|
|
117
|
-
} else {
|
|
118
|
-
filenameTemplate =
|
|
119
|
-
chunk.filenameTemplate ||
|
|
120
|
-
(chunk.canBeInitial()
|
|
121
|
-
? outputOptions.filename
|
|
122
|
-
: outputOptions.chunkFilename);
|
|
123
|
-
}
|
|
124
|
-
|
|
125
|
-
return compilation.getPath(filenameTemplate, {
|
|
126
|
-
chunk,
|
|
127
|
-
contentHashType
|
|
128
|
-
});
|
|
129
|
-
};
|
|
130
|
-
|
|
131
151
|
/**
|
|
132
152
|
* @param {Entrypoint} entrypoint entrypoint
|
|
133
153
|
* @returns {Chunk[]} every chunk this entrypoint needs in load order: the
|
|
@@ -240,27 +260,25 @@ const chunkHasCss = (chunk, chunkGraph) =>
|
|
|
240
260
|
);
|
|
241
261
|
|
|
242
262
|
/**
|
|
243
|
-
*
|
|
244
|
-
* `chunk.
|
|
245
|
-
*
|
|
246
|
-
*
|
|
247
|
-
*
|
|
248
|
-
*
|
|
249
|
-
*
|
|
250
|
-
*
|
|
251
|
-
*
|
|
252
|
-
*
|
|
253
|
-
* @param {Chunk}
|
|
254
|
-
* @
|
|
255
|
-
* @returns {-1 | 0 | 1} ordering
|
|
263
|
+
* Deterministic tie-break key for CSS link ordering. `chunk.name` and
|
|
264
|
+
* `chunk.id` are both stable strings (when present); one of them is set for
|
|
265
|
+
* every chunk webpack emits. We can't rely on `Array.prototype.sort` being
|
|
266
|
+
* stable — webpack still supports Node 10.13 where V8's sort is not guaranteed
|
|
267
|
+
* stable for arrays larger than ten elements — so any time
|
|
268
|
+
* `firstCssModulePostOrderIndex` returns the same value for two chunks (most
|
|
269
|
+
* commonly when several chunks have no reachable CSS module in the entrypoint's
|
|
270
|
+
* dependency walk and all map to `Infinity`) this key picks the canonical order.
|
|
271
|
+
* Computed once per chunk when building the sort array rather than per
|
|
272
|
+
* comparison.
|
|
273
|
+
* @param {Chunk} chunk chunk
|
|
274
|
+
* @returns {string} the tie-break key
|
|
256
275
|
*/
|
|
257
|
-
const
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
};
|
|
276
|
+
const cssChunkSortKey = (chunk) =>
|
|
277
|
+
`${chunk.name || ""} ${
|
|
278
|
+
chunk.id === null || chunk.id === undefined ? "" : chunk.id
|
|
279
|
+
}`;
|
|
280
|
+
|
|
281
|
+
const CSS_SOURCE_TYPES = [CSS_TYPE, CSS_IMPORT_TYPE];
|
|
264
282
|
|
|
265
283
|
/**
|
|
266
284
|
* Smallest post-order index among the CSS modules of a chunk, taken
|
|
@@ -285,7 +303,7 @@ const compareChunksForCssTieBreak = (a, b) => {
|
|
|
285
303
|
*/
|
|
286
304
|
const firstCssModulePostOrderIndex = (chunk, entrypoint, chunkGraph) => {
|
|
287
305
|
let min = Number.POSITIVE_INFINITY;
|
|
288
|
-
for (const sourceType of
|
|
306
|
+
for (const sourceType of CSS_SOURCE_TYPES) {
|
|
289
307
|
const modules = chunkGraph.getChunkModulesIterableBySourceType(
|
|
290
308
|
chunk,
|
|
291
309
|
sourceType
|
|
@@ -299,33 +317,44 @@ const firstCssModulePostOrderIndex = (chunk, entrypoint, chunkGraph) => {
|
|
|
299
317
|
return min;
|
|
300
318
|
};
|
|
301
319
|
|
|
302
|
-
const COPYABLE_LINK_ATTRS = ["nonce", "crossorigin", "referrerpolicy"];
|
|
303
|
-
|
|
304
320
|
/**
|
|
305
321
|
* Build a fresh `<link rel="stylesheet" href="…">` for a CSS chunk that
|
|
306
322
|
* was pulled in by a `<script src>` entry — the originating tag was a
|
|
307
323
|
* `<script>`, but the chunk is CSS so cloning the script tag verbatim
|
|
308
|
-
* would produce nonsense (`<script src="…\.css">`).
|
|
309
|
-
* `nonce`/`crossorigin`/`referrerpolicy`
|
|
310
|
-
* the same CSP and fetch policy applies;
|
|
311
|
-
* meaning on `<link>` and are dropped.
|
|
312
|
-
* @param {string}
|
|
324
|
+
* would produce nonsense (`<script src="…\.css">`). `extra` carries the
|
|
325
|
+
* `nonce`/`crossorigin`/`referrerpolicy` source spans captured from the
|
|
326
|
+
* original element at parse time so the same CSP and fetch policy applies;
|
|
327
|
+
* `defer`/`async`/`type` have no meaning on `<link>` and are dropped.
|
|
328
|
+
* @param {string} extra the copyable CSP/fetch attribute source text (leading-space-prefixed, or empty)
|
|
313
329
|
* @param {string} href URL for the stylesheet
|
|
330
|
+
* @param {string} crossOrigin ` crossorigin="…"` to append from `output.crossOriginLoading`, or `""`
|
|
314
331
|
* @returns {string} the sibling `<link>` tag's HTML
|
|
315
332
|
*/
|
|
316
|
-
const buildStylesheetLink = (
|
|
317
|
-
let extra = "";
|
|
318
|
-
for (const attr of COPYABLE_LINK_ATTRS) {
|
|
319
|
-
// Match ` <attr>`, ` <attr>=value`, ` <attr>="value"`, ` <attr>='value'`.
|
|
320
|
-
const re = new RegExp(
|
|
321
|
-
`\\s${attr}(?:\\s*=\\s*(?:"[^"]*"|'[^']*'|[^\\s>]+))?(?=[\\s/>])`,
|
|
322
|
-
"i"
|
|
323
|
-
);
|
|
324
|
-
const m = originalTag.match(re);
|
|
325
|
-
if (m) extra += m[0];
|
|
326
|
-
}
|
|
333
|
+
const buildStylesheetLink = (extra, href, crossOrigin) => {
|
|
327
334
|
const safeHref = href.replace(/"/g, """);
|
|
328
|
-
return `<link rel="stylesheet" href="${safeHref}"${extra}>`;
|
|
335
|
+
return `<link rel="stylesheet" href="${safeHref}"${extra}${crossOrigin}>`;
|
|
336
|
+
};
|
|
337
|
+
|
|
338
|
+
/**
|
|
339
|
+
* Build a fresh `<script src="…">` for a JS chunk pulled in by a custom
|
|
340
|
+
* (non-`<script>`) element that the user mapped to `type: "script"` /
|
|
341
|
+
* `"script-module"`. Cloning the custom element verbatim and appending
|
|
342
|
+
* `</script>` (as `cloneTagWithUrl` does for a real `<script>`) would emit
|
|
343
|
+
* mismatched, non-executing markup such as `<my-script src="…"></script>`,
|
|
344
|
+
* so synthesize a real script element instead — copying only the CSP/fetch
|
|
345
|
+
* attributes (`extra`, captured at parse time), since the custom element's
|
|
346
|
+
* other attributes have no defined meaning on a `<script>`.
|
|
347
|
+
* @param {string} extra the copyable CSP/fetch attribute source text (leading-space-prefixed, or empty)
|
|
348
|
+
* @param {string} src URL for the script
|
|
349
|
+
* @param {boolean} isModule whether to emit `type="module"`
|
|
350
|
+
* @param {string} crossOrigin ` crossorigin="…"` to append from `output.crossOriginLoading`, or `""`
|
|
351
|
+
* @returns {string} the sibling `<script>` tag's HTML
|
|
352
|
+
*/
|
|
353
|
+
const buildScriptTag = (extra, src, isModule, crossOrigin) => {
|
|
354
|
+
const safeSrc = src.replace(/"/g, """);
|
|
355
|
+
return `<script${
|
|
356
|
+
isModule ? ' type="module"' : ""
|
|
357
|
+
} src="${safeSrc}"${extra}${crossOrigin}></script>`;
|
|
329
358
|
};
|
|
330
359
|
|
|
331
360
|
/**
|
|
@@ -337,12 +366,18 @@ const buildStylesheetLink = (originalTag, href) => {
|
|
|
337
366
|
* content-specific. When the original tag was upgraded to a module script
|
|
338
367
|
* (either by the author or by the `output.module` auto-upgrade in
|
|
339
368
|
* `HtmlParser`), the sibling is forced to `type="module"` regardless of what
|
|
340
|
-
* the source originally said.
|
|
369
|
+
* the source originally said. The `integrity`/`type` spans come from the
|
|
370
|
+
* parser (`HtmlParser` captured them off the AST); edits are applied
|
|
371
|
+
* right-to-left so earlier offsets stay valid — no re-parsing of the tag.
|
|
341
372
|
* @param {string} originalTag the opening tag's source text including `>`
|
|
342
373
|
* @param {number} srcStartInTag offset of the src/href value start within `originalTag`
|
|
343
374
|
* @param {number} srcEndInTag offset of the src/href value end within `originalTag`
|
|
344
375
|
* @param {string} newUrl URL to put into the cloned tag's src/href slot
|
|
345
|
-
* @param {
|
|
376
|
+
* @param {HtmlEntryElementKind} elementKind shape of the originating tag
|
|
377
|
+
* @param {string} crossOrigin ` crossorigin="…"` to insert from `output.crossOriginLoading`, or `""`
|
|
378
|
+
* @param {number} tagNameEndInTag offset right after the tag name within `originalTag`, where `crossOrigin` is inserted
|
|
379
|
+
* @param {Range | null} integrityRange `integrity` attribute span within `originalTag` to drop, or null
|
|
380
|
+
* @param {Range | null} typeValueRange `type` value span within `originalTag` to overwrite with `module`, or null to insert `type="module"`
|
|
346
381
|
* @returns {string} the sibling tag's HTML (including a closing `</script>` for script tags)
|
|
347
382
|
*/
|
|
348
383
|
const cloneTagWithUrl = (
|
|
@@ -350,39 +385,60 @@ const cloneTagWithUrl = (
|
|
|
350
385
|
srcStartInTag,
|
|
351
386
|
srcEndInTag,
|
|
352
387
|
newUrl,
|
|
353
|
-
elementKind
|
|
388
|
+
elementKind,
|
|
389
|
+
crossOrigin,
|
|
390
|
+
tagNameEndInTag,
|
|
391
|
+
integrityRange,
|
|
392
|
+
typeValueRange
|
|
354
393
|
) => {
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
newUrl +
|
|
358
|
-
originalTag.slice(srcEndInTag);
|
|
359
|
-
|
|
360
|
-
// Strip dangerous-to-copy attributes from the cloned tag — currently
|
|
361
|
-
// just `integrity`. The match handles all three quoting styles
|
|
362
|
-
// (`"…"`, `'…'`, unquoted) and the bare-attribute form.
|
|
363
|
-
body = body.replace(
|
|
364
|
-
/\s+integrity(?:\s*=\s*(?:"[^"]*"|'[^']*'|[^\s>]+))?(?=[\s/>])/gi,
|
|
365
|
-
""
|
|
366
|
-
);
|
|
394
|
+
const isLink =
|
|
395
|
+
elementKind === "modulepreload" || elementKind === "stylesheet";
|
|
367
396
|
|
|
397
|
+
/** @type {{ start: number, end: number, text: string }[]} */
|
|
398
|
+
const edits = [{ start: srcStartInTag, end: srcEndInTag, text: newUrl }];
|
|
399
|
+
|
|
400
|
+
// `integrity` is content-specific — drop it from the clone.
|
|
401
|
+
// TODO: emit a correct per-chunk `integrity` once a core SRI output
|
|
402
|
+
// option exists, instead of dropping it.
|
|
403
|
+
if (integrityRange) {
|
|
404
|
+
edits.push({ start: integrityRange[0], end: integrityRange[1], text: "" });
|
|
405
|
+
}
|
|
406
|
+
|
|
407
|
+
// Inserted right after the tag name: `crossorigin` from
|
|
408
|
+
// `output.crossOriginLoading`, then a forced `type="module"` when the tag
|
|
409
|
+
// has no `type` value to rewrite in place.
|
|
410
|
+
let afterName = crossOrigin;
|
|
368
411
|
if (elementKind === "script-module") {
|
|
369
|
-
if (
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
412
|
+
if (typeValueRange) {
|
|
413
|
+
edits.push({
|
|
414
|
+
start: typeValueRange[0],
|
|
415
|
+
end: typeValueRange[1],
|
|
416
|
+
text: "module"
|
|
417
|
+
});
|
|
374
418
|
} else {
|
|
375
|
-
|
|
419
|
+
afterName += ' type="module"';
|
|
376
420
|
}
|
|
377
421
|
}
|
|
378
422
|
|
|
423
|
+
if (afterName) {
|
|
424
|
+
edits.push({
|
|
425
|
+
start: tagNameEndInTag,
|
|
426
|
+
end: tagNameEndInTag,
|
|
427
|
+
text: afterName
|
|
428
|
+
});
|
|
429
|
+
}
|
|
430
|
+
|
|
431
|
+
edits.sort((a, b) => b.start - a.start);
|
|
432
|
+
let body = originalTag;
|
|
433
|
+
for (const edit of edits) {
|
|
434
|
+
body = body.slice(0, edit.start) + edit.text + body.slice(edit.end);
|
|
435
|
+
}
|
|
436
|
+
|
|
379
437
|
// `<link>` is a void element — no closing tag. `<script>` needs `</script>`.
|
|
380
|
-
return
|
|
381
|
-
? body
|
|
382
|
-
: `${body}</script>`;
|
|
438
|
+
return isLink ? body : `${body}</script>`;
|
|
383
439
|
};
|
|
384
440
|
|
|
385
|
-
|
|
441
|
+
HtmlEntryDependency.Template = class HtmlEntryDependencyTemplate extends (
|
|
386
442
|
ModuleDependency.Template
|
|
387
443
|
) {
|
|
388
444
|
/**
|
|
@@ -394,9 +450,10 @@ HtmlScriptSrcDependency.Template = class HtmlScriptSrcDependencyTemplate extends
|
|
|
394
450
|
*/
|
|
395
451
|
apply(dependency, source, templateContext) {
|
|
396
452
|
const { runtimeTemplate } = templateContext;
|
|
397
|
-
const dep = /** @type {
|
|
453
|
+
const dep = /** @type {HtmlEntryDependency} */ (dependency);
|
|
398
454
|
const compilation = runtimeTemplate.compilation;
|
|
399
455
|
const { chunkGraph } = compilation;
|
|
456
|
+
const { crossOriginLoading } = compilation.outputOptions;
|
|
400
457
|
const entrypoint = /** @type {Entrypoint | undefined} */ (
|
|
401
458
|
compilation.entrypoints.get(dep.entryName)
|
|
402
459
|
);
|
|
@@ -410,15 +467,13 @@ HtmlScriptSrcDependency.Template = class HtmlScriptSrcDependencyTemplate extends
|
|
|
410
467
|
const entryChunk = orderedChunks[orderedChunks.length - 1];
|
|
411
468
|
const isStylesheet = dep.elementKind === "stylesheet";
|
|
412
469
|
|
|
413
|
-
// Rewrite
|
|
414
|
-
//
|
|
415
|
-
// `<link rel="stylesheet">`, `.js` for everything else.
|
|
470
|
+
// Rewrite src/href to a chunk-URL sentinel (resolved by renderManifest):
|
|
471
|
+
// `.css` for `<link rel="stylesheet">`, `.js` for everything else.
|
|
416
472
|
const entryContentHashType = isStylesheet ? "css" : "javascript";
|
|
417
|
-
const entryUrl =
|
|
473
|
+
const entryUrl = HtmlGenerator.makeChunkUrlSentinel(
|
|
418
474
|
entryChunk,
|
|
419
|
-
compilation,
|
|
420
475
|
entryContentHashType
|
|
421
|
-
)
|
|
476
|
+
);
|
|
422
477
|
source.replace(dep.range[0], dep.range[1] - 1, entryUrl);
|
|
423
478
|
|
|
424
479
|
if (dep.tagStart < 0 || dep.tagOpenEnd <= dep.tagStart) {
|
|
@@ -439,6 +494,30 @@ HtmlScriptSrcDependency.Template = class HtmlScriptSrcDependencyTemplate extends
|
|
|
439
494
|
const originalTag = originalContent.slice(dep.tagStart, dep.tagOpenEnd);
|
|
440
495
|
const srcStartInTag = dep.range[0] - dep.tagStart;
|
|
441
496
|
const srcEndInTag = dep.range[1] - dep.tagStart;
|
|
497
|
+
// Non-native originating elements (a custom element mapped to a
|
|
498
|
+
// `script`/`stylesheet` source `type`) can't be cloned verbatim — the
|
|
499
|
+
// clone would be invalid markup (e.g. `<my-script …></script>`), so a
|
|
500
|
+
// real native tag is synthesized instead. Decided at parse time from the
|
|
501
|
+
// tag name (`dep.tagIsNative`) rather than re-parsing the source text.
|
|
502
|
+
const tagIsNative = dep.tagIsNative;
|
|
503
|
+
|
|
504
|
+
// `crossorigin` to mirror `output.crossOriginLoading` onto every injected
|
|
505
|
+
// tag. Empty when the option is off or the originating tag already set
|
|
506
|
+
// `crossorigin` (author value wins, flagged at parse time). Mirrors
|
|
507
|
+
// webpack's runtime, which sets `crossOrigin` on chunk-loading scripts,
|
|
508
|
+
// and matches Vite, which emits it on every injected script/stylesheet.
|
|
509
|
+
const crossOrigin =
|
|
510
|
+
crossOriginLoading && !dep.hasOwnCrossOrigin
|
|
511
|
+
? ` crossorigin="${crossOriginLoading}"`
|
|
512
|
+
: "";
|
|
513
|
+
const tagNameEndInTag = dep.tagNameEnd - dep.tagStart;
|
|
514
|
+
|
|
515
|
+
// Mirror it onto the entry tag too (siblings get it via the builders
|
|
516
|
+
// below), inserted right after the tag name — its parse-time offset — so
|
|
517
|
+
// it sits alongside any `type="module"` the parser injected.
|
|
518
|
+
if (tagIsNative && crossOrigin && dep.tagNameEnd >= 0) {
|
|
519
|
+
source.insert(dep.tagNameEnd, crossOrigin);
|
|
520
|
+
}
|
|
442
521
|
|
|
443
522
|
/**
|
|
444
523
|
* @param {Chunk} chunk chunk to emit a sibling tag for
|
|
@@ -446,23 +525,49 @@ HtmlScriptSrcDependency.Template = class HtmlScriptSrcDependencyTemplate extends
|
|
|
446
525
|
* @returns {string} a single sibling tag's HTML
|
|
447
526
|
*/
|
|
448
527
|
const buildSibling = (chunk, kind) => {
|
|
449
|
-
const url =
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
//
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
528
|
+
const url = HtmlGenerator.makeChunkUrlSentinel(chunk, kind);
|
|
529
|
+
if (kind === "css") {
|
|
530
|
+
// A CSS chunk is always loaded via `<link rel="stylesheet">`.
|
|
531
|
+
// Clone only when the entry tag is itself a native `<link
|
|
532
|
+
// rel="stylesheet">` (so attributes like `media` carry over);
|
|
533
|
+
// a `<script>` entry that imported CSS, or a custom element,
|
|
534
|
+
// gets a freshly synthesized `<link>`.
|
|
535
|
+
if (isStylesheet && tagIsNative) {
|
|
536
|
+
return cloneTagWithUrl(
|
|
537
|
+
originalTag,
|
|
538
|
+
srcStartInTag,
|
|
539
|
+
srcEndInTag,
|
|
540
|
+
url,
|
|
541
|
+
dep.elementKind,
|
|
542
|
+
crossOrigin,
|
|
543
|
+
tagNameEndInTag,
|
|
544
|
+
dep.integrityRange,
|
|
545
|
+
dep.typeValueRange
|
|
546
|
+
);
|
|
547
|
+
}
|
|
548
|
+
return buildStylesheetLink(dep.copyableAttrsText, url, crossOrigin);
|
|
549
|
+
}
|
|
550
|
+
// A JS chunk is loaded via `<script>`. Clone a native `<script>`
|
|
551
|
+
// verbatim; synthesize a real `<script>` for custom elements that
|
|
552
|
+
// were mapped to `type: script`/`script-module`.
|
|
553
|
+
if (tagIsNative) {
|
|
554
|
+
return cloneTagWithUrl(
|
|
555
|
+
originalTag,
|
|
556
|
+
srcStartInTag,
|
|
557
|
+
srcEndInTag,
|
|
558
|
+
url,
|
|
559
|
+
dep.elementKind,
|
|
560
|
+
crossOrigin,
|
|
561
|
+
tagNameEndInTag,
|
|
562
|
+
dep.integrityRange,
|
|
563
|
+
dep.typeValueRange
|
|
564
|
+
);
|
|
459
565
|
}
|
|
460
|
-
return
|
|
461
|
-
|
|
462
|
-
srcStartInTag,
|
|
463
|
-
srcEndInTag,
|
|
566
|
+
return buildScriptTag(
|
|
567
|
+
dep.copyableAttrsText,
|
|
464
568
|
url,
|
|
465
|
-
dep.elementKind
|
|
569
|
+
dep.elementKind === "script-module",
|
|
570
|
+
crossOrigin
|
|
466
571
|
);
|
|
467
572
|
};
|
|
468
573
|
|
|
@@ -487,7 +592,7 @@ HtmlScriptSrcDependency.Template = class HtmlScriptSrcDependencyTemplate extends
|
|
|
487
592
|
// re-derive the order from the entrypoint's module post-order
|
|
488
593
|
// index, which mirrors the dependency walk and so reflects the
|
|
489
594
|
// import order.
|
|
490
|
-
/** @type {{ chunk: Chunk, index: number }[]} */
|
|
595
|
+
/** @type {{ chunk: Chunk, index: number, key: string }[]} */
|
|
491
596
|
const cssChunkOrder = [];
|
|
492
597
|
/** @type {Chunk[]} */
|
|
493
598
|
const jsChunks = [];
|
|
@@ -498,7 +603,8 @@ HtmlScriptSrcDependency.Template = class HtmlScriptSrcDependencyTemplate extends
|
|
|
498
603
|
if (hasCss) {
|
|
499
604
|
cssChunkOrder.push({
|
|
500
605
|
chunk,
|
|
501
|
-
index: firstCssModulePostOrderIndex(chunk, entrypoint, chunkGraph)
|
|
606
|
+
index: firstCssModulePostOrderIndex(chunk, entrypoint, chunkGraph),
|
|
607
|
+
key: cssChunkSortKey(chunk)
|
|
502
608
|
});
|
|
503
609
|
}
|
|
504
610
|
// Anything that isn't CSS-only stays on the JS lane, in the
|
|
@@ -520,7 +626,8 @@ HtmlScriptSrcDependency.Template = class HtmlScriptSrcDependencyTemplate extends
|
|
|
520
626
|
entryChunk,
|
|
521
627
|
entrypoint,
|
|
522
628
|
chunkGraph
|
|
523
|
-
)
|
|
629
|
+
),
|
|
630
|
+
key: cssChunkSortKey(entryChunk)
|
|
524
631
|
});
|
|
525
632
|
}
|
|
526
633
|
cssChunkOrder.sort((a, b) => {
|
|
@@ -533,11 +640,17 @@ HtmlScriptSrcDependency.Template = class HtmlScriptSrcDependencyTemplate extends
|
|
|
533
640
|
// including the `Infinity === Infinity` case.
|
|
534
641
|
if (a.index < b.index) return -1;
|
|
535
642
|
if (a.index > b.index) return 1;
|
|
536
|
-
|
|
643
|
+
if (a.key < b.key) return -1;
|
|
644
|
+
if (a.key > b.key) return 1;
|
|
645
|
+
return 0;
|
|
537
646
|
});
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
647
|
+
// Insert CSS before the first script (not just before this tag) so a
|
|
648
|
+
// later entry's stylesheet still loads ahead of every script.
|
|
649
|
+
const cssAt = dep.cssAnchor === -1 ? dep.tagStart : dep.cssAnchor;
|
|
650
|
+
const cssLinks = cssChunkOrder.map(({ chunk }) =>
|
|
651
|
+
buildSibling(chunk, "css")
|
|
652
|
+
);
|
|
653
|
+
if (cssLinks.length > 0) source.insert(cssAt, cssLinks.join(""));
|
|
541
654
|
for (const chunk of jsChunks) {
|
|
542
655
|
siblings.push(buildSibling(chunk, "javascript"));
|
|
543
656
|
}
|
|
@@ -550,8 +663,8 @@ HtmlScriptSrcDependency.Template = class HtmlScriptSrcDependencyTemplate extends
|
|
|
550
663
|
};
|
|
551
664
|
|
|
552
665
|
makeSerializable(
|
|
553
|
-
|
|
554
|
-
"webpack/lib/dependencies/
|
|
666
|
+
HtmlEntryDependency,
|
|
667
|
+
"webpack/lib/dependencies/HtmlEntryDependency"
|
|
555
668
|
);
|
|
556
669
|
|
|
557
|
-
module.exports =
|
|
670
|
+
module.exports = HtmlEntryDependency;
|