@depup/webpack 5.110.3-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/CircularModulesPlugin.js +157 -55
- package/lib/CleanPlugin.js +2 -2
- package/lib/CompatibilityPlugin.js +3 -4
- package/lib/Compilation.js +336 -337
- package/lib/Compiler.js +213 -51
- 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 +24 -28
- package/lib/ErrorHelpers.js +113 -0
- package/lib/ExportsInfo.js +20 -16
- package/lib/ExternalModule.js +47 -22
- package/lib/FileSystemInfo.js +17 -14
- package/lib/FlagDependencyExportsPlugin.js +53 -34
- package/lib/FlagDependencyUsagePlugin.js +9 -13
- 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 +135 -50
- package/lib/NormalModuleFactory.js +1 -1
- package/lib/RuntimeGlobals.js +21 -7
- package/lib/RuntimeModule.js +28 -12
- package/lib/RuntimePlugin.js +30 -3
- package/lib/RuntimeTemplate.js +813 -518
- 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/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 +138 -128
- package/lib/config/getClaimedAssetTypes.js +10 -11
- package/lib/config/normalization.js +82 -12
- 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 +94 -36
- package/lib/css/CssModule.js +1 -1
- package/lib/css/CssModulesPlugin.js +7 -6
- 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 +3514 -869
- package/lib/css/syntax.js +6370 -1220
- 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 +14 -5
- package/lib/dependencies/CommonJsSelfReferenceDependency.js +2 -4
- package/lib/dependencies/ContextDependency.js +1 -1
- package/lib/dependencies/ContextDependencyHelpers.js +3 -9
- 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/HarmonyExportDependencyParserPlugin.js +10 -7
- package/lib/dependencies/HarmonyExportExpressionDependency.js +47 -33
- package/lib/dependencies/HarmonyExportImportedSpecifierDependency.js +74 -17
- 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 +6 -1
- package/lib/dependencies/HarmonyImportDependencyParserPlugin.js +111 -17
- package/lib/dependencies/HarmonyImportSideEffectDependency.js +3 -4
- package/lib/dependencies/HarmonyImportSpecifierDependency.js +40 -3
- package/lib/dependencies/HarmonyModulesPlugin.js +20 -0
- package/lib/dependencies/HtmlEntryDependency.js +124 -102
- package/lib/dependencies/HtmlInlineScriptDependency.js +3 -4
- package/lib/dependencies/HtmlInlineStyleDependency.js +3 -4
- 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 +1 -1
- package/lib/dependencies/LoaderPlugin.js +26 -1
- package/lib/dependencies/RequireContextDependencyParserPlugin.js +1 -1
- 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 +15 -21
- package/lib/dependencies/WorkerDependency.js +7 -7
- package/lib/dependencies/WorkletDependency.js +7 -11
- 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/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/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 +30 -11
- package/lib/esm/ModuleChunkLoadingRuntimeModule.js +92 -60
- 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 +418 -200
- 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 +1618 -1391
- 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 +73 -72
- 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 +137 -9
- package/lib/node/NodeWatchFileSystem.js +3 -9
- package/lib/node/ReadFileChunkLoadingRuntimeModule.js +22 -0
- package/lib/node/RequireChunkLoadingRuntimeModule.js +22 -0
- package/lib/optimize/AggressiveMergingPlugin.js +3 -5
- package/lib/optimize/ConcatenatedModule.js +178 -120
- package/lib/optimize/ConstExportsPlugin.js +50 -39
- package/lib/optimize/FlagIncludedChunksPlugin.js +3 -11
- package/lib/optimize/InlineExports.js +20 -123
- 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 +68 -9
- 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 +18 -23
- 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 +98 -66
- 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 +305 -224
- 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/VirtualUrlPlugin.js +1 -1
- package/lib/serialization/BinaryMiddleware.js +9 -9
- package/lib/serialization/FileMiddleware.js +16 -16
- 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 +2 -3
- package/lib/url/URLParserPlugin.js +6 -8
- package/lib/util/LocConverter.js +4 -7
- package/lib/util/SourceProcessor.js +91 -91
- 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/createHooksRegistry.js +1 -2
- 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 +5 -1
- package/lib/util/registerExternalSerializer.js +6 -45
- package/lib/util/semver.js +5 -3
- package/lib/wasm-async/AsyncWasmCompileRuntimeModule.js +9 -0
- package/lib/wasm-async/AsyncWasmLoadingRuntimeModule.js +9 -0
- package/lib/wasm-async/AsyncWebAssemblyGenerator.js +6 -1
- package/lib/wasm-async/AsyncWebAssemblyJavascriptGenerator.js +5 -1
- 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/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 +379 -66
- 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 +1723 -604
- package/lib/dependencies/ExportBindingInitFragment.js +0 -191
- package/lib/errors/EntrypointOverlapWarning.js +0 -45
- package/lib/performance/EntrypointOverlapPlugin.js +0 -122
|
@@ -7,6 +7,7 @@
|
|
|
7
7
|
const {
|
|
8
8
|
CSS_IMPORT_TYPE,
|
|
9
9
|
CSS_TYPE,
|
|
10
|
+
HTML_TYPE,
|
|
10
11
|
JAVASCRIPT_TYPE
|
|
11
12
|
} = require("../ModuleSourceTypeConstants");
|
|
12
13
|
const ResourceHintPlugin = require("../prefetch/ResourceHintPlugin");
|
|
@@ -497,11 +498,12 @@ const cloneTagWithUrl = (
|
|
|
497
498
|
return isLink ? body : `${body}</script>`;
|
|
498
499
|
};
|
|
499
500
|
|
|
500
|
-
// ES5 `<link rel="modulepreload">` polyfill (Safari <17, Firefox <115,
|
|
501
|
-
//
|
|
502
|
-
// tag's own credentials
|
|
503
|
-
// `.ep` guard makes
|
|
504
|
-
//
|
|
501
|
+
// WHY: an ES5 `<link rel="modulepreload">` polyfill (Safari <17, Firefox <115,
|
|
502
|
+
// …). On a browser without native support, each modulepreload target is fetched
|
|
503
|
+
// with the tag's own credentials and integrity, so the pending module import
|
|
504
|
+
// reuses it. The `.ep` guard makes that idempotent and the observer catches any
|
|
505
|
+
// later-inserted link. Emitted only where the target environment lacks native
|
|
506
|
+
// support.
|
|
505
507
|
const MODULEPRELOAD_POLYFILL = [
|
|
506
508
|
"(function(){",
|
|
507
509
|
'var s=document.createElement("link").relList;',
|
|
@@ -587,6 +589,47 @@ const buildLinkTag = (rel, attrs) =>
|
|
|
587
589
|
: ""
|
|
588
590
|
}>`;
|
|
589
591
|
|
|
592
|
+
/**
|
|
593
|
+
* The chunks a hint means when it names a page: a page loads no JavaScript of
|
|
594
|
+
* its own, so the hint follows the entries the parser extracted from it.
|
|
595
|
+
* @param {import("../Compilation")} compilation compilation
|
|
596
|
+
* @param {Chunk} chunk chunk a hint resolved to
|
|
597
|
+
* @returns {Chunk[]} the chunks to hint at
|
|
598
|
+
*/
|
|
599
|
+
const resolvePageChunk = (compilation, chunk) => {
|
|
600
|
+
const { chunkGraph } = compilation;
|
|
601
|
+
const modules = chunkGraph.getChunkModulesIterableBySourceType(
|
|
602
|
+
chunk,
|
|
603
|
+
HTML_TYPE
|
|
604
|
+
);
|
|
605
|
+
// A page with a JavaScript side of its own (an `output.library` entry) is
|
|
606
|
+
// hinted too — `chunkHasJs` can't say so, it holds for any runtime chunk.
|
|
607
|
+
const javascript = chunkGraph.getChunkModulesIterableBySourceType(
|
|
608
|
+
chunk,
|
|
609
|
+
JAVASCRIPT_TYPE
|
|
610
|
+
);
|
|
611
|
+
/** @type {Chunk[]} */
|
|
612
|
+
const chunks = javascript === undefined ? [] : [chunk];
|
|
613
|
+
// A chunk carrying no page stands for itself; a page stands for the entries
|
|
614
|
+
// extracted from it, so one that extracted nothing hints nothing.
|
|
615
|
+
if (modules === undefined) return chunks.length === 0 ? [chunk] : chunks;
|
|
616
|
+
for (const module of modules) {
|
|
617
|
+
const { htmlEntries } =
|
|
618
|
+
/** @type {import("../html/HtmlModule").HtmlModuleBuildInfo} */ (
|
|
619
|
+
module.buildInfo
|
|
620
|
+
) || {};
|
|
621
|
+
if (!htmlEntries) continue;
|
|
622
|
+
for (const group of Object.values(htmlEntries)) {
|
|
623
|
+
for (const { entryName } of group) {
|
|
624
|
+
const entrypoint = compilation.entrypoints.get(entryName);
|
|
625
|
+
const entryChunk = entrypoint && entrypoint.getEntrypointChunk();
|
|
626
|
+
if (entryChunk) chunks.push(entryChunk);
|
|
627
|
+
}
|
|
628
|
+
}
|
|
629
|
+
}
|
|
630
|
+
return chunks;
|
|
631
|
+
};
|
|
632
|
+
|
|
590
633
|
/**
|
|
591
634
|
* Resolve one `output.html.resourceHints` descriptor to zero or more `<link>`
|
|
592
635
|
* tags. A `chunk`/`entry` reference becomes the emitted chunk URL (a sentinel
|
|
@@ -633,6 +676,14 @@ const resolveResourceHint = (desc, ctx) => {
|
|
|
633
676
|
} else {
|
|
634
677
|
return [];
|
|
635
678
|
}
|
|
679
|
+
/** @type {Chunk[]} */
|
|
680
|
+
const hinted = [];
|
|
681
|
+
for (const chunk of chunks) {
|
|
682
|
+
for (const resolved of resolvePageChunk(ctx.compilation, chunk)) {
|
|
683
|
+
hinted.push(resolved);
|
|
684
|
+
}
|
|
685
|
+
}
|
|
686
|
+
chunks = hinted;
|
|
636
687
|
const kind = desc.as === "style" ? "css" : "javascript";
|
|
637
688
|
const as = desc.as || (rel === "modulepreload" ? undefined : "script");
|
|
638
689
|
// A hint targeting another chunk must match how that chunk is fetched, so
|
|
@@ -687,10 +738,9 @@ HtmlEntryDependency.Template = class HtmlEntryDependencyTemplate extends (
|
|
|
687
738
|
const dep = /** @type {HtmlEntryDependency} */ (dependency);
|
|
688
739
|
const compilation = runtimeTemplate.compilation;
|
|
689
740
|
|
|
690
|
-
// A `type: "html"` link points at another emitted page
|
|
691
|
-
//
|
|
692
|
-
//
|
|
693
|
-
// link loads only itself.
|
|
741
|
+
// A `type: "html"` link points at another emitted page rather than a chunk,
|
|
742
|
+
// so rewrite the attribute to that page's filename and emit no siblings:
|
|
743
|
+
// a page link loads only itself.
|
|
694
744
|
if (dep.elementKind === "html") {
|
|
695
745
|
source.replace(
|
|
696
746
|
dep.range[0],
|
|
@@ -714,21 +764,17 @@ HtmlEntryDependency.Template = class HtmlEntryDependencyTemplate extends (
|
|
|
714
764
|
const orderedChunks = getEntrypointChunksInLoadOrder(entrypoint);
|
|
715
765
|
const entryChunk = orderedChunks[orderedChunks.length - 1];
|
|
716
766
|
|
|
717
|
-
//
|
|
718
|
-
//
|
|
719
|
-
// `crossorigin`
|
|
720
|
-
// webpack's runtime, which sets `crossOrigin` on chunk-loading scripts,
|
|
721
|
-
// and matches Vite, which emits it on every injected script/stylesheet.
|
|
767
|
+
// Mirrors `output.crossOriginLoading` onto every injected tag, as webpack's
|
|
768
|
+
// runtime does for chunk-loading scripts. Empty when the option is off or
|
|
769
|
+
// the originating tag set `crossorigin` itself, since the author wins.
|
|
722
770
|
const crossOrigin =
|
|
723
771
|
crossOriginLoading && !dep.hasOwnCrossOrigin
|
|
724
772
|
? ` crossorigin="${crossOriginLoading}"`
|
|
725
773
|
: "";
|
|
726
774
|
|
|
727
|
-
// Per-chunk SRI
|
|
728
|
-
//
|
|
729
|
-
//
|
|
730
|
-
// `integrity` options, so sentinels are emitted whenever any page wants SRI
|
|
731
|
-
// and each page then resolves or strips them on emit.
|
|
775
|
+
// Per-chunk SRI emits an `integrity` sentinel resolved once the chunks'
|
|
776
|
+
// final bytes exist. One module can back pages with different `integrity`
|
|
777
|
+
// options, so every page emits them and strips its own on emit.
|
|
732
778
|
const htmlOption = compilation.outputOptions.html;
|
|
733
779
|
const integrityOn = getHtmlGenerator().hasIntegritySentinels(compilation);
|
|
734
780
|
const inject =
|
|
@@ -898,11 +944,9 @@ HtmlEntryDependency.Template = class HtmlEntryDependencyTemplate extends (
|
|
|
898
944
|
? ` integrity="${getHtmlGenerator().makeChunkIntegritySentinel(chunk, kind)}"`
|
|
899
945
|
: "";
|
|
900
946
|
if (kind === "css") {
|
|
901
|
-
// A CSS chunk
|
|
902
|
-
//
|
|
903
|
-
//
|
|
904
|
-
// a `<script>` entry that imported CSS, or a custom element,
|
|
905
|
-
// gets a freshly synthesized `<link>`.
|
|
947
|
+
// A CSS chunk always loads through `<link rel="stylesheet">`. Clone
|
|
948
|
+
// only when the entry tag is itself one, so `media` carries over;
|
|
949
|
+
// anything else gets a freshly synthesized `<link>`.
|
|
906
950
|
if (isStylesheet && tagIsNative) {
|
|
907
951
|
return cloneTagWithUrl(
|
|
908
952
|
originalTag,
|
|
@@ -954,10 +998,9 @@ HtmlEntryDependency.Template = class HtmlEntryDependencyTemplate extends (
|
|
|
954
998
|
// Parser-derived anchor (a source text scan would match `</head>` inside
|
|
955
999
|
// comments or raw text).
|
|
956
1000
|
const headClose = inject === "head" ? dep.headAnchor : -1;
|
|
957
|
-
//
|
|
958
|
-
//
|
|
959
|
-
//
|
|
960
|
-
// Insert before the entry tag instead so the load order is preserved.
|
|
1001
|
+
// With the entry tag already inside `<head>`, inserting at `headClose`
|
|
1002
|
+
// would place siblings after it and reverse runtime-before-entry order
|
|
1003
|
+
// for deferred scripts. Insert before the entry tag instead.
|
|
961
1004
|
const headAt =
|
|
962
1005
|
headClose < 0
|
|
963
1006
|
? -1
|
|
@@ -968,29 +1011,24 @@ HtmlEntryDependency.Template = class HtmlEntryDependencyTemplate extends (
|
|
|
968
1011
|
let cssHtml = "";
|
|
969
1012
|
let cssAt = -1;
|
|
970
1013
|
if (isStylesheet) {
|
|
971
|
-
// `<link rel="stylesheet">`
|
|
972
|
-
// JS-only chunk
|
|
973
|
-
//
|
|
974
|
-
// produce a `.css` asset
|
|
975
|
-
//
|
|
976
|
-
// `<style>` when inlined
|
|
1014
|
+
// WHY: a `<link rel="stylesheet">` entry is CSS, but a shared or runtime
|
|
1015
|
+
// JS-only chunk — `optimization.runtimeChunk`, say — can still sit in the
|
|
1016
|
+
// entrypoint, so the `<link>` is cloned only for siblings that actually
|
|
1017
|
+
// produce a `.css` asset, mirroring the JS branch below. Otherwise it
|
|
1018
|
+
// points at a `.css` file that does not exist: a 404, or an empty
|
|
1019
|
+
// `<style>` when inlined. Attributes such as `media` still carry over.
|
|
977
1020
|
for (let i = 0; i < orderedChunks.length - 1; i++) {
|
|
978
1021
|
if (chunkHasCss(orderedChunks[i], chunkGraph)) {
|
|
979
1022
|
siblings.push(buildSibling(orderedChunks[i], "css"));
|
|
980
1023
|
}
|
|
981
1024
|
}
|
|
982
1025
|
} else {
|
|
983
|
-
//
|
|
984
|
-
//
|
|
985
|
-
//
|
|
986
|
-
//
|
|
987
|
-
//
|
|
988
|
-
//
|
|
989
|
-
// *reverse* of the order they were processed — exactly the
|
|
990
|
-
// html-webpack-plugin#1838 / mini-css-extract#959 symptom). We
|
|
991
|
-
// re-derive the order from the entrypoint's module post-order
|
|
992
|
-
// index, which mirrors the dependency walk and so reflects the
|
|
993
|
-
// import order.
|
|
1026
|
+
// WHY: splitChunks inserts each new chunk before the entry chunk, so
|
|
1027
|
+
// `entrypoint.chunks` hands back split CSS siblings in reverse of the
|
|
1028
|
+
// order they were processed — the html-webpack-plugin#1838 and
|
|
1029
|
+
// mini-css-extract#959 symptom. The order is re-derived from the
|
|
1030
|
+
// entrypoint's module post-order index, which follows the dependency
|
|
1031
|
+
// walk and so the source's import order.
|
|
994
1032
|
/** @type {{ chunk: Chunk, index: number, key: string }[]} */
|
|
995
1033
|
const cssChunkOrder = [];
|
|
996
1034
|
/** @type {Chunk[]} */
|
|
@@ -1010,18 +1048,14 @@ HtmlEntryDependency.Template = class HtmlEntryDependencyTemplate extends (
|
|
|
1010
1048
|
key: cssChunkSortKey(chunk)
|
|
1011
1049
|
});
|
|
1012
1050
|
}
|
|
1013
|
-
// Anything
|
|
1014
|
-
//
|
|
1015
|
-
//
|
|
1016
|
-
// Chunks that produce no `.js` and no `.css` (e.g. wasm-only
|
|
1017
|
-
// or asset-only) still get a `<script>` clone here so we
|
|
1018
|
-
// keep prior behavior for users who relied on it.
|
|
1051
|
+
// Anything not CSS-only stays on the JS lane in `orderedChunks` order,
|
|
1052
|
+
// preserving the runtime-first invariant. A chunk emitting neither
|
|
1053
|
+
// `.js` nor `.css` still gets a clone, as it always has.
|
|
1019
1054
|
if (hasJs || !hasCss) jsChunks.push(chunk);
|
|
1020
1055
|
}
|
|
1021
|
-
//
|
|
1022
|
-
//
|
|
1023
|
-
//
|
|
1024
|
-
// cascade position relative to sibling CSS chunks.
|
|
1056
|
+
// When the entry chunk carries CSS itself, fold it into the same
|
|
1057
|
+
// ordering so its `<link>` lands in the right cascade position
|
|
1058
|
+
// relative to the sibling CSS chunks.
|
|
1025
1059
|
if (chunkHasCss(entryChunk, chunkGraph)) {
|
|
1026
1060
|
cssChunkOrder.push({
|
|
1027
1061
|
chunk: entryChunk,
|
|
@@ -1034,13 +1068,9 @@ HtmlEntryDependency.Template = class HtmlEntryDependencyTemplate extends (
|
|
|
1034
1068
|
});
|
|
1035
1069
|
}
|
|
1036
1070
|
cssChunkOrder.sort(compareCssChunkOrder);
|
|
1037
|
-
// Stylesheets
|
|
1038
|
-
//
|
|
1039
|
-
//
|
|
1040
|
-
// `defer`/module they go to the *end* of head, after the script
|
|
1041
|
-
// tags — Vite's and html-webpack-plugin's order: the scripts
|
|
1042
|
-
// start fetching earlier yet still execute after parsing and
|
|
1043
|
-
// after pending stylesheets.
|
|
1071
|
+
// Stylesheets land in `<head>`. A classic blocking script pins them
|
|
1072
|
+
// ahead of itself, so it never awaits later CSS; with only `defer` and
|
|
1073
|
+
// module scripts they go last, which starts the script fetches earlier.
|
|
1044
1074
|
cssAt =
|
|
1045
1075
|
dep.headAnchor >= 0
|
|
1046
1076
|
? dep.cssAnchor >= 0 && dep.cssAnchor < dep.headAnchor
|
|
@@ -1066,15 +1096,15 @@ HtmlEntryDependency.Template = class HtmlEntryDependencyTemplate extends (
|
|
|
1066
1096
|
if (cssHtml !== "" && dep.cssAnchor < 0) source.insert(cssAt, cssHtml);
|
|
1067
1097
|
}
|
|
1068
1098
|
|
|
1069
|
-
//
|
|
1070
|
-
//
|
|
1071
|
-
//
|
|
1072
|
-
//
|
|
1073
|
-
//
|
|
1074
|
-
// `defaultHints
|
|
1075
|
-
//
|
|
1076
|
-
//
|
|
1077
|
-
//
|
|
1099
|
+
// WHY: resource hints are opt-in, the initial chunks already loading
|
|
1100
|
+
// through parallel `<script>` tags, so there is no default waterfall to
|
|
1101
|
+
// prevent. `output.resourceHints` requests them: `true` preloads the entry's
|
|
1102
|
+
// initial dependency chunks (runtime, vendor, split), while an array or a
|
|
1103
|
+
// function adds custom ones and a function may spread the auto
|
|
1104
|
+
// `defaultHints`. Extracted pages only — a JS-string HTML export would embed
|
|
1105
|
+
// the sentinels in the JS chunk. A URL-referenced asset carrying
|
|
1106
|
+
// `webpackPrefetch` / `webpackPreload`, by magic comment or a
|
|
1107
|
+
// `parser.<type>.urlHints` rule, emits here too.
|
|
1078
1108
|
const resourceHintResolver =
|
|
1079
1109
|
ResourceHintPlugin.getCompilationResolver(compilation);
|
|
1080
1110
|
const resourceHints = resourceHintResolver.hints;
|
|
@@ -1102,15 +1132,16 @@ HtmlEntryDependency.Template = class HtmlEntryDependencyTemplate extends (
|
|
|
1102
1132
|
|
|
1103
1133
|
// === chunks channel — the entry's own initial dependency graph ===
|
|
1104
1134
|
if (resourceHints !== undefined && resourceHints !== false) {
|
|
1105
|
-
//
|
|
1106
|
-
// tag
|
|
1107
|
-
// function may spread them
|
|
1108
|
-
//
|
|
1109
|
-
//
|
|
1110
|
-
//
|
|
1111
|
-
// `integrity
|
|
1112
|
-
//
|
|
1113
|
-
// which routes through
|
|
1135
|
+
// WHY: descriptors for the auto initial-graph preload, carrying their
|
|
1136
|
+
// exact tag and built only when needed — `true` or `"prefetch"` emits
|
|
1137
|
+
// them, and a function may spread them. The entry chunk is skipped, being
|
|
1138
|
+
// the `<script src>` already. ESM uses `modulepreload`, which fetches and
|
|
1139
|
+
// parses; classic output `preload as="script"`; and `"prefetch"` opts into
|
|
1140
|
+
// `<link rel="prefetch">`, an idle-time fetch with no `as` and no
|
|
1141
|
+
// `integrity`, which the spec does not list. An async `import()` chunk is
|
|
1142
|
+
// not covered here: that is
|
|
1143
|
+
// `module.parser.javascript.dynamicImport*`, which routes through
|
|
1144
|
+
// webpack's on-demand chunk-load runtime.
|
|
1114
1145
|
const prefetchMode = resourceHints === "prefetch";
|
|
1115
1146
|
const preloadMode = resourceHints === true;
|
|
1116
1147
|
/** @type {"modulepreload" | "preload" | "prefetch"} */
|
|
@@ -1145,10 +1176,9 @@ HtmlEntryDependency.Template = class HtmlEntryDependencyTemplate extends (
|
|
|
1145
1176
|
"javascript"
|
|
1146
1177
|
)}"`
|
|
1147
1178
|
: "";
|
|
1148
|
-
// Mirror the entry tag's `nonce
|
|
1149
|
-
//
|
|
1150
|
-
//
|
|
1151
|
-
// fetching twice.
|
|
1179
|
+
// Mirror the entry tag's `nonce`, `crossorigin` and `referrerpolicy`,
|
|
1180
|
+
// so the request matches the sibling `<script>`'s and the browser
|
|
1181
|
+
// reuses it rather than fetching twice.
|
|
1152
1182
|
const attrs = `${dep.copyableAttrsText}${crossOrigin}${integrityAttr}`;
|
|
1153
1183
|
const tag = prefetchMode
|
|
1154
1184
|
? `<link rel="prefetch" href="${href}"${attrs}>`
|
|
@@ -1226,14 +1256,10 @@ HtmlEntryDependency.Template = class HtmlEntryDependencyTemplate extends (
|
|
|
1226
1256
|
}
|
|
1227
1257
|
|
|
1228
1258
|
// === assets channel — URL-referenced assets carrying `prefetch`/`preload` ===
|
|
1229
|
-
|
|
1230
|
-
//
|
|
1231
|
-
// consume that list
|
|
1232
|
-
//
|
|
1233
|
-
// the HTML `<head>`; the JS chunk-startup runtime skips it (no
|
|
1234
|
-
// double `<link>` in DOM). URLs are sentinels resolved from asset
|
|
1235
|
-
// codegen data during `HtmlModulesPlugin` render — the asset
|
|
1236
|
-
// module might not have been codegen'd yet at this point.
|
|
1259
|
+
|
|
1260
|
+
// The plugin already walked the entrypoint once and cached this entry's
|
|
1261
|
+
// asset deps, so consume that list rather than repeat it. URLs stay
|
|
1262
|
+
// sentinels here: the asset module may not be codegen'd yet.
|
|
1237
1263
|
const outputCrossOriginAttr = crossOriginLoading
|
|
1238
1264
|
? ` crossorigin="${crossOriginLoading}"`
|
|
1239
1265
|
: "";
|
|
@@ -1274,12 +1300,9 @@ HtmlEntryDependency.Template = class HtmlEntryDependencyTemplate extends (
|
|
|
1274
1300
|
finalHints.push(h);
|
|
1275
1301
|
}
|
|
1276
1302
|
}
|
|
1277
|
-
//
|
|
1278
|
-
//
|
|
1279
|
-
//
|
|
1280
|
-
// `resourceHints.modulePreloadPolyfill` defaults from the target's
|
|
1281
|
-
// modulepreload support (`output.environment.modulePreload`); `false`
|
|
1282
|
-
// opts out (strict CSP).
|
|
1303
|
+
// Without native `modulepreload` the hints warm no cache, so append the
|
|
1304
|
+
// polyfill once per page. It defaults from the target's support, and
|
|
1305
|
+
// `false` opts out, which a strict CSP needs.
|
|
1283
1306
|
if (
|
|
1284
1307
|
rhOptions &&
|
|
1285
1308
|
rhOptions.modulePreloadPolyfill &&
|
|
@@ -1289,10 +1312,9 @@ HtmlEntryDependency.Template = class HtmlEntryDependencyTemplate extends (
|
|
|
1289
1312
|
polyfilledSources.add(source);
|
|
1290
1313
|
finalHints.push(`<script>${MODULEPRELOAD_POLYFILL}</script>`);
|
|
1291
1314
|
}
|
|
1292
|
-
// Insert
|
|
1293
|
-
//
|
|
1294
|
-
// blocking script
|
|
1295
|
-
// written `<head>` (e.g. an HTML fragment).
|
|
1315
|
+
// Insert just after the `<head>` open tag, so the hints are the first
|
|
1316
|
+
// fetches. A page with no written `<head>` falls back to the first
|
|
1317
|
+
// blocking script, else the entry tag.
|
|
1296
1318
|
const hintAt =
|
|
1297
1319
|
dep.headOpenEnd >= 0
|
|
1298
1320
|
? dep.headOpenEnd
|
|
@@ -112,10 +112,9 @@ HtmlInlineScriptDependency.Template = class HtmlInlineScriptDependencyTemplate e
|
|
|
112
112
|
url = getHtmlGenerator().makeChunkUrlSentinel(chunk, "javascript");
|
|
113
113
|
}
|
|
114
114
|
|
|
115
|
-
// Insert ` src="…"`
|
|
116
|
-
//
|
|
117
|
-
//
|
|
118
|
-
// it below so the unprocessed JS doesn't ride along.
|
|
115
|
+
// Insert ` src="…"` just after `<script`, serving the body from the emitted
|
|
116
|
+
// chunk. The browser ignores an inline body beside `src`, but it is cleared
|
|
117
|
+
// below so the unprocessed JS does not ride along.
|
|
119
118
|
source.insert(dep.insertPos, ` src="${url}"`);
|
|
120
119
|
source.replace(dep.contentRange[0], dep.contentRange[1] - 1, "");
|
|
121
120
|
}
|
|
@@ -127,10 +127,9 @@ HtmlInlineStyleDependency.Template = class HtmlInlineStyleDependencyTemplate ext
|
|
|
127
127
|
}
|
|
128
128
|
}
|
|
129
129
|
|
|
130
|
-
// An attribute value was entity-decoded before parsing, so
|
|
131
|
-
//
|
|
132
|
-
//
|
|
133
|
-
// appends so the rewritten attribute stays on one line.
|
|
130
|
+
// An attribute value was entity-decoded before parsing, so the processed CSS
|
|
131
|
+
// is re-escaped to keep the markup valid in any quoting context, and the
|
|
132
|
+
// generator's trailing newline dropped to keep it on one line.
|
|
134
133
|
if (dep.inAttribute) {
|
|
135
134
|
cssText = cssText
|
|
136
135
|
.replace(TRAILING_WHITESPACE_REGEXP, "")
|
|
@@ -20,7 +20,7 @@ const ImportMetaContextDependency = require("./ImportMetaContextDependency");
|
|
|
20
20
|
* } from "estree"
|
|
21
21
|
*/
|
|
22
22
|
/** @import JavascriptParser, { Range } from "../javascript/JavascriptParser" */
|
|
23
|
-
/** @import { ContextModuleOptions, ContextMode } from "../ContextModule" */
|
|
23
|
+
/** @import { ContextModuleOptions, ContextMode } from "../context/ContextModule" */
|
|
24
24
|
/** @import { ChunkName } from "../Chunk" */
|
|
25
25
|
/** @import { RawChunkGroupOptions } from "../ChunkGroup" */
|
|
26
26
|
/** @import { RawReferencedExports, DependencyLocation } from "../Dependency" */
|
|
@@ -27,7 +27,7 @@ const getUnsupportedFeatureWarning = memoize(() =>
|
|
|
27
27
|
require("../errors/UnsupportedFeatureWarning")
|
|
28
28
|
);
|
|
29
29
|
|
|
30
|
-
/** @import { ContextModuleOptions } from "../ContextModule" */
|
|
30
|
+
/** @import { ContextModuleOptions } from "../context/ContextModule" */
|
|
31
31
|
/** @import JavascriptParser, { Range } from "../javascript/JavascriptParser" */
|
|
32
32
|
/** @import { RawReferencedExports, DependencyLocation } from "../Dependency" */
|
|
33
33
|
/**
|
|
@@ -0,0 +1,104 @@
|
|
|
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 makeSerializable = require("../util/makeSerializable");
|
|
9
|
+
const ConstDependency = require("./ConstDependency");
|
|
10
|
+
const NullDependency = require("./NullDependency");
|
|
11
|
+
|
|
12
|
+
/** @import { ReplaceSource } from "webpack-sources" */
|
|
13
|
+
/** @import Dependency, { UpdateHashContext } from "../Dependency" */
|
|
14
|
+
/** @import { DependencyTemplateContext } from "../DependencyTemplate" */
|
|
15
|
+
/** @import { Range } from "../javascript/JavascriptParser" */
|
|
16
|
+
/**
|
|
17
|
+
* @import {
|
|
18
|
+
* ObjectDeserializerContext,
|
|
19
|
+
* ObjectSerializerContext
|
|
20
|
+
* } from "../serialization/ObjectMiddleware"
|
|
21
|
+
*/
|
|
22
|
+
/** @import Hash from "../util/Hash" */
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* `import.meta.main` asks whether the module is the entry, which needs the
|
|
26
|
+
* module argument scope hoisting removes. An inner concatenated module is
|
|
27
|
+
* never an entry module, so it answers with a separate constant expression.
|
|
28
|
+
*/
|
|
29
|
+
class ImportMetaMainDependency extends ConstDependency {
|
|
30
|
+
/**
|
|
31
|
+
* Creates an instance of ImportMetaMainDependency.
|
|
32
|
+
* @param {string} expression the expression a module outside a concatenation evaluates
|
|
33
|
+
* @param {string} concatenatedExpression the expression an inner concatenated module evaluates
|
|
34
|
+
* @param {Range} range the source range
|
|
35
|
+
* @param {(string[] | null)=} runtimeRequirements runtime requirements of `expression`
|
|
36
|
+
*/
|
|
37
|
+
constructor(expression, concatenatedExpression, range, runtimeRequirements) {
|
|
38
|
+
super(expression, range, runtimeRequirements);
|
|
39
|
+
/** @type {string} */
|
|
40
|
+
this.concatenatedExpression = concatenatedExpression;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* Updates the hash with the data contributed by this instance.
|
|
45
|
+
* @param {Hash} hash hash to be updated
|
|
46
|
+
* @param {UpdateHashContext} context context
|
|
47
|
+
* @returns {void}
|
|
48
|
+
*/
|
|
49
|
+
updateHash(hash, context) {
|
|
50
|
+
super.updateHash(hash, context);
|
|
51
|
+
hash.update(this.concatenatedExpression);
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* Serializes this instance into the provided serializer context.
|
|
56
|
+
* @param {ObjectSerializerContext} context context
|
|
57
|
+
*/
|
|
58
|
+
serialize(context) {
|
|
59
|
+
context.write(this.concatenatedExpression);
|
|
60
|
+
super.serialize(context);
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
/**
|
|
64
|
+
* Restores this instance from the provided deserializer context.
|
|
65
|
+
* @param {ObjectDeserializerContext} context context
|
|
66
|
+
*/
|
|
67
|
+
deserialize(context) {
|
|
68
|
+
this.concatenatedExpression = context.read();
|
|
69
|
+
super.deserialize(context.rest);
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
makeSerializable(
|
|
74
|
+
ImportMetaMainDependency,
|
|
75
|
+
"webpack/lib/dependencies/ImportMetaMainDependency"
|
|
76
|
+
);
|
|
77
|
+
|
|
78
|
+
ImportMetaMainDependency.Template = class ImportMetaMainDependencyTemplate extends (
|
|
79
|
+
NullDependency.Template
|
|
80
|
+
) {
|
|
81
|
+
/**
|
|
82
|
+
* Applies the plugin by registering its hooks on the compiler.
|
|
83
|
+
* @param {Dependency} dependency the dependency for which the template should be applied
|
|
84
|
+
* @param {ReplaceSource} source the current replace source which can be modified
|
|
85
|
+
* @param {DependencyTemplateContext} templateContext the context object
|
|
86
|
+
* @returns {void}
|
|
87
|
+
*/
|
|
88
|
+
apply(dependency, source, templateContext) {
|
|
89
|
+
const dep = /** @type {ImportMetaMainDependency} */ (dependency);
|
|
90
|
+
const concatenated = templateContext.concatenationScope !== undefined;
|
|
91
|
+
if (!concatenated && dep.runtimeRequirements) {
|
|
92
|
+
for (const req of dep.runtimeRequirements) {
|
|
93
|
+
templateContext.runtimeRequirements.add(req);
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
const expression = concatenated
|
|
97
|
+
? dep.concatenatedExpression
|
|
98
|
+
: dep.expression;
|
|
99
|
+
const range = /** @type {Range} */ (dep.range);
|
|
100
|
+
source.replace(range[0], range[1] - 1, expression);
|
|
101
|
+
}
|
|
102
|
+
};
|
|
103
|
+
|
|
104
|
+
module.exports = ImportMetaMainDependency;
|