@depup/webpack 5.110.1-depup.0 → 5.111.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 -8
- package/changes.json +7 -11
- package/lib/APIPlugin.js +26 -11
- package/lib/AutomaticPrefetchPlugin.js +1 -1
- package/lib/Cache.js +8 -3
- package/lib/CacheFacade.js +1 -1
- package/lib/ChunkGraph.js +20 -18
- package/lib/CircularModulesPlugin.js +157 -55
- package/lib/CleanPlugin.js +2 -2
- package/lib/CompatibilityPlugin.js +3 -4
- package/lib/Compilation.js +337 -338
- package/lib/Compiler.js +213 -51
- package/lib/ConcatenationScope.js +25 -35
- package/lib/ConstPlugin.js +16 -132
- package/lib/CopyPlugin.js +1054 -0
- package/lib/DefinePlugin.js +24 -8
- package/lib/DependencyTemplate.js +2 -1
- package/lib/DotenvPlugin.js +64 -40
- package/lib/ErrorHelpers.js +113 -0
- package/lib/ExportsInfo.js +30 -16
- package/lib/ExternalModule.js +47 -22
- package/lib/FileSystemInfo.js +17 -14
- package/lib/FlagDependencyExportsPlugin.js +53 -34
- package/lib/FlagDependencyUsagePlugin.js +17 -15
- package/lib/Generator.js +24 -2
- package/lib/HotModuleReplacementPlugin.js +55 -7
- package/lib/IgnorePlugin.js +1 -1
- package/lib/JavascriptMetaInfoPlugin.js +5 -3
- package/lib/LoaderOptionsPlugin.js +1 -1
- package/lib/MainTemplate.js +5 -1
- package/lib/Module.js +19 -10
- package/lib/ModuleGraph.js +6 -9
- package/lib/MultiCompiler.js +7 -17
- package/lib/MultiWatching.js +1 -1
- package/lib/NormalModule.js +148 -70
- package/lib/NormalModuleFactory.js +1 -1
- package/lib/RuntimeGlobals.js +21 -7
- package/lib/RuntimeModule.js +28 -12
- package/lib/RuntimePlugin.js +33 -3
- package/lib/RuntimeTemplate.js +1147 -847
- package/lib/SourceMapDevToolPlugin.js +54 -104
- package/lib/TemplatedPathPlugin.js +16 -59
- package/lib/Watching.js +9 -0
- package/lib/WebpackOptionsApply.js +84 -91
- package/lib/asset/AssetBytesGenerator.js +7 -1
- package/lib/asset/AssetGenerator.js +50 -24
- package/lib/asset/AssetModule.js +3 -0
- package/lib/asset/AssetSourceGenerator.js +7 -1
- package/lib/asset/WebManifestParser.js +7 -5
- package/lib/async-modules/AsyncModuleHelpers.js +10 -4
- package/lib/buildChunkGraph.js +11 -15
- package/lib/cache/AddBuildDependenciesPlugin.js +33 -4
- package/lib/cache/IdleFileCachePlugin.js +2 -2
- package/lib/cache/MemoryCachePlugin.js +4 -4
- package/lib/cache/MemoryWithGcCachePlugin.js +7 -8
- package/lib/cache/PackFileCacheStrategy.js +17 -19
- package/lib/cache/getLazyHashedEtag.js +3 -5
- package/lib/config/browserslistTargetHandler.js +17 -4
- package/lib/config/defaults.js +162 -142
- package/lib/config/getClaimedAssetTypes.js +10 -11
- package/lib/config/normalization.js +100 -20
- package/lib/config/target.js +13 -4
- package/lib/container/ContainerReferencePlugin.js +6 -0
- package/lib/container/RemoteRuntimeModule.js +9 -0
- package/lib/container/declaredRemotes.js +39 -0
- package/lib/{ContextExclusionPlugin.js → context/ContextExclusionPlugin.js} +1 -1
- package/lib/{ContextModule.js → context/ContextModule.js} +54 -115
- package/lib/{ContextModuleFactory.js → context/ContextModuleFactory.js} +19 -21
- package/lib/{ContextReplacementPlugin.js → context/ContextReplacementPlugin.js} +4 -4
- package/lib/css/CssGenerator.js +27 -11
- package/lib/css/CssInjectStyleRuntimeModule.js +9 -0
- package/lib/css/CssLoadingRuntimeModule.js +92 -15
- package/lib/css/CssModule.js +1 -1
- package/lib/css/CssModulesPlugin.js +3 -10
- package/lib/css/CssParser.js +162 -31
- package/lib/css/CssServerStylesRuntimeModule.js +9 -0
- package/lib/css/cssMinify.js +43 -32
- package/lib/css/data.js +3526 -871
- package/lib/css/syntax.js +6455 -1237
- package/lib/debug/ProfilingPlugin.js +7 -4
- package/lib/dependencies/AMDDefineDependencyParserPlugin.js +6 -3
- package/lib/dependencies/AMDRuntimeModules.js +18 -0
- package/lib/dependencies/CommonJsExportRequireDependency.js +13 -12
- package/lib/dependencies/CommonJsExportsParserPlugin.js +12 -13
- package/lib/dependencies/CommonJsImportsParserPlugin.js +5 -5
- package/lib/dependencies/CommonJsPlugin.js +19 -3
- package/lib/dependencies/CommonJsRequireDependency.js +32 -9
- package/lib/dependencies/CommonJsSelfReferenceDependency.js +2 -4
- package/lib/dependencies/ContextDependency.js +1 -1
- package/lib/dependencies/ContextDependencyHelpers.js +3 -9
- package/lib/dependencies/ContextDependencyTemplateAsRequireCall.js +20 -7
- package/lib/dependencies/ContextElementDependency.js +1 -1
- package/lib/dependencies/CssIcssExportDependency.js +13 -9
- package/lib/dependencies/CssIcssImportDependency.js +3 -6
- package/lib/dependencies/CssUrlDependency.js +3 -5
- package/lib/dependencies/HarmonyCompatibilityDependency.js +67 -22
- package/lib/dependencies/HarmonyDetectionParserPlugin.js +3 -4
- package/lib/dependencies/HarmonyEvaluatedImportSpecifierDependency.js +10 -4
- package/lib/dependencies/HarmonyExportDependencyParserPlugin.js +12 -7
- package/lib/dependencies/HarmonyExportExpressionDependency.js +47 -33
- package/lib/dependencies/HarmonyExportImportedSpecifierDependency.js +217 -34
- package/lib/dependencies/HarmonyExportInitFragment.js +110 -23
- package/lib/dependencies/HarmonyExportSpecifierDependency.js +25 -58
- package/lib/dependencies/HarmonyImportBareSideEffectDependency.js +59 -0
- package/lib/dependencies/HarmonyImportDependency.js +99 -41
- package/lib/dependencies/HarmonyImportDependencyParserPlugin.js +198 -25
- package/lib/dependencies/HarmonyImportSideEffectDependency.js +117 -4
- package/lib/dependencies/HarmonyImportSpecifierDependency.js +40 -3
- package/lib/dependencies/HarmonyModulesPlugin.js +20 -0
- package/lib/dependencies/HtmlEntryDependency.js +136 -104
- package/lib/dependencies/HtmlInlineScriptDependency.js +3 -4
- package/lib/dependencies/HtmlInlineStyleDependency.js +3 -4
- package/lib/dependencies/ImportContextDependency.js +43 -3
- package/lib/dependencies/ImportDependency.js +8 -29
- package/lib/dependencies/ImportMetaContextDependencyParserPlugin.js +1 -1
- package/lib/dependencies/ImportMetaGlobHelpers.js +1 -1
- package/lib/dependencies/ImportMetaMainDependency.js +104 -0
- package/lib/dependencies/ImportMetaPlugin.js +67 -25
- package/lib/dependencies/ImportParserPlugin.js +25 -15
- package/lib/dependencies/LoaderPlugin.js +26 -1
- package/lib/dependencies/RequireContextDependencyParserPlugin.js +1 -1
- package/lib/dependencies/RequireHeaderDependency.js +20 -21
- package/lib/dependencies/SystemRuntimeModule.js +9 -0
- package/lib/dependencies/URLContextDependency.js +1 -1
- package/lib/dependencies/URLDependency.js +6 -5
- package/lib/dependencies/WorkerAndWorkletPlugin.js +16 -21
- package/lib/dependencies/WorkerDependency.js +12 -18
- package/lib/dependencies/WorkletDependency.js +12 -20
- package/lib/dependencies/importOptionsCheck.js +47 -0
- package/lib/dll/DelegatedModule.js +18 -1
- package/lib/dll/DllReferencePlugin.js +11 -8
- package/lib/dll/LibManifestPlugin.js +1 -1
- package/lib/errors/AnalyzableBailoutsWarning.js +41 -0
- package/lib/errors/DotenvFileError.js +29 -0
- package/lib/errors/DuplicateModulesWarning.js +12 -7
- package/lib/errors/EmptyCopyPatternWarning.js +26 -0
- package/lib/errors/ExternalStarReexportError.js +44 -0
- package/lib/errors/HookWebpackError.js +3 -2
- package/lib/errors/ImportedBindingAssignmentError.js +30 -0
- package/lib/errors/MissingSourceMapsWarning.js +36 -0
- package/lib/errors/ModuleParseError.js +2 -1
- package/lib/errors/UnusedAssetsWarning.js +36 -0
- package/lib/errors/UnusedFederationWarning.js +35 -0
- package/lib/errors/UnusedModulesWarning.js +38 -0
- package/lib/esm/ExportWebpackRequireRuntimeModule.js +9 -0
- package/lib/esm/ModuleChunkFormatPlugin.js +28 -3
- package/lib/esm/ModuleChunkLoadingPlugin.js +21 -5
- package/lib/esm/ModuleChunkLoadingRuntimeModule.js +91 -53
- package/lib/hmr/HotModuleReplacement.runtime.js +8 -2
- package/lib/hmr/HotModuleReplacementRuntimeModule.js +9 -0
- package/lib/hmr/LazyCompilationPlugin.js +3 -5
- package/lib/html/HtmlGenerator.js +72 -87
- package/lib/html/HtmlModulesPlugin.js +479 -215
- package/lib/html/HtmlParser.js +110 -147
- package/lib/html/builtinEmbeddedRenderer.js +107 -0
- package/lib/html/data.js +142 -7
- package/lib/html/htmlMinify.js +92 -122
- package/lib/html/syntax.js +2031 -1556
- package/lib/ids/HashedModuleIdsPlugin.js +2 -1
- package/lib/index.js +49 -3
- package/lib/javascript/ChunkFormatHelpers.js +4 -3
- package/lib/javascript/JavascriptGenerator.js +8 -1
- package/lib/javascript/JavascriptModule.js +1 -0
- package/lib/javascript/JavascriptModulesPlugin.js +76 -80
- package/lib/javascript/JavascriptParser.js +1970 -900
- package/lib/javascript/StartupHelpers.js +27 -3
- package/lib/javascript/data.js +172 -0
- package/lib/javascript/grammar.js +5546 -0
- package/lib/javascript/parser.js +1500 -0
- package/lib/javascript/regexp.js +1762 -0
- package/lib/javascript/regexpData.js +51 -0
- package/lib/javascript/syntax.js +9061 -5262
- package/lib/json/JsonGenerator.js +7 -1
- package/lib/library/ModuleLibraryPlugin.js +171 -132
- package/lib/loaders/LoaderRunner.js +170 -14
- package/lib/node/NodeWatchFileSystem.js +3 -9
- package/lib/node/ReadFileChunkLoadingRuntimeModule.js +22 -0
- package/lib/node/ReadFileCompileAsyncWasmPlugin.js +8 -15
- package/lib/node/RequireChunkLoadingRuntimeModule.js +22 -0
- package/lib/optimize/AggressiveMergingPlugin.js +3 -5
- package/lib/optimize/ConcatenatedModule.js +222 -125
- package/lib/optimize/ConstExportsPlugin.js +50 -34
- package/lib/optimize/FlagIncludedChunksPlugin.js +3 -11
- package/lib/optimize/InlineExports.js +20 -2
- package/lib/optimize/InnerGraphPlugin.js +7 -13
- package/lib/optimize/LimitChunkCountPlugin.js +5 -8
- package/lib/optimize/MangleExportsPlugin.js +13 -4
- package/lib/optimize/ModuleConcatenationPlugin.js +27 -5
- package/lib/optimize/RealContentHashPlugin.js +179 -44
- package/lib/optimize/SideEffectsFlagPlugin.js +24 -28
- package/lib/optimize/SplitChunksPlugin.js +2 -4
- package/lib/performance/AnalyzableBailoutsPlugin.js +115 -0
- package/lib/performance/BroadContextsPlugin.js +1 -1
- package/lib/performance/CacheEffectivenessPlugin.js +7 -7
- package/lib/performance/DuplicateModulesPlugin.js +57 -13
- package/lib/performance/EvalUsagePlugin.js +5 -2
- package/lib/performance/MissingSourceMapsPlugin.js +115 -0
- package/lib/performance/PureAnnotationsPlugin.js +6 -3
- package/lib/performance/SizeLimitsPlugin.js +2 -4
- package/lib/performance/TopLevelThisPlugin.js +5 -4
- package/lib/performance/UnusedAssetsPlugin.js +109 -0
- package/lib/performance/UnusedFederationPlugin.js +147 -0
- package/lib/performance/UnusedModulesPlugin.js +141 -0
- package/lib/performance/UnusedReexportsPlugin.js +1 -55
- package/lib/performance/isOnlyReexported.js +65 -0
- package/lib/prefetch/ChunkPrefetchFunctionRuntimeModule.js +25 -5
- package/lib/prefetch/ChunkPrefetchPreloadPlugin.js +8 -8
- package/lib/prefetch/ChunkPrefetchStartupRuntimeModule.js +9 -0
- package/lib/prefetch/ChunkPrefetchTriggerRuntimeModule.js +9 -0
- package/lib/prefetch/ChunkPreloadTriggerRuntimeModule.js +9 -0
- package/lib/prefetch/ResourceHintPlugin.js +29 -35
- package/lib/prefetch/ResourceHintRuntimeModule.js +9 -0
- package/lib/prefetch/StartupAssetHintRuntimeModule.js +16 -10
- package/lib/rules/RuleSetCompiler.js +211 -4
- package/lib/runtime/AsyncModuleRuntimeModule.js +103 -67
- package/lib/runtime/AutoPublicPathRuntimeModule.js +9 -0
- package/lib/runtime/BaseUriRuntimeModule.js +9 -0
- package/lib/runtime/ChunkNameRuntimeModule.js +9 -0
- package/lib/runtime/EnsureChunkRuntimeModule.js +35 -16
- package/lib/runtime/GetChunkFilenameRuntimeModule.js +12 -4
- package/lib/runtime/GetFullHashRuntimeModule.js +9 -0
- package/lib/runtime/GetMainFilenameRuntimeModule.js +9 -0
- package/lib/runtime/GetWorkletBootstrapRuntimeModule.js +9 -0
- package/lib/runtime/GlobalRuntimeModule.js +11 -4
- package/lib/runtime/HasOwnPropertyRuntimeModule.js +9 -0
- package/lib/runtime/HelperRuntimeModule.js +10 -0
- package/lib/runtime/MakeDeferredNamespaceObjectRuntime.js +313 -222
- package/lib/runtime/NonceRuntimeModule.js +9 -0
- package/lib/runtime/OnChunksLoadedRuntimeModule.js +67 -20
- package/lib/runtime/PublicPathRuntimeModule.js +9 -0
- package/lib/runtime/RuntimeIdRuntimeModule.js +9 -0
- package/lib/runtime/SpecNamespaceObjectRuntimeModule.js +90 -0
- package/lib/runtime/StartupChunkDependenciesRuntimeModule.js +9 -0
- package/lib/runtime/StartupEntrypointRuntimeModule.js +9 -0
- package/lib/runtime/SystemContextRuntimeModule.js +9 -0
- package/lib/runtime/ToBinaryRuntimeModule.js +9 -0
- package/lib/schemes/DataUriPlugin.js +3 -6
- package/lib/schemes/HttpUriPlugin.js +22 -5
- package/lib/schemes/VirtualUrlPlugin.js +1 -1
- package/lib/serialization/BinaryMiddleware.js +9 -9
- package/lib/serialization/FileMiddleware.js +31 -18
- package/lib/serialization/ObjectMiddleware.js +168 -139
- package/lib/sharing/ConsumeSharedPlugin.js +12 -0
- package/lib/sharing/ConsumeSharedRuntimeModule.js +11 -0
- package/lib/sharing/ShareRuntimeModule.js +9 -0
- package/lib/sharing/declaredShared.js +47 -0
- package/lib/stats/DefaultStatsFactoryPlugin.js +6 -5
- package/lib/stats/DefaultStatsPrinterPlugin.js +3 -0
- package/lib/typescript/TypeScriptPlugin.js +10 -13
- package/lib/url/URLParserPlugin.js +6 -8
- package/lib/util/ArrayQueue.js +3 -3
- package/lib/util/LocConverter.js +4 -7
- package/lib/util/SourceProcessor.js +115 -99
- package/lib/util/URLAbsoluteSpecifier.js +3 -1
- package/lib/util/async.js +292 -0
- package/lib/util/buildDiagnostics.js +69 -0
- package/lib/util/chainedImports.js +3 -4
- package/lib/util/concatenate.js +4 -4
- package/lib/util/conventions.js +5 -1
- package/lib/util/createHooksRegistry.js +1 -2
- package/lib/util/createMappings.js +25 -3
- package/lib/util/dataURL.js +2 -3
- package/lib/util/deterministicGrouping.js +8 -13
- package/lib/util/findGraphRoots.js +6 -13
- package/lib/util/fs.js +27 -1
- package/lib/util/globUtils.js +1 -1
- package/lib/util/handlerKeys.js +40 -0
- package/lib/util/hash/wasm-hash.js +3 -4
- package/lib/util/identifier.js +20 -0
- package/lib/util/internalSerializables.js +7 -1
- package/lib/util/registerExternalSerializer.js +6 -45
- package/lib/util/removeBOM.js +82 -1
- package/lib/util/semver.js +5 -3
- package/lib/wasm-async/AsyncWasmCompileRuntimeModule.js +14 -3
- package/lib/wasm-async/AsyncWasmLoadingRuntimeModule.js +14 -3
- package/lib/wasm-async/AsyncWebAssemblyGenerator.js +6 -1
- package/lib/wasm-async/AsyncWebAssemblyJavascriptGenerator.js +5 -1
- package/lib/wasm-async/UniversalCompileAsyncWasmPlugin.js +7 -12
- package/lib/wasm-sync/WasmChunkLoadingRuntimeModule.js +12 -4
- package/lib/wasm-sync/WebAssemblyGenerator.js +6 -1
- package/lib/wasm-sync/WebAssemblyJavascriptGenerator.js +5 -1
- package/lib/wasm-sync/WebAssemblyUtils.js +2 -4
- package/lib/web/FetchCompileAsyncWasmPlugin.js +10 -6
- package/lib/web/FetchCompileWasmPlugin.js +4 -2
- package/lib/web/JsonpChunkLoadingRuntimeModule.js +36 -0
- package/lib/webworker/ImportScriptsChunkLoadingRuntimeModule.js +19 -0
- package/package.json +55 -46
- package/schemas/WebpackOptions.check.js +1 -1
- package/schemas/WebpackOptions.json +388 -76
- package/schemas/plugins/LoaderOptionsPlugin.check.js +1 -1
- package/schemas/plugins/ManifestPlugin.check.js +1 -1
- package/schemas/plugins/SourceMapDevToolPlugin.check.js +1 -1
- package/schemas/plugins/asset/AssetGeneratorOptions.check.js +1 -1
- package/schemas/plugins/asset/AssetResourceGeneratorOptions.check.js +1 -1
- package/schemas/plugins/container/ContainerPlugin.check.js +1 -1
- package/schemas/plugins/container/ModuleFederationPlugin.check.js +1 -1
- package/schemas/plugins/debug/ProfilingPlugin.check.js +1 -1
- package/schemas/plugins/dll/DllReferencePlugin.check.js +1 -1
- package/schemas/plugins/ids/HashedModuleIdsPlugin.check.js +1 -1
- package/schemas/plugins/schemes/HttpUriPlugin.check.js +1 -1
- package/types.d.ts +1795 -608
- package/lib/dependencies/ExportBindingInitFragment.js +0 -191
- package/lib/errors/EntrypointOverlapWarning.js +0 -45
- package/lib/performance/EntrypointOverlapPlugin.js +0 -122
package/lib/html/HtmlParser.js
CHANGED
|
@@ -90,10 +90,9 @@ const STYLE_ATTR_URL_REGEXP = /url\(|src\(|image\(|image-set\(/i;
|
|
|
90
90
|
// hold a `url(...)` FuncIRI. Most are plain colors/keywords (`#fff`, `red`).
|
|
91
91
|
const FUNC_IRI_URL_REGEXP = /url\(/i;
|
|
92
92
|
|
|
93
|
-
// Cheap pre-filter for `<iframe srcdoc
|
|
94
|
-
//
|
|
95
|
-
// `
|
|
96
|
-
// formatting/text markup (`<p>hi</p>`) rewrites to itself, so skip it.
|
|
93
|
+
// Cheap pre-filter for `<iframe srcdoc>`: a nested HTML module is only worth
|
|
94
|
+
// building when the markup can reference an asset — any attribute, a CSS
|
|
95
|
+
// `url(...)` or an `@import`. Pure text markup rewrites to itself.
|
|
97
96
|
const SRCDOC_ASSET_REGEXP = /[=]|url\(|@import/i;
|
|
98
97
|
|
|
99
98
|
// A URL carrying its own scheme (`https:`, `data:`, …) ignores the document
|
|
@@ -370,10 +369,9 @@ const isLinkStylesheet = (attributes) => {
|
|
|
370
369
|
*/
|
|
371
370
|
const dict = (...bags) => Object.assign(Object.create(null), ...bags);
|
|
372
371
|
|
|
373
|
-
//
|
|
374
|
-
//
|
|
375
|
-
//
|
|
376
|
-
// `parseSrcset` parser for it and otherwise treats it like `src`.
|
|
372
|
+
// One shared `SourceItem` per kind, so the walk's lookups stay on a single V8
|
|
373
|
+
// hidden class. `srcset` is its own type: the walk picks `parseSrcset` for it
|
|
374
|
+
// and otherwise treats it like `src`.
|
|
377
375
|
/** @type {SourceItem} */
|
|
378
376
|
const PLAIN_SRC = { type: "src", filter: undefined };
|
|
379
377
|
/** @type {SourceItem} */
|
|
@@ -389,10 +387,9 @@ const LINK_HREF = {
|
|
|
389
387
|
type: (attrs, css) => {
|
|
390
388
|
if (isLinkModulePreload(attrs)) return "modulepreload";
|
|
391
389
|
if (css && isLinkStylesheet(attrs)) return "stylesheet";
|
|
392
|
-
// `rel="preload"/"prefetch"` with `as="script"`
|
|
393
|
-
// `experiments.css`
|
|
394
|
-
//
|
|
395
|
-
// font, fetch, …) stay plain asset URLs.
|
|
390
|
+
// `rel="preload"/"prefetch"` with `as="script"` — or `as="style"` under
|
|
391
|
+
// `experiments.css` — becomes a non-executing entry pointing at the built
|
|
392
|
+
// chunk; every other `as` target stays a plain asset URL.
|
|
396
393
|
const rel = getAttributeValue(attrs, "rel");
|
|
397
394
|
if (rel) {
|
|
398
395
|
const rels = rel.trim().toLowerCase().split(/\s+/);
|
|
@@ -446,11 +443,9 @@ const META_CONTENT = {
|
|
|
446
443
|
filter: filterMetaContent
|
|
447
444
|
};
|
|
448
445
|
|
|
449
|
-
//
|
|
450
|
-
//
|
|
451
|
-
//
|
|
452
|
-
// the default `sources` config just references this table and pays
|
|
453
|
-
// zero per-parser work.
|
|
446
|
+
// Written in its final resolved shape, `[tag][attribute] = item`, rather than
|
|
447
|
+
// built from an array at module load: a parser on the default `sources` config
|
|
448
|
+
// references this table and pays nothing per instance.
|
|
454
449
|
/** @type {Record<string, Record<string, SourceItem>>} */
|
|
455
450
|
const DEFAULT_SOURCES_BY_TAG = dict({
|
|
456
451
|
// Obsolete Java-applet element; `code`/`object` are single class/object URLs.
|
|
@@ -489,13 +484,14 @@ const DEFAULT_SOURCES_BY_TAG = dict({
|
|
|
489
484
|
th: dict({ background: PLAIN_SRC }),
|
|
490
485
|
track: dict({ src: PLAIN_SRC }),
|
|
491
486
|
video: dict({ poster: PLAIN_SRC, src: PLAIN_SRC }),
|
|
492
|
-
// SVG. Tag names match the tree builder's adjusted camelCase
|
|
493
|
-
// (`feImage`/`textPath`/`linearGradient`/`radialGradient`). `href
|
|
494
|
-
// `xlink:href` reference another element
|
|
495
|
-
//
|
|
496
|
-
// `color-profile`'s `xlink:href` points at an external ICC profile
|
|
497
|
-
// `cursor
|
|
498
|
-
// `glyphRef
|
|
487
|
+
// WHY: SVG. Tag names match the tree builder's adjusted camelCase
|
|
488
|
+
// (`feImage`/`textPath`/`linearGradient`/`radialGradient`). `href` and
|
|
489
|
+
// `xlink:href` reference another element or resource, and a fragment-only
|
|
490
|
+
// `#id` value is left untouched, so only an external `file.svg#id` is
|
|
491
|
+
// rewritten. `color-profile`'s `xlink:href` points at an external ICC profile
|
|
492
|
+
// file; `cursor` and `font-face-uri` at an external image or font file; and
|
|
493
|
+
// `altGlyph`, `glyphRef` and `tref` are legacy element references, removed in
|
|
494
|
+
// SVG 2.
|
|
499
495
|
altGlyph: dict({ "xlink:href": PLAIN_SRC, href: PLAIN_SRC }),
|
|
500
496
|
"color-profile": dict({ "xlink:href": PLAIN_SRC, href: PLAIN_SRC }),
|
|
501
497
|
cursor: dict({ "xlink:href": PLAIN_SRC, href: PLAIN_SRC }),
|
|
@@ -515,11 +511,11 @@ const DEFAULT_SOURCES_BY_TAG = dict({
|
|
|
515
511
|
// clip-path, …) are handled separately during the walk (`parseCssUrls`).
|
|
516
512
|
});
|
|
517
513
|
|
|
518
|
-
// SVG presentation attributes (`fill`, `stroke`, …) carry CSS `url(...)`
|
|
519
|
-
// FuncIRIs
|
|
520
|
-
// `url(#id)`
|
|
521
|
-
// the item is `namespace`-gated rather than placed in a tag bucket
|
|
522
|
-
// is a cheap pre-check skipping the common plain values (`red`, `none
|
|
514
|
+
// WHY: SVG presentation attributes (`fill`, `stroke`, …) carry CSS `url(...)`
|
|
515
|
+
// FuncIRIs, whose external refs `parseCssUrls` extracts as assets, leaving an
|
|
516
|
+
// internal `url(#id)` untouched. They apply to every SVG-namespace element, so
|
|
517
|
+
// the item is `namespace`-gated rather than placed in a tag bucket, and the
|
|
518
|
+
// filter is a cheap pre-check skipping the common plain values (`red`, `none`).
|
|
523
519
|
/** @type {SourceItem} */
|
|
524
520
|
const SVG_CSS_URL = {
|
|
525
521
|
type: "css-url",
|
|
@@ -527,21 +523,18 @@ const SVG_CSS_URL = {
|
|
|
527
523
|
namespace: NS_SVG
|
|
528
524
|
};
|
|
529
525
|
|
|
530
|
-
// The global `style=""` attribute
|
|
531
|
-
//
|
|
532
|
-
//
|
|
533
|
-
// created); the filter is a cheap pre-check skipping declarations without a
|
|
534
|
-
// `url()`/`src()`/… .
|
|
526
|
+
// The global `style=""` attribute, available on every tag and even under
|
|
527
|
+
// `sources: false`. Like every `stylesheet-style*` source it only emits when
|
|
528
|
+
// `experiments.css` is on, checked where the dependency is created.
|
|
535
529
|
/** @type {SourceItem} */
|
|
536
530
|
const STYLE_ATTRIBUTE = {
|
|
537
531
|
type: "stylesheet-style-attribute",
|
|
538
532
|
filter: (attributes, value) => STYLE_ATTR_URL_REGEXP.test(value)
|
|
539
533
|
};
|
|
540
534
|
|
|
541
|
-
// Any-tag sources
|
|
542
|
-
//
|
|
543
|
-
//
|
|
544
|
-
// unless `sources: false`; only the always-on style attribute survives `false`.
|
|
535
|
+
// Any-tag sources, folded into each tag bucket so the walk resolves one object
|
|
536
|
+
// per element and one property per attribute. `sources: false` leaves only the
|
|
537
|
+
// always-on style attribute.
|
|
545
538
|
/** @type {Record<string, SourceItem>} */
|
|
546
539
|
const DEFAULT_ANY_SOURCES = dict({ style: STYLE_ATTRIBUTE });
|
|
547
540
|
for (const name of [
|
|
@@ -625,10 +618,9 @@ const styleContentFilter = (attrs) => {
|
|
|
625
618
|
return t === "" || t === "text/css";
|
|
626
619
|
};
|
|
627
620
|
|
|
628
|
-
// Element-body sources, independent of the `sources` option
|
|
629
|
-
//
|
|
630
|
-
//
|
|
631
|
-
// created, like every `stylesheet-style*` source).
|
|
621
|
+
// Element-body sources, independent of the `sources` option: a `<script>` body
|
|
622
|
+
// is always processed, while a `<style>` body only emits when `experiments.css`
|
|
623
|
+
// is on, checked where the dependency is created.
|
|
632
624
|
/** @type {Record<string, ContentSourceItem>} */
|
|
633
625
|
const CONTENT_SOURCES = dict({
|
|
634
626
|
script: { type: scriptContentType, filter: scriptContentFilter },
|
|
@@ -649,11 +641,9 @@ class HtmlParser extends Parser {
|
|
|
649
641
|
this.template = options.template;
|
|
650
642
|
/** @type {import("../../declarations/WebpackOptions").UrlHintRule[] | undefined} */
|
|
651
643
|
this._urlHints = options.urlHints;
|
|
652
|
-
// `as` selects the parse mode
|
|
653
|
-
//
|
|
654
|
-
//
|
|
655
|
-
// so context-sensitive tags (`<tr>`, `<td>`, `<option>`, …) in a partial
|
|
656
|
-
// are kept, not dropped. `"template"` is the neutral generic fragment.
|
|
644
|
+
// `as` selects the parse mode: `"document"` parses a full page, any other
|
|
645
|
+
// value names the context element whose inner HTML this is, so that a
|
|
646
|
+
// partial's `<tr>`, `<td>` or `<option>` is kept rather than dropped.
|
|
657
647
|
/** @type {string | undefined} */
|
|
658
648
|
this.fragmentContext =
|
|
659
649
|
options.as === undefined || options.as === "document"
|
|
@@ -673,13 +663,9 @@ class HtmlParser extends Parser {
|
|
|
673
663
|
return;
|
|
674
664
|
}
|
|
675
665
|
|
|
676
|
-
//
|
|
677
|
-
//
|
|
678
|
-
//
|
|
679
|
-
// `{ attribute: "data-style", type: "stylesheet-style-attribute" }`).
|
|
680
|
-
// User entries override regardless of position. `dict()` keeps every
|
|
681
|
-
// table null-prototype (see its doc), and per-tag writes rebuild the
|
|
682
|
-
// bucket so the aliased default buckets stay intact.
|
|
666
|
+
// `"..."` anywhere opts the per-tag defaults in as the base, and a user
|
|
667
|
+
// entry with no `tag` is an any-tag source; user entries override wherever
|
|
668
|
+
// they sit. Per-tag writes rebuild the bucket, so the defaults stay intact.
|
|
683
669
|
/** @type {SourceTable} */
|
|
684
670
|
const byTag = sources.includes("...")
|
|
685
671
|
? dict(DEFAULT_SOURCES_BY_TAG)
|
|
@@ -804,14 +790,9 @@ class HtmlParser extends Parser {
|
|
|
804
790
|
const css = Boolean(compilation.options.experiments.css);
|
|
805
791
|
const urlHints = this._urlHints;
|
|
806
792
|
|
|
807
|
-
//
|
|
808
|
-
//
|
|
809
|
-
//
|
|
810
|
-
// path (a plain absolute path) — going through `contextify` against
|
|
811
|
-
// the compilation root keeps the hash machine-stable for the same
|
|
812
|
-
// project layout. Note: `module.identifier()` returns `html|<path>`
|
|
813
|
-
// for HTML modules, which doesn't start with `/`, so contextify would
|
|
814
|
-
// leave it absolute. `module.resource` is the bare path.
|
|
793
|
+
// Per-module prefix keeping generated entry names from colliding across the
|
|
794
|
+
// HTML modules of one compilation. It hashes `module.resource` rather than
|
|
795
|
+
// `identifier()`, whose `html|` prefix `contextify` would leave absolute.
|
|
815
796
|
/** @type {string} */
|
|
816
797
|
const resource =
|
|
817
798
|
/** @type {EXPECTED_ANY} */ (module).resource || module.identifier();
|
|
@@ -820,11 +801,9 @@ class HtmlParser extends Parser {
|
|
|
820
801
|
.digest("hex")
|
|
821
802
|
.slice(0, 8);
|
|
822
803
|
|
|
823
|
-
// `output.html` head injection
|
|
824
|
-
//
|
|
825
|
-
//
|
|
826
|
-
// wrappers already carry the tags and iframe srcdoc pages must stay
|
|
827
|
-
// untouched.
|
|
804
|
+
// `output.html` head injection collects facts during the walk and turns
|
|
805
|
+
// them into presentational dependencies after, so no later pass re-parses
|
|
806
|
+
// the page. `data:` documents are skipped — they already carry the tags.
|
|
828
807
|
const htmlOutputOptions =
|
|
829
808
|
compilation.options && compilation.options.output
|
|
830
809
|
? compilation.options.output.html
|
|
@@ -846,10 +825,9 @@ class HtmlParser extends Parser {
|
|
|
846
825
|
let inHead = false;
|
|
847
826
|
// `<template>` contents are inert
|
|
848
827
|
let headTemplateDepth = 0;
|
|
849
|
-
// Depth of open `<template>` elements anywhere in the tree
|
|
850
|
-
//
|
|
851
|
-
//
|
|
852
|
-
// templates seen while in `<head>`, so it can't guard body templates).
|
|
828
|
+
// Depth of open `<template>` elements anywhere in the tree: their content
|
|
829
|
+
// is an inert fragment, so a `<base>` inside one must not set the document
|
|
830
|
+
// base. `headTemplateDepth` covers only `<head>`, so it cannot guard this.
|
|
853
831
|
let templateDepth = 0;
|
|
854
832
|
let headHasTitle = false;
|
|
855
833
|
let headHasBase = false;
|
|
@@ -857,17 +835,14 @@ class HtmlParser extends Parser {
|
|
|
857
835
|
/** @type {Set<string> | undefined} */
|
|
858
836
|
let headMetaNames;
|
|
859
837
|
|
|
860
|
-
//
|
|
861
|
-
//
|
|
862
|
-
//
|
|
863
|
-
// leader-only dependOn so they share a runtime.
|
|
864
|
-
// `<link rel="modulepreload">` entries are kept independent — they
|
|
865
|
-
// must preload without running, so they can never become a runtime
|
|
866
|
-
// leader that other entries would import.
|
|
838
|
+
// Collected per type during the walk; HtmlModulesPlugin turns them into
|
|
839
|
+
// entries. `script` and `script-module` chain through a leader-only
|
|
840
|
+
// dependOn; modulepreload stays independent, as it must not run.
|
|
867
841
|
/**
|
|
868
842
|
* @typedef {object} HtmlEntryInfo
|
|
869
843
|
* @property {string} request
|
|
870
844
|
* @property {string} entryName
|
|
845
|
+
* @property {number} index position in the document, across all groups — the order the emitted files are named in
|
|
871
846
|
* @property {"script" | "script-module" | "modulepreload" | "stylesheet" | "html" | "preload" | "prefetch"} type
|
|
872
847
|
* @property {boolean=} css entry emits a CSS chunk (`<link rel="preload" as="style">`), so it needs the CSS filename template
|
|
873
848
|
*/
|
|
@@ -891,28 +866,26 @@ class HtmlParser extends Parser {
|
|
|
891
866
|
/** @type {HtmlEntryInfo[]} */
|
|
892
867
|
const prefetchEntries = [];
|
|
893
868
|
|
|
894
|
-
// Offset of the first classic blocking script tag
|
|
895
|
-
// `<link>`s stay ahead of
|
|
896
|
-
//
|
|
897
|
-
// so CSS may follow their tags (the order Vite emits).
|
|
869
|
+
// Offset of the first classic blocking script tag, which injected stylesheet
|
|
870
|
+
// `<link>`s stay ahead of. `defer`/`async`/module scripts do not anchor: they
|
|
871
|
+
// run after parsing and after pending stylesheets.
|
|
898
872
|
let firstBlockingScriptStart = -1;
|
|
899
873
|
|
|
900
874
|
let nextEntryIndex = 0;
|
|
901
875
|
|
|
902
|
-
// `<base href>` resolves the relative URLs that follow it. A relative base
|
|
903
|
-
// (`./assets/`) rewrites them into a subdirectory
|
|
904
|
-
// root-relative or absolute
|
|
905
|
-
//
|
|
906
|
-
//
|
|
876
|
+
// WHY: `<base href>` resolves the relative URLs that follow it. A relative base
|
|
877
|
+
// (`./assets/`) rewrites them into a subdirectory and they stay bundled; a
|
|
878
|
+
// root-relative or absolute one (`/`, `https://cdn/`) points outside the
|
|
879
|
+
// build, so those URLs are left untouched. Resolved in the walk below from
|
|
880
|
+
// the first `<base href>` seen, `documentBase` being undefined until then.
|
|
907
881
|
/** @type {string | undefined} */
|
|
908
882
|
let documentBase;
|
|
909
883
|
/** @type {string | undefined} */
|
|
910
884
|
let baseDir;
|
|
911
885
|
let baseIsExternal = false;
|
|
912
|
-
// Prepended to the emitted URLs' auto-public-path undo path
|
|
913
|
-
//
|
|
914
|
-
//
|
|
915
|
-
// it. Undefined for absolute publicPath (no undo path is emitted).
|
|
886
|
+
// Prepended to the emitted URLs' auto-public-path undo path: the browser
|
|
887
|
+
// resolves them against the base dir, so one `../` per base segment cancels
|
|
888
|
+
// it. Undefined for an absolute publicPath, which emits no undo path.
|
|
916
889
|
/** @type {string | undefined} */
|
|
917
890
|
let baseUrlPrefix;
|
|
918
891
|
|
|
@@ -1016,10 +989,9 @@ class HtmlParser extends Parser {
|
|
|
1016
989
|
baseIsExternal = true;
|
|
1017
990
|
return;
|
|
1018
991
|
}
|
|
1019
|
-
// Normalize the base path into
|
|
1020
|
-
//
|
|
1021
|
-
//
|
|
1022
|
-
// dot-segment; `up` counts `..`s that climb above the document dir.
|
|
992
|
+
// Normalize the base path into descending directory segments, resolving
|
|
993
|
+
// `.`/`..` as the URL spec does. The final segment names a file and is
|
|
994
|
+
// dropped; `up` counts the `..`s climbing above the document dir.
|
|
1023
995
|
const parts = documentBase.split("/");
|
|
1024
996
|
/** @type {string[]} */
|
|
1025
997
|
const dirs = [];
|
|
@@ -1069,9 +1041,8 @@ class HtmlParser extends Parser {
|
|
|
1069
1041
|
};
|
|
1070
1042
|
|
|
1071
1043
|
// TODO implement full HTML parser (WASM)
|
|
1072
|
-
// The walker descends into children
|
|
1073
|
-
//
|
|
1074
|
-
// children are done (the old `walkChildren` behaviour).
|
|
1044
|
+
// The walker descends into children and `<template>` content itself, and the
|
|
1045
|
+
// Element `exit` clears a pending `webpackIgnore` once they are done.
|
|
1075
1046
|
new SourceProcessor()
|
|
1076
1047
|
.use({
|
|
1077
1048
|
[NodeType.Comment]: (path) => {
|
|
@@ -1219,9 +1190,8 @@ class HtmlParser extends Parser {
|
|
|
1219
1190
|
pendingWebpackIgnore = undefined;
|
|
1220
1191
|
pendingWebpackInline = undefined;
|
|
1221
1192
|
|
|
1222
|
-
// `<head>` anchors are collected for every page
|
|
1223
|
-
// `inject: "head"` siblings and resource hints
|
|
1224
|
-
// title/meta/base facts only when configured. Structural, so it
|
|
1193
|
+
// `<head>` anchors are collected for every page, since they place
|
|
1194
|
+
// `inject: "head"` siblings and resource hints. Structural, so this
|
|
1225
1195
|
// runs even for `webpackIgnore`d elements.
|
|
1226
1196
|
{
|
|
1227
1197
|
const name = path.tagName();
|
|
@@ -1446,11 +1416,9 @@ class HtmlParser extends Parser {
|
|
|
1446
1416
|
module.addCodeGenerationDependency(dep);
|
|
1447
1417
|
break;
|
|
1448
1418
|
}
|
|
1449
|
-
// `<iframe srcdoc
|
|
1450
|
-
//
|
|
1451
|
-
// `
|
|
1452
|
-
// whose URL is `about:srcdoc`, so its base URL is inherited from
|
|
1453
|
-
// this document — asset URLs resolve against this file's context.
|
|
1419
|
+
// `<iframe srcdoc>` is an entity-encoded document, fed back through
|
|
1420
|
+
// the pipeline as a nested `data:text/html` module. Its URL is
|
|
1421
|
+
// `about:srcdoc`, so asset URLs resolve against this file.
|
|
1454
1422
|
case "srcdoc": {
|
|
1455
1423
|
const htmlText = decodeEntities(value, true);
|
|
1456
1424
|
// Only spin up a nested module when there is markup that can
|
|
@@ -1478,7 +1446,8 @@ class HtmlParser extends Parser {
|
|
|
1478
1446
|
const scriptType =
|
|
1479
1447
|
/** @type {"script" | "script-module"} */ (type);
|
|
1480
1448
|
const request = dataUri("text/javascript", value);
|
|
1481
|
-
const
|
|
1449
|
+
const index = nextEntryIndex++;
|
|
1450
|
+
const entryName = `__html_${moduleHash}_${index}`;
|
|
1482
1451
|
const dep = new HtmlInlineScriptDependency(
|
|
1483
1452
|
request,
|
|
1484
1453
|
nameEnd,
|
|
@@ -1501,6 +1470,7 @@ class HtmlParser extends Parser {
|
|
|
1501
1470
|
).push({
|
|
1502
1471
|
request,
|
|
1503
1472
|
entryName,
|
|
1473
|
+
index,
|
|
1504
1474
|
type: scriptType
|
|
1505
1475
|
});
|
|
1506
1476
|
break;
|
|
@@ -1576,12 +1546,12 @@ class HtmlParser extends Parser {
|
|
|
1576
1546
|
}
|
|
1577
1547
|
const s = start + (map ? map[us] : us);
|
|
1578
1548
|
const e = start + (map ? map[ue] : ue);
|
|
1579
|
-
// `html` links the URL as its own emitted page: the same
|
|
1580
|
-
//
|
|
1581
|
-
//
|
|
1582
|
-
// Recorded as an independent entry (no `dependOn`), like an entry point.
|
|
1549
|
+
// `html` links the URL as its own emitted page: the same dependency
|
|
1550
|
+
// as `<script src>`, but rewriting to the page's filename and
|
|
1551
|
+
// emitting no siblings. Independent, like an entry point.
|
|
1583
1552
|
if (type === "html") {
|
|
1584
|
-
const
|
|
1553
|
+
const index = nextEntryIndex++;
|
|
1554
|
+
const entryName = `__html_${moduleHash}_${index}`;
|
|
1585
1555
|
const dep = new HtmlEntryDependency(
|
|
1586
1556
|
request,
|
|
1587
1557
|
[s, e],
|
|
@@ -1591,23 +1561,22 @@ class HtmlParser extends Parser {
|
|
|
1591
1561
|
);
|
|
1592
1562
|
setLoc(dep, s, e);
|
|
1593
1563
|
module.addPresentationalDependency(dep);
|
|
1594
|
-
htmlLinkEntries.push({ request, entryName, type });
|
|
1564
|
+
htmlLinkEntries.push({ request, entryName, index, type });
|
|
1595
1565
|
continue;
|
|
1596
1566
|
}
|
|
1597
|
-
// `rel="preload"/"prefetch"` of a bundled resource: an
|
|
1598
|
-
//
|
|
1599
|
-
//
|
|
1600
|
-
// sibling tags — a resource hint references exactly one URL.
|
|
1567
|
+
// `rel="preload"/"prefetch"` of a bundled resource: an independent,
|
|
1568
|
+
// non-executing entry rewritten to the built chunk's URL. No
|
|
1569
|
+
// siblings — a resource hint references exactly one URL.
|
|
1601
1570
|
if (type === "preload" || type === "prefetch") {
|
|
1602
1571
|
const as = getAttributeValue(getAttributesMap(), "as");
|
|
1603
1572
|
const asStyle = as
|
|
1604
1573
|
? as.trim().toLowerCase() === "style"
|
|
1605
1574
|
: false;
|
|
1606
|
-
const
|
|
1607
|
-
|
|
1608
|
-
//
|
|
1609
|
-
//
|
|
1610
|
-
//
|
|
1575
|
+
const index = nextEntryIndex++;
|
|
1576
|
+
const entryName = `__html_${moduleHash}_${index}`;
|
|
1577
|
+
// Tag metadata letting the template mirror `crossorigin` and
|
|
1578
|
+
// `integrity` onto a native `preload` `<link>`. `prefetch` is not
|
|
1579
|
+
// integrity-eligible per the SRI spec, so its is left uncaptured.
|
|
1611
1580
|
const isNativeLink = elementName === "link";
|
|
1612
1581
|
const dep = new HtmlEntryDependency(
|
|
1613
1582
|
request,
|
|
@@ -1635,6 +1604,7 @@ class HtmlParser extends Parser {
|
|
|
1635
1604
|
).push({
|
|
1636
1605
|
request,
|
|
1637
1606
|
entryName,
|
|
1607
|
+
index,
|
|
1638
1608
|
type,
|
|
1639
1609
|
css: asStyle
|
|
1640
1610
|
});
|
|
@@ -1649,7 +1619,8 @@ class HtmlParser extends Parser {
|
|
|
1649
1619
|
type === "modulepreload" ||
|
|
1650
1620
|
type === "stylesheet"
|
|
1651
1621
|
) {
|
|
1652
|
-
const
|
|
1622
|
+
const index = nextEntryIndex++;
|
|
1623
|
+
const entryName = `__html_${moduleHash}_${index}`;
|
|
1653
1624
|
const willBeModuleScript =
|
|
1654
1625
|
type === "script-module" ||
|
|
1655
1626
|
(outputModule && type === "script");
|
|
@@ -1693,13 +1664,9 @@ class HtmlParser extends Parser {
|
|
|
1693
1664
|
}
|
|
1694
1665
|
}
|
|
1695
1666
|
}
|
|
1696
|
-
// Blocking-ness of the tag as
|
|
1697
|
-
// `reconcileScriptTypeAttr`
|
|
1698
|
-
//
|
|
1699
|
-
// authored `type="module"` otherwise — so only non-module
|
|
1700
|
-
// output without `defer`/`async` blocks. Non-native
|
|
1701
|
-
// elements anchor conservatively (their synthesized
|
|
1702
|
-
// siblings may be plain blocking `<script>`s).
|
|
1667
|
+
// Blocking-ness of the tag as emitted, not as authored:
|
|
1668
|
+
// `reconcileScriptTypeAttr` decides the final `type`, so only
|
|
1669
|
+
// non-module output without `defer`/`async` blocks.
|
|
1703
1670
|
if (
|
|
1704
1671
|
firstBlockingScriptStart === -1 &&
|
|
1705
1672
|
(type === "script" || type === "script-module") &&
|
|
@@ -1710,11 +1677,9 @@ class HtmlParser extends Parser {
|
|
|
1710
1677
|
) {
|
|
1711
1678
|
firstBlockingScriptStart = elementStart;
|
|
1712
1679
|
}
|
|
1713
|
-
// Sibling-clone attribute edits, captured
|
|
1714
|
-
//
|
|
1715
|
-
//
|
|
1716
|
-
// (content-specific) and `script-module` clones are forced
|
|
1717
|
-
// to `type="module"` (its value range, else inserted).
|
|
1680
|
+
// Sibling-clone attribute edits, captured as offsets relative to
|
|
1681
|
+
// the tag so the template need not re-parse it: `integrity` is
|
|
1682
|
+
// content-specific and dropped, `script-module` forces `type`.
|
|
1718
1683
|
const integrityRange =
|
|
1719
1684
|
elementStart >= 0 && elementName === nativeTag
|
|
1720
1685
|
? captureIntegrityRange(path, source, elementStart)
|
|
@@ -1777,7 +1742,7 @@ class HtmlParser extends Parser {
|
|
|
1777
1742
|
: type === "stylesheet"
|
|
1778
1743
|
? stylesheetEntries
|
|
1779
1744
|
: modulePreloadEntries
|
|
1780
|
-
).push({ request, entryName, type });
|
|
1745
|
+
).push({ request, entryName, index, type });
|
|
1781
1746
|
} else {
|
|
1782
1747
|
const dep = new HtmlSourceDependency(request, [s, e]);
|
|
1783
1748
|
ResourceHintPlugin.applyDefaults(
|
|
@@ -1816,10 +1781,9 @@ class HtmlParser extends Parser {
|
|
|
1816
1781
|
}
|
|
1817
1782
|
}
|
|
1818
1783
|
})
|
|
1819
|
-
// Skip AST output this walk never reads: `text
|
|
1820
|
-
// read by offset
|
|
1821
|
-
//
|
|
1822
|
-
// magic comments (`webpackIgnore`).
|
|
1784
|
+
// Skip AST output this walk never reads: `text`, since script and style
|
|
1785
|
+
// bodies are read by offset, and `doctype` unless head injection needs it
|
|
1786
|
+
// as an anchor. `comments` stays, for `webpackIgnore`.
|
|
1823
1787
|
.process(source, {
|
|
1824
1788
|
fragmentContext: this.fragmentContext,
|
|
1825
1789
|
skip: { text: true, doctype: headOptions === undefined }
|
|
@@ -1874,13 +1838,12 @@ class HtmlParser extends Parser {
|
|
|
1874
1838
|
const buildInfo = /** @type {HtmlModuleBuildInfo} */ (module.buildInfo);
|
|
1875
1839
|
buildInfo.strict = true;
|
|
1876
1840
|
if (baseUrlPrefix !== undefined) buildInfo.baseUrlPrefix = baseUrlPrefix;
|
|
1877
|
-
//
|
|
1878
|
-
// real compilation entries during the finishMake hook. The `script`
|
|
1879
|
-
//
|
|
1880
|
-
//
|
|
1881
|
-
//
|
|
1882
|
-
//
|
|
1883
|
-
// links are independent page entries too.
|
|
1841
|
+
// WHY: hand the collected entries to HtmlModulesPlugin, which creates the
|
|
1842
|
+
// real compilation entries during the finishMake hook. The `script` and
|
|
1843
|
+
// `script-module` groups chain through a leader-only `dependOn` so they share
|
|
1844
|
+
// a runtime, while `modulepreload` and `stylesheet` entries are independent:
|
|
1845
|
+
// `<link rel=modulepreload>` must preload without running, and a stylesheet
|
|
1846
|
+
// has no runtime. `html` links are independent page entries too.
|
|
1884
1847
|
if (
|
|
1885
1848
|
scriptEntries.length > 0 ||
|
|
1886
1849
|
scriptModuleEntries.length > 0 ||
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
/*
|
|
2
|
+
MIT License http://www.opensource.org/licenses/mit-license.php
|
|
3
|
+
Author Alexander Akait @alexander-akait
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
"use strict";
|
|
7
|
+
|
|
8
|
+
const { CSS_TYPE } = require("../ModuleSourceTypeConstants");
|
|
9
|
+
|
|
10
|
+
/** @import { CssProcessOptions } from "../css/syntax" */
|
|
11
|
+
/** @import { EmbeddedSourceRenderer } from "./syntax" */
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* What this minifies inline CSS with: the CSS minifier's own options, so an
|
|
15
|
+
* inline declaration is held to the rules a `.css` asset is.
|
|
16
|
+
* @typedef {Pick<CssProcessOptions, "environment" | "convertLengthUnits" | "rewriteCustomProperties" | "transforms" | "unusedSymbols" | "pseudoClasses">} BuiltinEmbeddedRendererOptions
|
|
17
|
+
*/
|
|
18
|
+
|
|
19
|
+
// Both are loaded on first render rather than at module load: a document that
|
|
20
|
+
// embeds no CSS and no JSON pays for neither.
|
|
21
|
+
/** @type {typeof import("../css/syntax") | undefined} */
|
|
22
|
+
let _cssSyntax;
|
|
23
|
+
/** @type {typeof import("./syntax") | undefined} */
|
|
24
|
+
let _htmlSyntax;
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* Strip the whitespace between a JSON body's tokens, every literal copied byte
|
|
28
|
+
* for byte. Re-serializing would round numbers, drop a duplicate key and rewrite
|
|
29
|
+
* the escapes that keep a string from closing the `<script>` early.
|
|
30
|
+
* @param {string} json a `<script>` body
|
|
31
|
+
* @returns {string} the stripped body, or the body as written where it is not JSON
|
|
32
|
+
*/
|
|
33
|
+
const stripJsonWhitespace = (json) => {
|
|
34
|
+
try {
|
|
35
|
+
JSON.parse(json);
|
|
36
|
+
} catch (_err) {
|
|
37
|
+
// Not JSON after all (a template, a placeholder) — not ours to touch.
|
|
38
|
+
return json;
|
|
39
|
+
}
|
|
40
|
+
let out = "";
|
|
41
|
+
let inString = false;
|
|
42
|
+
let escaped = false;
|
|
43
|
+
for (let i = 0; i < json.length; i++) {
|
|
44
|
+
const c = json.charCodeAt(i);
|
|
45
|
+
if (inString) {
|
|
46
|
+
out += json[i];
|
|
47
|
+
if (escaped) escaped = false;
|
|
48
|
+
else if (c === 0x5c) escaped = true;
|
|
49
|
+
else if (c === 0x22) inString = false;
|
|
50
|
+
continue;
|
|
51
|
+
}
|
|
52
|
+
if (c === 0x22) {
|
|
53
|
+
inString = true;
|
|
54
|
+
out += json[i];
|
|
55
|
+
continue;
|
|
56
|
+
}
|
|
57
|
+
// JSON whitespace (RFC 8259): tab, LF, CR, space.
|
|
58
|
+
if (c === 0x09 || c === 0x0a || c === 0x0d || c === 0x20) continue;
|
|
59
|
+
out += json[i];
|
|
60
|
+
}
|
|
61
|
+
return out;
|
|
62
|
+
};
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
* The renderer webpack ships for what a document embeds: its own CSS minifier
|
|
66
|
+
* for a `<style>` or `style=""` and `stripJsonWhitespace` for JSON, declining
|
|
67
|
+
* every other language. A caller passes it where it has no renderer of its own,
|
|
68
|
+
* or behind one for the languages that one declines — the HTML printer minifies
|
|
69
|
+
* none of this itself.
|
|
70
|
+
* @param {BuiltinEmbeddedRendererOptions=} options the CSS minifier's options, so an inline declaration is minified as the `.css` assets are
|
|
71
|
+
* @returns {EmbeddedSourceRenderer} the renderer
|
|
72
|
+
*/
|
|
73
|
+
const builtinEmbeddedRenderer = (options = {}) => {
|
|
74
|
+
const { BLOCK_CONTENTS, JSON_TYPE } =
|
|
75
|
+
_htmlSyntax || (_htmlSyntax = require("./syntax"));
|
|
76
|
+
const sheet = { mode: /** @type {"minify"} */ ("minify"), ...options };
|
|
77
|
+
const block = { ...sheet, as: BLOCK_CONTENTS };
|
|
78
|
+
// A `style=""` repeats across a document far more often than it varies.
|
|
79
|
+
/** @type {Map<string, string>} */
|
|
80
|
+
const blocks = new Map();
|
|
81
|
+
return (source, info) => {
|
|
82
|
+
if (info.type === JSON_TYPE) return stripJsonWhitespace(source);
|
|
83
|
+
if (info.type !== CSS_TYPE) return undefined;
|
|
84
|
+
const isBlock = info.as === BLOCK_CONTENTS;
|
|
85
|
+
if (isBlock) {
|
|
86
|
+
const memoized = blocks.get(source);
|
|
87
|
+
if (memoized !== undefined) return memoized;
|
|
88
|
+
}
|
|
89
|
+
const { SourceProcessor } =
|
|
90
|
+
_cssSyntax || (_cssSyntax = require("../css/syntax"));
|
|
91
|
+
let code;
|
|
92
|
+
try {
|
|
93
|
+
code = new SourceProcessor().process(
|
|
94
|
+
source,
|
|
95
|
+
isBlock ? block : sheet
|
|
96
|
+
).code;
|
|
97
|
+
} catch (_err) {
|
|
98
|
+
// Text the minifier cannot read is left as written, by declining.
|
|
99
|
+
return undefined;
|
|
100
|
+
}
|
|
101
|
+
if (isBlock) blocks.set(source, code);
|
|
102
|
+
return code;
|
|
103
|
+
};
|
|
104
|
+
};
|
|
105
|
+
|
|
106
|
+
module.exports.builtinEmbeddedRenderer = builtinEmbeddedRenderer;
|
|
107
|
+
module.exports.stripJsonWhitespace = stripJsonWhitespace;
|