webpack 5.101.3 → 5.102.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 +21 -26
- package/lib/APIPlugin.js +30 -36
- package/lib/AsyncDependenciesBlock.js +1 -4
- package/lib/BannerPlugin.js +0 -1
- package/lib/Cache.js +7 -6
- package/lib/CacheFacade.js +0 -1
- package/lib/Chunk.js +49 -31
- package/lib/ChunkGraph.js +35 -25
- package/lib/ChunkGroup.js +8 -10
- package/lib/ChunkTemplate.js +1 -1
- package/lib/CleanPlugin.js +3 -3
- package/lib/CodeGenerationResults.js +2 -1
- package/lib/CompatibilityPlugin.js +29 -12
- package/lib/Compilation.js +204 -185
- package/lib/Compiler.js +36 -35
- package/lib/ConcatenationScope.js +6 -1
- package/lib/ConditionalInitFragment.js +1 -1
- package/lib/ConstPlugin.js +6 -5
- package/lib/ContextExclusionPlugin.js +0 -1
- package/lib/ContextModule.js +22 -20
- package/lib/ContextModuleFactory.js +30 -11
- package/lib/ContextReplacementPlugin.js +38 -15
- package/lib/DefinePlugin.js +4 -8
- package/lib/DelegatedModule.js +7 -11
- package/lib/DependenciesBlock.js +0 -2
- package/lib/Dependency.js +9 -11
- package/lib/DependencyTemplates.js +1 -3
- package/lib/DllModule.js +1 -7
- package/lib/DllReferencePlugin.js +2 -4
- package/lib/DynamicEntryPlugin.js +0 -2
- package/lib/EntryOptionPlugin.js +0 -5
- package/lib/EnvironmentNotSupportAsyncWarning.js +0 -3
- package/lib/EvalDevToolModulePlugin.js +4 -3
- package/lib/EvalSourceMapDevToolPlugin.js +3 -4
- package/lib/ExportsInfo.js +50 -49
- package/lib/ExternalModule.js +84 -52
- package/lib/ExternalModuleFactoryPlugin.js +27 -7
- package/lib/ExternalsPlugin.js +24 -17
- package/lib/FileSystemInfo.js +96 -78
- package/lib/FlagDependencyUsagePlugin.js +3 -4
- package/lib/Generator.js +2 -13
- package/lib/GraphHelpers.js +0 -3
- package/lib/HookWebpackError.js +0 -2
- package/lib/HotModuleReplacementPlugin.js +22 -24
- package/lib/HotUpdateChunk.js +0 -3
- package/lib/IgnorePlugin.js +5 -2
- package/lib/InitFragment.js +41 -29
- package/lib/InvalidDependenciesModuleWarning.js +0 -1
- package/lib/LibManifestPlugin.js +4 -6
- package/lib/LoaderOptionsPlugin.js +1 -10
- package/lib/MainTemplate.js +8 -19
- package/lib/Module.js +32 -20
- package/lib/ModuleFactory.js +1 -1
- package/lib/ModuleFilenameHelpers.js +41 -24
- package/lib/ModuleGraph.js +30 -16
- package/lib/ModuleInfoHeaderPlugin.js +0 -1
- package/lib/ModuleTemplate.js +0 -2
- package/lib/ModuleTypeConstants.js +11 -1
- package/lib/MultiCompiler.js +23 -15
- package/lib/MultiWatching.js +6 -10
- package/lib/NodeStuffPlugin.js +2 -10
- package/lib/NormalModule.js +145 -88
- package/lib/NormalModuleFactory.js +59 -40
- package/lib/OptionsApply.js +1 -1
- package/lib/Parser.js +1 -1
- package/lib/ProgressPlugin.js +6 -10
- package/lib/ProvidePlugin.js +5 -7
- package/lib/RawModule.js +1 -6
- package/lib/RecordIdsPlugin.js +10 -6
- package/lib/ResolverFactory.js +0 -2
- package/lib/RuntimeGlobals.js +5 -0
- package/lib/RuntimeModule.js +1 -3
- package/lib/RuntimePlugin.js +26 -22
- package/lib/RuntimeTemplate.js +12 -11
- package/lib/SourceMapDevToolModuleOptionsPlugin.js +2 -2
- package/lib/SourceMapDevToolPlugin.js +6 -11
- package/lib/Stats.js +0 -1
- package/lib/Template.js +6 -11
- package/lib/TemplatedPathPlugin.js +2 -1
- package/lib/WatchIgnorePlugin.js +2 -3
- package/lib/Watching.js +15 -15
- package/lib/WebpackIsIncludedPlugin.js +0 -2
- package/lib/WebpackOptionsApply.js +74 -107
- package/lib/asset/AssetBytesGenerator.js +166 -0
- package/lib/asset/AssetBytesParser.js +37 -0
- package/lib/asset/AssetGenerator.js +20 -34
- package/lib/asset/AssetModulesPlugin.js +34 -16
- package/lib/asset/AssetParser.js +7 -3
- package/lib/asset/AssetSourceGenerator.js +1 -1
- package/lib/asset/RawDataUrlModule.js +3 -2
- package/lib/async-modules/AsyncModuleHelpers.js +6 -4
- package/lib/buildChunkGraph.js +0 -1
- package/lib/cache/MemoryCachePlugin.js +0 -2
- package/lib/cache/MemoryWithGcCachePlugin.js +0 -2
- package/lib/cache/PackFileCacheStrategy.js +14 -1
- package/lib/cache/ResolverCachePlugin.js +9 -15
- package/lib/config/defaults.js +155 -21
- package/lib/config/normalization.js +18 -3
- package/lib/container/ContainerEntryDependency.js +0 -1
- package/lib/container/ContainerEntryModule.js +3 -7
- package/lib/container/ContainerPlugin.js +1 -2
- package/lib/container/ContainerReferencePlugin.js +0 -1
- package/lib/container/FallbackDependency.js +2 -1
- package/lib/container/FallbackModule.js +6 -7
- package/lib/container/ModuleFederationPlugin.js +0 -1
- package/lib/container/RemoteModule.js +8 -8
- package/lib/container/RemoteRuntimeModule.js +2 -2
- package/lib/css/CssGenerator.js +3 -6
- package/lib/css/CssLoadingRuntimeModule.js +6 -9
- package/lib/css/CssModulesPlugin.js +11 -13
- package/lib/css/CssParser.js +3 -3
- package/lib/css/walkCssTokens.js +1 -1
- package/lib/debug/ProfilingPlugin.js +35 -8
- package/lib/dependencies/AMDDefineDependencyParserPlugin.js +12 -17
- package/lib/dependencies/AMDPlugin.js +2 -2
- package/lib/dependencies/AMDRequireDependenciesBlockParserPlugin.js +1 -2
- package/lib/dependencies/CachedConstDependency.js +0 -4
- package/lib/dependencies/CommonJsExportRequireDependency.js +20 -14
- package/lib/dependencies/CommonJsExportsDependency.js +2 -1
- package/lib/dependencies/CommonJsExportsParserPlugin.js +20 -5
- package/lib/dependencies/CommonJsFullRequireDependency.js +6 -4
- package/lib/dependencies/CommonJsImportsParserPlugin.js +16 -7
- package/lib/dependencies/CommonJsRequireContextDependency.js +1 -1
- package/lib/dependencies/CommonJsSelfReferenceDependency.js +4 -4
- package/lib/dependencies/ConstDependency.js +2 -2
- package/lib/dependencies/ContextDependency.js +9 -4
- package/lib/dependencies/ContextDependencyHelpers.js +2 -2
- package/lib/dependencies/ContextDependencyTemplateAsId.js +9 -9
- package/lib/dependencies/ContextDependencyTemplateAsRequireCall.js +9 -9
- package/lib/dependencies/ContextElementDependency.js +22 -11
- package/lib/dependencies/CssIcssImportDependency.js +0 -2
- package/lib/dependencies/CssIcssSymbolDependency.js +2 -2
- package/lib/dependencies/CssImportDependency.js +0 -8
- package/lib/dependencies/CssLocalIdentifierDependency.js +3 -4
- package/lib/dependencies/CssSelfLocalIdentifierDependency.js +2 -2
- package/lib/dependencies/CssUrlDependency.js +0 -6
- package/lib/dependencies/ExportsInfoDependency.js +7 -9
- package/lib/dependencies/ExternalModuleDependency.js +0 -3
- package/lib/dependencies/ExternalModuleInitFragment.js +1 -1
- package/lib/dependencies/HarmonyAcceptDependency.js +1 -1
- package/lib/dependencies/HarmonyAcceptImportDependency.js +0 -4
- package/lib/dependencies/HarmonyCompatibilityDependency.js +0 -1
- package/lib/dependencies/HarmonyDetectionParserPlugin.js +0 -14
- package/lib/dependencies/HarmonyEvaluatedImportSpecifierDependency.js +3 -3
- package/lib/dependencies/HarmonyExportDependencyParserPlugin.js +4 -1
- package/lib/dependencies/HarmonyExportImportedSpecifierDependency.js +29 -35
- package/lib/dependencies/HarmonyImportDependency.js +30 -14
- package/lib/dependencies/HarmonyImportDependencyParserPlugin.js +20 -23
- package/lib/dependencies/HarmonyImportSideEffectDependency.js +0 -4
- package/lib/dependencies/HarmonyImportSpecifierDependency.js +46 -31
- package/lib/dependencies/HarmonyModulesPlugin.js +3 -3
- package/lib/dependencies/ImportDependency.js +18 -6
- package/lib/dependencies/ImportEagerDependency.js +2 -3
- package/lib/dependencies/ImportMetaContextDependencyParserPlugin.js +8 -5
- package/lib/dependencies/ImportMetaContextPlugin.js +0 -1
- package/lib/dependencies/ImportMetaPlugin.js +2 -1
- package/lib/dependencies/ImportParserPlugin.js +288 -45
- package/lib/dependencies/ImportWeakDependency.js +2 -3
- package/lib/dependencies/JsonExportsDependency.js +0 -1
- package/lib/dependencies/LoaderDependency.js +0 -3
- package/lib/dependencies/LoaderImportDependency.js +0 -3
- package/lib/dependencies/LoaderPlugin.js +11 -5
- package/lib/dependencies/ModuleDecoratorDependency.js +2 -4
- package/lib/dependencies/ModuleDependency.js +3 -9
- package/lib/dependencies/NullDependency.js +2 -0
- package/lib/dependencies/ProvidedDependency.js +6 -8
- package/lib/dependencies/PureExpressionDependency.js +0 -1
- package/lib/dependencies/RequireEnsureDependenciesBlock.js +0 -1
- package/lib/dependencies/RequireEnsureDependenciesBlockParserPlugin.js +1 -2
- package/lib/dependencies/RequireIncludeDependency.js +2 -2
- package/lib/dependencies/RequireResolveDependency.js +2 -2
- package/lib/dependencies/RuntimeRequirementsDependency.js +2 -3
- package/lib/dependencies/StaticExportsDependency.js +3 -5
- package/lib/dependencies/URLDependency.js +2 -7
- package/lib/dependencies/URLPlugin.js +1 -2
- package/lib/dependencies/WebAssemblyExportImportedDependency.js +2 -2
- package/lib/dependencies/WebAssemblyImportDependency.js +2 -2
- package/lib/dependencies/WebpackIsIncludedDependency.js +2 -3
- package/lib/dependencies/WorkerDependency.js +2 -3
- package/lib/dependencies/WorkerPlugin.js +3 -9
- package/lib/dependencies/processExportInfo.js +2 -3
- package/lib/esm/ModuleChunkFormatPlugin.js +0 -3
- package/lib/esm/ModuleChunkLoadingPlugin.js +2 -1
- package/lib/esm/ModuleChunkLoadingRuntimeModule.js +7 -7
- package/lib/hmr/LazyCompilationPlugin.js +6 -4
- package/lib/hmr/lazyCompilationBackend.js +13 -10
- package/lib/ids/DeterministicChunkIdsPlugin.js +0 -1
- package/lib/ids/NamedChunkIdsPlugin.js +1 -6
- package/lib/ids/NamedModuleIdsPlugin.js +1 -5
- package/lib/ids/NaturalChunkIdsPlugin.js +0 -1
- package/lib/ids/NaturalModuleIdsPlugin.js +0 -1
- package/lib/ids/OccurrenceChunkIdsPlugin.js +0 -1
- package/lib/ids/OccurrenceModuleIdsPlugin.js +0 -1
- package/lib/ids/SyncModuleIdsPlugin.js +4 -3
- package/lib/index.js +8 -7
- package/lib/javascript/ArrayPushCallbackChunkFormatPlugin.js +4 -1
- package/lib/javascript/BasicEvaluatedExpression.js +13 -6
- package/lib/javascript/ChunkFormatHelpers.js +1 -1
- package/lib/javascript/CommonJsChunkFormatPlugin.js +0 -1
- package/lib/javascript/JavascriptGenerator.js +2 -3
- package/lib/javascript/JavascriptModulesPlugin.js +44 -21
- package/lib/javascript/JavascriptParser.js +119 -54
- package/lib/javascript/JavascriptParserHelpers.js +2 -2
- package/lib/javascript/StartupHelpers.js +2 -4
- package/lib/json/JsonData.js +1 -1
- package/lib/json/JsonGenerator.js +4 -5
- package/lib/json/JsonModulesPlugin.js +0 -3
- package/lib/json/JsonParser.js +4 -2
- package/lib/library/AbstractLibraryPlugin.js +2 -2
- package/lib/library/AmdLibraryPlugin.js +0 -1
- package/lib/library/AssignLibraryPlugin.js +23 -12
- package/lib/library/EnableLibraryPlugin.js +7 -11
- package/lib/library/ExportPropertyLibraryPlugin.js +8 -20
- package/lib/library/JsonpLibraryPlugin.js +5 -2
- package/lib/library/ModuleLibraryPlugin.js +88 -43
- package/lib/library/SystemLibraryPlugin.js +0 -1
- package/lib/library/UmdLibraryPlugin.js +12 -18
- package/lib/logging/Logger.js +12 -10
- package/lib/logging/createConsoleLogger.js +15 -14
- package/lib/logging/truncateArgs.js +1 -1
- package/lib/node/CommonJsChunkLoadingPlugin.js +2 -1
- package/lib/node/NodeWatchFileSystem.js +4 -4
- package/lib/node/ReadFileChunkLoadingRuntimeModule.js +2 -2
- package/lib/node/RequireChunkLoadingRuntimeModule.js +5 -2
- package/lib/node/nodeConsole.js +2 -2
- package/lib/optimize/AggressiveSplittingPlugin.js +2 -0
- package/lib/optimize/ConcatenatedModule.js +142 -100
- package/lib/optimize/InnerGraph.js +17 -11
- package/lib/optimize/InnerGraphPlugin.js +0 -3
- package/lib/optimize/ModuleConcatenationPlugin.js +3 -4
- package/lib/optimize/RuntimeChunkPlugin.js +0 -1
- package/lib/optimize/SideEffectsFlagPlugin.js +3 -10
- package/lib/optimize/SplitChunksPlugin.js +46 -40
- package/lib/performance/SizeLimitsPlugin.js +2 -1
- package/lib/prefetch/ChunkPrefetchFunctionRuntimeModule.js +5 -7
- package/lib/prefetch/ChunkPrefetchPreloadPlugin.js +0 -2
- package/lib/prefetch/ChunkPrefetchStartupRuntimeModule.js +0 -1
- package/lib/prefetch/ChunkPrefetchTriggerRuntimeModule.js +2 -2
- package/lib/prefetch/ChunkPreloadTriggerRuntimeModule.js +2 -2
- package/lib/rules/BasicMatcherRulePlugin.js +0 -2
- package/lib/rules/ObjectMatcherRulePlugin.js +0 -1
- package/lib/rules/RuleSetCompiler.js +8 -6
- package/lib/runtime/BaseUriRuntimeModule.js +2 -2
- package/lib/runtime/CompatRuntimeModule.js +0 -1
- package/lib/runtime/GetChunkFilenameRuntimeModule.js +8 -9
- package/lib/runtime/LoadScriptRuntimeModule.js +0 -2
- package/lib/runtime/MakeDeferredNamespaceObjectRuntime.js +1 -1
- package/lib/runtime/PublicPathRuntimeModule.js +2 -2
- package/lib/runtime/StartupEntrypointRuntimeModule.js +0 -1
- package/lib/runtime/SystemContextRuntimeModule.js +0 -2
- package/lib/runtime/ToBinaryRuntimeModule.js +64 -0
- package/lib/schemes/DataUriPlugin.js +2 -28
- package/lib/schemes/FileUriPlugin.js +5 -2
- package/lib/schemes/HttpUriPlugin.js +4 -2
- package/lib/schemes/VirtualUrlPlugin.js +11 -11
- package/lib/serialization/NullPrototypeObjectSerializer.js +5 -3
- package/lib/serialization/ObjectMiddleware.js +30 -19
- package/lib/serialization/SerializerMiddleware.js +1 -3
- package/lib/serialization/types.js +1 -1
- package/lib/sharing/ConsumeSharedModule.js +3 -5
- package/lib/sharing/ConsumeSharedPlugin.js +2 -4
- package/lib/sharing/ConsumeSharedRuntimeModule.js +9 -6
- package/lib/sharing/ProvideSharedModule.js +3 -7
- package/lib/sharing/SharePlugin.js +0 -2
- package/lib/sharing/ShareRuntimeModule.js +4 -1
- package/lib/sharing/resolveMatchedConfigs.js +14 -6
- package/lib/sharing/utils.js +0 -6
- package/lib/stats/DefaultStatsFactoryPlugin.js +178 -94
- package/lib/stats/DefaultStatsPresetPlugin.js +15 -9
- package/lib/stats/DefaultStatsPrinterPlugin.js +77 -113
- package/lib/stats/StatsFactory.js +14 -11
- package/lib/url/URLParserPlugin.js +2 -4
- package/lib/util/ArrayHelpers.js +4 -4
- package/lib/util/AsyncQueue.js +1 -0
- package/lib/util/LazySet.js +2 -2
- package/lib/util/StackedCacheMap.js +0 -2
- package/lib/util/TupleSet.js +9 -4
- package/lib/util/URLAbsoluteSpecifier.js +0 -1
- package/lib/util/WeakTupleMap.js +1 -1
- package/lib/util/chainedImports.js +3 -1
- package/lib/util/cleverMerge.js +15 -18
- package/lib/util/comparators.js +2 -4
- package/lib/util/compileBooleanMatcher.js +11 -9
- package/lib/util/concatenate.js +1 -2
- package/lib/util/create-schema-validation.js +0 -1
- package/lib/util/dataURL.js +39 -0
- package/lib/util/deprecation.js +29 -31
- package/lib/util/deterministicGrouping.js +34 -30
- package/lib/util/extractSourceMap.js +319 -0
- package/lib/util/findGraphRoots.js +15 -5
- package/lib/util/fs.js +29 -8
- package/lib/util/semver.js +9 -8
- package/lib/util/smartGrouping.js +41 -26
- package/lib/util/traverseDestructuringAssignmentProperties.js +45 -0
- package/lib/wasm/EnableWasmLoadingPlugin.js +3 -2
- package/lib/wasm-async/AsyncWasmLoadingRuntimeModule.js +5 -1
- package/lib/wasm-async/AsyncWebAssemblyJavascriptGenerator.js +2 -13
- package/lib/wasm-async/AsyncWebAssemblyModulesPlugin.js +2 -9
- package/lib/wasm-async/AsyncWebAssemblyParser.js +2 -1
- package/lib/wasm-sync/WasmChunkLoadingRuntimeModule.js +6 -4
- package/lib/wasm-sync/WebAssemblyGenerator.js +1 -3
- package/lib/wasm-sync/WebAssemblyJavascriptGenerator.js +1 -4
- package/lib/wasm-sync/WebAssemblyModulesPlugin.js +2 -7
- package/lib/wasm-sync/WebAssemblyParser.js +1 -4
- package/lib/web/JsonpChunkLoadingPlugin.js +2 -1
- package/lib/web/JsonpChunkLoadingRuntimeModule.js +1 -1
- package/lib/web/JsonpTemplatePlugin.js +0 -1
- package/lib/webpack.js +21 -8
- package/lib/webworker/ImportScriptsChunkLoadingPlugin.js +2 -1
- package/lib/webworker/ImportScriptsChunkLoadingRuntimeModule.js +1 -1
- package/package.json +12 -12
- package/schemas/WebpackOptions.check.js +1 -1
- package/schemas/WebpackOptions.json +77 -93
- package/schemas/plugins/BannerPlugin.check.js +1 -1
- package/schemas/plugins/BannerPlugin.json +4 -0
- package/schemas/plugins/IgnorePlugin.json +1 -1
- package/schemas/plugins/ProgressPlugin.json +1 -1
- package/schemas/plugins/SourceMapDevToolPlugin.check.js +1 -1
- package/schemas/plugins/SourceMapDevToolPlugin.json +5 -1
- package/schemas/plugins/schemes/VirtualUrlPlugin.json +3 -3
- package/types.d.ts +1129 -530
- package/SECURITY.md +0 -9
|
@@ -0,0 +1,166 @@
|
|
|
1
|
+
/*
|
|
2
|
+
MIT License http://www.opensource.org/licenses/mit-license.php
|
|
3
|
+
Author Alexander Akait @alexander-akait
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
"use strict";
|
|
7
|
+
|
|
8
|
+
const { RawSource } = require("webpack-sources");
|
|
9
|
+
const ConcatenationScope = require("../ConcatenationScope");
|
|
10
|
+
const Generator = require("../Generator");
|
|
11
|
+
const {
|
|
12
|
+
CSS_URL_TYPES,
|
|
13
|
+
JS_AND_CSS_URL_TYPES,
|
|
14
|
+
JS_TYPES,
|
|
15
|
+
NO_TYPES
|
|
16
|
+
} = require("../ModuleSourceTypesConstants");
|
|
17
|
+
const RuntimeGlobals = require("../RuntimeGlobals");
|
|
18
|
+
|
|
19
|
+
/** @typedef {import("webpack-sources").Source} Source */
|
|
20
|
+
/** @typedef {import("../Generator").GenerateContext} GenerateContext */
|
|
21
|
+
/** @typedef {import("../Module").ConcatenationBailoutReasonContext} ConcatenationBailoutReasonContext */
|
|
22
|
+
/** @typedef {import("../Module").SourceTypes} SourceTypes */
|
|
23
|
+
/** @typedef {import("../ModuleGraph")} ModuleGraph */
|
|
24
|
+
/** @typedef {import("../NormalModule")} NormalModule */
|
|
25
|
+
|
|
26
|
+
class AssetSourceGenerator extends Generator {
|
|
27
|
+
/**
|
|
28
|
+
* @param {ModuleGraph} moduleGraph the module graph
|
|
29
|
+
*/
|
|
30
|
+
constructor(moduleGraph) {
|
|
31
|
+
super();
|
|
32
|
+
|
|
33
|
+
this._moduleGraph = moduleGraph;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* @param {NormalModule} module module for which the code should be generated
|
|
38
|
+
* @param {GenerateContext} generateContext context for generate
|
|
39
|
+
* @returns {Source | null} generated code
|
|
40
|
+
*/
|
|
41
|
+
generate(
|
|
42
|
+
module,
|
|
43
|
+
{ type, concatenationScope, getData, runtimeTemplate, runtimeRequirements }
|
|
44
|
+
) {
|
|
45
|
+
const originalSource = module.originalSource();
|
|
46
|
+
const data = getData ? getData() : undefined;
|
|
47
|
+
|
|
48
|
+
switch (type) {
|
|
49
|
+
case "javascript": {
|
|
50
|
+
if (!originalSource) {
|
|
51
|
+
return new RawSource("");
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
const encodedSource = originalSource.buffer().toString("base64");
|
|
55
|
+
|
|
56
|
+
runtimeRequirements.add(RuntimeGlobals.toBinary);
|
|
57
|
+
|
|
58
|
+
let sourceContent;
|
|
59
|
+
if (concatenationScope) {
|
|
60
|
+
concatenationScope.registerNamespaceExport(
|
|
61
|
+
ConcatenationScope.NAMESPACE_OBJECT_EXPORT
|
|
62
|
+
);
|
|
63
|
+
sourceContent = `${runtimeTemplate.renderConst()} ${
|
|
64
|
+
ConcatenationScope.NAMESPACE_OBJECT_EXPORT
|
|
65
|
+
} = ${RuntimeGlobals.toBinary}(${JSON.stringify(encodedSource)});`;
|
|
66
|
+
} else {
|
|
67
|
+
runtimeRequirements.add(RuntimeGlobals.module);
|
|
68
|
+
sourceContent = `${RuntimeGlobals.module}.exports = ${RuntimeGlobals.toBinary}(${JSON.stringify(
|
|
69
|
+
encodedSource
|
|
70
|
+
)});`;
|
|
71
|
+
}
|
|
72
|
+
return new RawSource(sourceContent);
|
|
73
|
+
}
|
|
74
|
+
case "css-url": {
|
|
75
|
+
if (!originalSource) {
|
|
76
|
+
return null;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
const encodedSource = originalSource.buffer().toString("base64");
|
|
80
|
+
|
|
81
|
+
if (data) {
|
|
82
|
+
data.set("url", {
|
|
83
|
+
[type]: `data:application/octet-stream;base64,${encodedSource}`
|
|
84
|
+
});
|
|
85
|
+
}
|
|
86
|
+
return null;
|
|
87
|
+
}
|
|
88
|
+
default:
|
|
89
|
+
return null;
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
/**
|
|
94
|
+
* @param {Error} error the error
|
|
95
|
+
* @param {NormalModule} module module for which the code should be generated
|
|
96
|
+
* @param {GenerateContext} generateContext context for generate
|
|
97
|
+
* @returns {Source | null} generated code
|
|
98
|
+
*/
|
|
99
|
+
generateError(error, module, generateContext) {
|
|
100
|
+
switch (generateContext.type) {
|
|
101
|
+
case "javascript": {
|
|
102
|
+
return new RawSource(
|
|
103
|
+
`throw new Error(${JSON.stringify(error.message)});`
|
|
104
|
+
);
|
|
105
|
+
}
|
|
106
|
+
default:
|
|
107
|
+
return null;
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
/**
|
|
112
|
+
* @param {NormalModule} module module for which the bailout reason should be determined
|
|
113
|
+
* @param {ConcatenationBailoutReasonContext} context context
|
|
114
|
+
* @returns {string | undefined} reason why this module can't be concatenated, undefined when it can be concatenated
|
|
115
|
+
*/
|
|
116
|
+
getConcatenationBailoutReason(module, context) {
|
|
117
|
+
return undefined;
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
/**
|
|
121
|
+
* @param {NormalModule} module fresh module
|
|
122
|
+
* @returns {SourceTypes} available types (do not mutate)
|
|
123
|
+
*/
|
|
124
|
+
getTypes(module) {
|
|
125
|
+
/** @type {Set<string>} */
|
|
126
|
+
const sourceTypes = new Set();
|
|
127
|
+
const connections = this._moduleGraph.getIncomingConnections(module);
|
|
128
|
+
|
|
129
|
+
for (const connection of connections) {
|
|
130
|
+
if (!connection.originModule) {
|
|
131
|
+
continue;
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
sourceTypes.add(connection.originModule.type.split("/")[0]);
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
if (sourceTypes.size > 0) {
|
|
138
|
+
if (sourceTypes.has("javascript") && sourceTypes.has("css")) {
|
|
139
|
+
return JS_AND_CSS_URL_TYPES;
|
|
140
|
+
} else if (sourceTypes.has("css")) {
|
|
141
|
+
return CSS_URL_TYPES;
|
|
142
|
+
}
|
|
143
|
+
return JS_TYPES;
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
return NO_TYPES;
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
/**
|
|
150
|
+
* @param {NormalModule} module the module
|
|
151
|
+
* @param {string=} type source type
|
|
152
|
+
* @returns {number} estimate size of the module
|
|
153
|
+
*/
|
|
154
|
+
getSize(module, type) {
|
|
155
|
+
const originalSource = module.originalSource();
|
|
156
|
+
|
|
157
|
+
if (!originalSource) {
|
|
158
|
+
return 0;
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
// Example: m.exports="abcd"
|
|
162
|
+
return originalSource.size() + 12;
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
module.exports = AssetSourceGenerator;
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
/*
|
|
2
|
+
MIT License http://www.opensource.org/licenses/mit-license.php
|
|
3
|
+
Author Alexander Akait @alexander-akait
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
"use strict";
|
|
7
|
+
|
|
8
|
+
const Parser = require("../Parser");
|
|
9
|
+
|
|
10
|
+
/** @typedef {import("../Module").BuildInfo} BuildInfo */
|
|
11
|
+
/** @typedef {import("../Module").BuildMeta} BuildMeta */
|
|
12
|
+
/** @typedef {import("../Parser").ParserState} ParserState */
|
|
13
|
+
/** @typedef {import("../Parser").PreparsedAst} PreparsedAst */
|
|
14
|
+
|
|
15
|
+
class AssetBytesParser extends Parser {
|
|
16
|
+
/**
|
|
17
|
+
* @param {string | Buffer | PreparsedAst} source the source to parse
|
|
18
|
+
* @param {ParserState} state the parser state
|
|
19
|
+
* @returns {ParserState} the parser state
|
|
20
|
+
*/
|
|
21
|
+
parse(source, state) {
|
|
22
|
+
if (typeof source === "object" && !Buffer.isBuffer(source)) {
|
|
23
|
+
throw new Error("AssetBytesParser doesn't accept preparsed AST");
|
|
24
|
+
}
|
|
25
|
+
const { module } = state;
|
|
26
|
+
/** @type {BuildInfo} */
|
|
27
|
+
(module.buildInfo).strict = true;
|
|
28
|
+
/** @type {BuildMeta} */
|
|
29
|
+
(module.buildMeta).exportsType = "default";
|
|
30
|
+
/** @type {BuildMeta} */
|
|
31
|
+
(state.module.buildMeta).defaultObject = false;
|
|
32
|
+
|
|
33
|
+
return state;
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
module.exports = AssetBytesParser;
|
|
@@ -6,7 +6,6 @@
|
|
|
6
6
|
"use strict";
|
|
7
7
|
|
|
8
8
|
const path = require("path");
|
|
9
|
-
const mimeTypes = require("mime-types");
|
|
10
9
|
const { RawSource } = require("webpack-sources");
|
|
11
10
|
const ConcatenationScope = require("../ConcatenationScope");
|
|
12
11
|
const Generator = require("../Generator");
|
|
@@ -25,41 +24,38 @@ const RuntimeGlobals = require("../RuntimeGlobals");
|
|
|
25
24
|
const CssUrlDependency = require("../dependencies/CssUrlDependency");
|
|
26
25
|
const createHash = require("../util/createHash");
|
|
27
26
|
const { makePathsRelative } = require("../util/identifier");
|
|
27
|
+
const memoize = require("../util/memoize");
|
|
28
28
|
const nonNumericOnlyHash = require("../util/nonNumericOnlyHash");
|
|
29
29
|
|
|
30
|
+
const getMimeTypes = memoize(() => require("mime-types"));
|
|
31
|
+
|
|
30
32
|
/** @typedef {import("webpack-sources").Source} Source */
|
|
31
33
|
/** @typedef {import("../../declarations/WebpackOptions").AssetGeneratorDataUrlOptions} AssetGeneratorDataUrlOptions */
|
|
32
34
|
/** @typedef {import("../../declarations/WebpackOptions").AssetGeneratorOptions} AssetGeneratorOptions */
|
|
33
35
|
/** @typedef {import("../../declarations/WebpackOptions").AssetModuleFilename} AssetModuleFilename */
|
|
34
36
|
/** @typedef {import("../../declarations/WebpackOptions").AssetModuleOutputPath} AssetModuleOutputPath */
|
|
35
37
|
/** @typedef {import("../../declarations/WebpackOptions").AssetResourceGeneratorOptions} AssetResourceGeneratorOptions */
|
|
36
|
-
/** @typedef {import("../../declarations/WebpackOptions").HashFunction} HashFunction */
|
|
37
38
|
/** @typedef {import("../../declarations/WebpackOptions").RawPublicPath} RawPublicPath */
|
|
38
39
|
/** @typedef {import("../ChunkGraph")} ChunkGraph */
|
|
39
|
-
/** @typedef {import("../Compilation")} Compilation */
|
|
40
40
|
/** @typedef {import("../Compilation").AssetInfo} AssetInfo */
|
|
41
|
-
/** @typedef {import("../Compilation").InterpolatedPathAndAssetInfo} InterpolatedPathAndAssetInfo */
|
|
42
|
-
/** @typedef {import("../Compiler")} Compiler */
|
|
43
41
|
/** @typedef {import("../Generator").GenerateContext} GenerateContext */
|
|
44
42
|
/** @typedef {import("../Generator").UpdateHashContext} UpdateHashContext */
|
|
45
|
-
/** @typedef {import("../Module")}
|
|
43
|
+
/** @typedef {import("../Module").NameForCondition} NameForCondition */
|
|
46
44
|
/** @typedef {import("../Module").BuildInfo} BuildInfo */
|
|
47
|
-
/** @typedef {import("../Module").BuildMeta} BuildMeta */
|
|
48
45
|
/** @typedef {import("../Module").ConcatenationBailoutReasonContext} ConcatenationBailoutReasonContext */
|
|
49
46
|
/** @typedef {import("../Module").SourceTypes} SourceTypes */
|
|
50
47
|
/** @typedef {import("../ModuleGraph")} ModuleGraph */
|
|
51
48
|
/** @typedef {import("../NormalModule")} NormalModule */
|
|
52
49
|
/** @typedef {import("../RuntimeTemplate")} RuntimeTemplate */
|
|
53
|
-
/** @typedef {import("../TemplatedPathPlugin").TemplatePath} TemplatePath */
|
|
54
50
|
/** @typedef {import("../util/Hash")} Hash */
|
|
55
51
|
/** @typedef {import("../util/runtime").RuntimeSpec} RuntimeSpec */
|
|
56
52
|
|
|
57
53
|
/**
|
|
58
54
|
* @template T
|
|
59
55
|
* @template U
|
|
60
|
-
* @param {null | string |
|
|
61
|
-
* @param {null | string |
|
|
62
|
-
* @returns {
|
|
56
|
+
* @param {null | string | T[] | Set<T> | undefined} a a
|
|
57
|
+
* @param {null | string | U[] | Set<U> | undefined} b b
|
|
58
|
+
* @returns {T[] & U[]} array
|
|
63
59
|
*/
|
|
64
60
|
const mergeMaybeArrays = (a, b) => {
|
|
65
61
|
const set = new Set();
|
|
@@ -220,7 +216,8 @@ class AssetGenerator extends Generator {
|
|
|
220
216
|
static getSourceFileName(module, runtimeTemplate) {
|
|
221
217
|
return makePathsRelative(
|
|
222
218
|
runtimeTemplate.compilation.compiler.context,
|
|
223
|
-
|
|
219
|
+
/** @type {string} */
|
|
220
|
+
(module.getResource()),
|
|
224
221
|
runtimeTemplate.compilation.compiler.root
|
|
225
222
|
).replace(/^\.\//, "");
|
|
226
223
|
}
|
|
@@ -231,10 +228,7 @@ class AssetGenerator extends Generator {
|
|
|
231
228
|
* @returns {[string, string]} return full hash and non-numeric full hash
|
|
232
229
|
*/
|
|
233
230
|
static getFullContentHash(module, runtimeTemplate) {
|
|
234
|
-
const hash = createHash(
|
|
235
|
-
/** @type {HashFunction} */
|
|
236
|
-
(runtimeTemplate.outputOptions.hashFunction)
|
|
237
|
-
);
|
|
231
|
+
const hash = createHash(runtimeTemplate.outputOptions.hashFunction);
|
|
238
232
|
|
|
239
233
|
if (runtimeTemplate.outputOptions.hashSalt) {
|
|
240
234
|
hash.update(runtimeTemplate.outputOptions.hashSalt);
|
|
@@ -257,8 +251,7 @@ class AssetGenerator extends Generator {
|
|
|
257
251
|
/** @type {string} */
|
|
258
252
|
const contentHash = nonNumericOnlyHash(
|
|
259
253
|
fullContentHash,
|
|
260
|
-
|
|
261
|
-
(runtimeTemplate.outputOptions.hashDigestLength)
|
|
254
|
+
runtimeTemplate.outputOptions.hashDigestLength
|
|
262
255
|
);
|
|
263
256
|
|
|
264
257
|
return [fullContentHash, contentHash];
|
|
@@ -279,8 +272,7 @@ class AssetGenerator extends Generator {
|
|
|
279
272
|
) {
|
|
280
273
|
const assetModuleFilename =
|
|
281
274
|
generatorOptions.filename ||
|
|
282
|
-
|
|
283
|
-
(runtimeTemplate.outputOptions.assetModuleFilename);
|
|
275
|
+
runtimeTemplate.outputOptions.assetModuleFilename;
|
|
284
276
|
|
|
285
277
|
const sourceFilename = AssetGenerator.getSourceFileName(
|
|
286
278
|
module,
|
|
@@ -381,13 +373,9 @@ class AssetGenerator extends Generator {
|
|
|
381
373
|
const path =
|
|
382
374
|
compilation.outputOptions.publicPath === "auto"
|
|
383
375
|
? CssUrlDependency.PUBLIC_PATH_AUTO
|
|
384
|
-
: compilation.getAssetPath(
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
{
|
|
388
|
-
hash: compilation.hash
|
|
389
|
-
}
|
|
390
|
-
);
|
|
376
|
+
: compilation.getAssetPath(compilation.outputOptions.publicPath, {
|
|
377
|
+
hash: compilation.hash
|
|
378
|
+
});
|
|
391
379
|
|
|
392
380
|
assetPath = path + filename;
|
|
393
381
|
}
|
|
@@ -425,7 +413,7 @@ class AssetGenerator extends Generator {
|
|
|
425
413
|
(this.dataUrlOptions).mimetype;
|
|
426
414
|
if (mimeType === undefined) {
|
|
427
415
|
const ext = path.extname(
|
|
428
|
-
/** @type {
|
|
416
|
+
/** @type {NameForCondition} */
|
|
429
417
|
(module.nameForCondition())
|
|
430
418
|
);
|
|
431
419
|
if (
|
|
@@ -436,7 +424,7 @@ class AssetGenerator extends Generator {
|
|
|
436
424
|
module.resourceResolveData.mimetype +
|
|
437
425
|
module.resourceResolveData.parameters;
|
|
438
426
|
} else if (ext) {
|
|
439
|
-
mimeType =
|
|
427
|
+
mimeType = getMimeTypes().lookup(ext);
|
|
440
428
|
|
|
441
429
|
if (typeof mimeType !== "string") {
|
|
442
430
|
throw new Error(
|
|
@@ -471,7 +459,7 @@ class AssetGenerator extends Generator {
|
|
|
471
459
|
|
|
472
460
|
if (typeof this.dataUrlOptions === "function") {
|
|
473
461
|
encodedSource = this.dataUrlOptions.call(null, source.source(), {
|
|
474
|
-
filename:
|
|
462
|
+
filename: /** @type {string} */ (module.getResource()),
|
|
475
463
|
module
|
|
476
464
|
});
|
|
477
465
|
} else {
|
|
@@ -619,7 +607,7 @@ class AssetGenerator extends Generator {
|
|
|
619
607
|
);
|
|
620
608
|
|
|
621
609
|
return new RawSource(
|
|
622
|
-
`${runtimeTemplate.
|
|
610
|
+
`${runtimeTemplate.renderConst()} ${
|
|
623
611
|
ConcatenationScope.NAMESPACE_OBJECT_EXPORT
|
|
624
612
|
} = ${content};`
|
|
625
613
|
);
|
|
@@ -794,9 +782,7 @@ class AssetGenerator extends Generator {
|
|
|
794
782
|
}
|
|
795
783
|
|
|
796
784
|
const assetModuleFilename =
|
|
797
|
-
this.filename ||
|
|
798
|
-
/** @type {AssetModuleFilename} */
|
|
799
|
-
(runtimeTemplate.outputOptions.assetModuleFilename);
|
|
785
|
+
this.filename || runtimeTemplate.outputOptions.assetModuleFilename;
|
|
800
786
|
const { path: filename, info } =
|
|
801
787
|
runtimeTemplate.compilation.getAssetPathWithInfo(
|
|
802
788
|
assetModuleFilename,
|
|
@@ -7,22 +7,19 @@
|
|
|
7
7
|
|
|
8
8
|
const {
|
|
9
9
|
ASSET_MODULE_TYPE,
|
|
10
|
+
ASSET_MODULE_TYPE_BYTES,
|
|
10
11
|
ASSET_MODULE_TYPE_INLINE,
|
|
11
12
|
ASSET_MODULE_TYPE_RESOURCE,
|
|
12
13
|
ASSET_MODULE_TYPE_SOURCE
|
|
13
14
|
} = require("../ModuleTypeConstants");
|
|
14
|
-
const { cleverMerge } = require("../util/cleverMerge");
|
|
15
15
|
const { compareModulesByIdOrIdentifier } = require("../util/comparators");
|
|
16
16
|
const createSchemaValidation = require("../util/create-schema-validation");
|
|
17
17
|
const memoize = require("../util/memoize");
|
|
18
18
|
|
|
19
19
|
/** @typedef {import("webpack-sources").Source} Source */
|
|
20
|
-
/** @typedef {import("../../declarations/WebpackOptions").AssetParserOptions} AssetParserOptions */
|
|
21
20
|
/** @typedef {import("schema-utils").Schema} Schema */
|
|
22
|
-
/** @typedef {import("../Chunk")} Chunk */
|
|
23
21
|
/** @typedef {import("../Compilation").AssetInfo} AssetInfo */
|
|
24
22
|
/** @typedef {import("../Compiler")} Compiler */
|
|
25
|
-
/** @typedef {import("../Module")} Module */
|
|
26
23
|
/** @typedef {import("../Module").BuildInfo} BuildInfo */
|
|
27
24
|
/** @typedef {import("../Module").CodeGenerationResult} CodeGenerationResult */
|
|
28
25
|
/** @typedef {import("../NormalModule")} NormalModule */
|
|
@@ -74,9 +71,11 @@ const validateParserOptions = createSchemaValidation(
|
|
|
74
71
|
const getAssetGenerator = memoize(() => require("./AssetGenerator"));
|
|
75
72
|
const getAssetParser = memoize(() => require("./AssetParser"));
|
|
76
73
|
const getAssetSourceParser = memoize(() => require("./AssetSourceParser"));
|
|
74
|
+
const getAssetBytesParser = memoize(() => require("./AssetBytesParser"));
|
|
77
75
|
const getAssetSourceGenerator = memoize(() =>
|
|
78
76
|
require("./AssetSourceGenerator")
|
|
79
77
|
);
|
|
78
|
+
const getAssetBytesGenerator = memoize(() => require("./AssetBytesGenerator"));
|
|
80
79
|
|
|
81
80
|
const type = ASSET_MODULE_TYPE;
|
|
82
81
|
const PLUGIN_NAME = "AssetModulesPlugin";
|
|
@@ -95,11 +94,6 @@ class AssetModulesPlugin {
|
|
|
95
94
|
.for(ASSET_MODULE_TYPE)
|
|
96
95
|
.tap(PLUGIN_NAME, (parserOptions) => {
|
|
97
96
|
validateParserOptions(parserOptions);
|
|
98
|
-
parserOptions = cleverMerge(
|
|
99
|
-
/** @type {AssetParserOptions} */
|
|
100
|
-
(compiler.options.module.parser.asset),
|
|
101
|
-
parserOptions
|
|
102
|
-
);
|
|
103
97
|
|
|
104
98
|
let dataUrlCondition = parserOptions.dataUrlCondition;
|
|
105
99
|
if (!dataUrlCondition || typeof dataUrlCondition === "object") {
|
|
@@ -134,6 +128,13 @@ class AssetModulesPlugin {
|
|
|
134
128
|
|
|
135
129
|
return new AssetSourceParser();
|
|
136
130
|
});
|
|
131
|
+
normalModuleFactory.hooks.createParser
|
|
132
|
+
.for(ASSET_MODULE_TYPE_BYTES)
|
|
133
|
+
.tap(PLUGIN_NAME, (_parserOptions) => {
|
|
134
|
+
const AssetBytesParser = getAssetBytesParser();
|
|
135
|
+
|
|
136
|
+
return new AssetBytesParser();
|
|
137
|
+
});
|
|
137
138
|
|
|
138
139
|
for (const type of [
|
|
139
140
|
ASSET_MODULE_TYPE,
|
|
@@ -186,6 +187,14 @@ class AssetModulesPlugin {
|
|
|
186
187
|
return new AssetSourceGenerator(compilation.moduleGraph);
|
|
187
188
|
});
|
|
188
189
|
|
|
190
|
+
normalModuleFactory.hooks.createGenerator
|
|
191
|
+
.for(ASSET_MODULE_TYPE_BYTES)
|
|
192
|
+
.tap(PLUGIN_NAME, () => {
|
|
193
|
+
const AssetBytesGenerator = getAssetBytesGenerator();
|
|
194
|
+
|
|
195
|
+
return new AssetBytesGenerator(compilation.moduleGraph);
|
|
196
|
+
});
|
|
197
|
+
|
|
189
198
|
compilation.hooks.renderManifest.tap(PLUGIN_NAME, (result, options) => {
|
|
190
199
|
const { chunkGraph } = compilation;
|
|
191
200
|
const { chunk, codeGenerationResults, runtimeTemplate } = options;
|
|
@@ -245,10 +254,15 @@ class AssetModulesPlugin {
|
|
|
245
254
|
entryInfo = assetInfo;
|
|
246
255
|
entryHash = fullContentHash;
|
|
247
256
|
} else {
|
|
248
|
-
entryFilename =
|
|
249
|
-
|
|
257
|
+
entryFilename =
|
|
258
|
+
/** @type {string} */
|
|
259
|
+
(buildInfo.filename || data.get("filename"));
|
|
260
|
+
entryInfo =
|
|
261
|
+
/** @type {AssetInfo} */
|
|
262
|
+
(buildInfo.assetInfo || data.get("assetInfo"));
|
|
250
263
|
entryHash =
|
|
251
|
-
|
|
264
|
+
/** @type {string} */
|
|
265
|
+
(buildInfo.fullContentHash || data.get("fullContentHash"));
|
|
252
266
|
}
|
|
253
267
|
|
|
254
268
|
result.push({
|
|
@@ -280,10 +294,14 @@ class AssetModulesPlugin {
|
|
|
280
294
|
const data =
|
|
281
295
|
/** @type {NonNullable<CodeGenerationResult["data"]>} */
|
|
282
296
|
(codeGenerationResult.data);
|
|
283
|
-
context.assets.set(
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
297
|
+
context.assets.set(
|
|
298
|
+
/** @type {string} */
|
|
299
|
+
(data.get("filename")),
|
|
300
|
+
{
|
|
301
|
+
source,
|
|
302
|
+
info: data.get("assetInfo")
|
|
303
|
+
}
|
|
304
|
+
);
|
|
287
305
|
}
|
|
288
306
|
);
|
|
289
307
|
}
|
package/lib/asset/AssetParser.js
CHANGED
|
@@ -33,15 +33,19 @@ class AssetParser extends Parser {
|
|
|
33
33
|
throw new Error("AssetParser doesn't accept preparsed AST");
|
|
34
34
|
}
|
|
35
35
|
|
|
36
|
-
const buildInfo =
|
|
36
|
+
const buildInfo =
|
|
37
|
+
/** @type {BuildInfo} */
|
|
38
|
+
(state.module.buildInfo);
|
|
37
39
|
buildInfo.strict = true;
|
|
38
|
-
const buildMeta =
|
|
40
|
+
const buildMeta =
|
|
41
|
+
/** @type {BuildMeta} */
|
|
42
|
+
(state.module.buildMeta);
|
|
39
43
|
buildMeta.exportsType = "default";
|
|
40
44
|
buildMeta.defaultObject = false;
|
|
41
45
|
|
|
42
46
|
if (typeof this.dataUrlCondition === "function") {
|
|
43
47
|
buildInfo.dataUrl = this.dataUrlCondition(source, {
|
|
44
|
-
filename:
|
|
48
|
+
filename: /** @type {string} */ (state.module.getResource()),
|
|
45
49
|
module: state.module
|
|
46
50
|
});
|
|
47
51
|
} else if (typeof this.dataUrlCondition === "boolean") {
|
|
@@ -60,7 +60,7 @@ class AssetSourceGenerator extends Generator {
|
|
|
60
60
|
concatenationScope.registerNamespaceExport(
|
|
61
61
|
ConcatenationScope.NAMESPACE_OBJECT_EXPORT
|
|
62
62
|
);
|
|
63
|
-
sourceContent = `${runtimeTemplate.
|
|
63
|
+
sourceContent = `${runtimeTemplate.renderConst()} ${
|
|
64
64
|
ConcatenationScope.NAMESPACE_OBJECT_EXPORT
|
|
65
65
|
} = ${JSON.stringify(encodedSource)};`;
|
|
66
66
|
} else {
|
|
@@ -12,10 +12,11 @@ const { ASSET_MODULE_TYPE_RAW_DATA_URL } = require("../ModuleTypeConstants");
|
|
|
12
12
|
const RuntimeGlobals = require("../RuntimeGlobals");
|
|
13
13
|
const makeSerializable = require("../util/makeSerializable");
|
|
14
14
|
|
|
15
|
-
/** @typedef {import("
|
|
15
|
+
/** @typedef {import("../config/defaults").WebpackOptionsNormalizedWithDefaults} WebpackOptions */
|
|
16
16
|
/** @typedef {import("../Compilation")} Compilation */
|
|
17
17
|
/** @typedef {import("../Dependency").UpdateHashContext} UpdateHashContext */
|
|
18
18
|
/** @typedef {import("../Module").BuildCallback} BuildCallback */
|
|
19
|
+
/** @typedef {import("../Module").RuntimeRequirements} RuntimeRequirements */
|
|
19
20
|
/** @typedef {import("../Module").CodeGenerationContext} CodeGenerationContext */
|
|
20
21
|
/** @typedef {import("../Module").CodeGenerationResult} CodeGenerationResult */
|
|
21
22
|
/** @typedef {import("../Module").NeedBuildCallback} NeedBuildCallback */
|
|
@@ -23,7 +24,6 @@ const makeSerializable = require("../util/makeSerializable");
|
|
|
23
24
|
/** @typedef {import("../Module").SourceTypes} SourceTypes */
|
|
24
25
|
/** @typedef {import("../RequestShortener")} RequestShortener */
|
|
25
26
|
/** @typedef {import("../ResolverFactory").ResolverWithOptions} ResolverWithOptions */
|
|
26
|
-
/** @typedef {import("../WebpackError")} WebpackError */
|
|
27
27
|
/** @typedef {import("../serialization/ObjectMiddleware").ObjectDeserializerContext} ObjectDeserializerContext */
|
|
28
28
|
/** @typedef {import("../serialization/ObjectMiddleware").ObjectSerializerContext} ObjectSerializerContext */
|
|
29
29
|
/** @typedef {import("../util/Hash")} Hash */
|
|
@@ -120,6 +120,7 @@ class RawDataUrlModule extends Module {
|
|
|
120
120
|
data.set("url", {
|
|
121
121
|
javascript: this.url
|
|
122
122
|
});
|
|
123
|
+
/** @type {RuntimeRequirements} */
|
|
123
124
|
const runtimeRequirements = new Set();
|
|
124
125
|
runtimeRequirements.add(RuntimeGlobals.module);
|
|
125
126
|
return { sources, runtimeRequirements, data };
|
|
@@ -10,17 +10,19 @@ const HarmonyImportDependency = require("../dependencies/HarmonyImportDependency
|
|
|
10
10
|
/** @typedef {import("../ModuleGraph")} ModuleGraph */
|
|
11
11
|
/** @typedef {import("../Module")} Module */
|
|
12
12
|
|
|
13
|
+
/** @typedef {Set<Module>} Modules */
|
|
14
|
+
|
|
13
15
|
/**
|
|
14
16
|
* @param {ModuleGraph} moduleGraph module graph
|
|
15
17
|
* @param {Module} module module
|
|
16
|
-
* @returns {
|
|
18
|
+
* @returns {Modules} set of modules
|
|
17
19
|
*/
|
|
18
20
|
const getOutgoingAsyncModules = (moduleGraph, module) => {
|
|
19
|
-
/** @type {
|
|
21
|
+
/** @type {Modules} */
|
|
20
22
|
const set = new Set();
|
|
21
|
-
/** @type {
|
|
23
|
+
/** @type {Modules} */
|
|
22
24
|
const seen = new Set();
|
|
23
|
-
(function g(
|
|
25
|
+
(function g(module) {
|
|
24
26
|
if (!moduleGraph.isAsync(module) || seen.has(module)) return;
|
|
25
27
|
seen.add(module);
|
|
26
28
|
if (module.buildMeta && module.buildMeta.async) {
|
package/lib/buildChunkGraph.js
CHANGED
|
@@ -15,7 +15,6 @@ const { getEntryRuntime, mergeRuntime } = require("./util/runtime");
|
|
|
15
15
|
/** @typedef {import("./ChunkGroup")} ChunkGroup */
|
|
16
16
|
/** @typedef {import("./Compilation")} Compilation */
|
|
17
17
|
/** @typedef {import("./DependenciesBlock")} DependenciesBlock */
|
|
18
|
-
/** @typedef {import("./Dependency")} Dependency */
|
|
19
18
|
/** @typedef {import("./Dependency").DependencyLocation} DependencyLocation */
|
|
20
19
|
/** @typedef {import("./Entrypoint")} Entrypoint */
|
|
21
20
|
/** @typedef {import("./Module")} Module */
|
|
@@ -7,11 +7,9 @@
|
|
|
7
7
|
|
|
8
8
|
const Cache = require("../Cache");
|
|
9
9
|
|
|
10
|
-
/** @typedef {import("webpack-sources").Source} Source */
|
|
11
10
|
/** @typedef {import("../Cache").Data} Data */
|
|
12
11
|
/** @typedef {import("../Cache").Etag} Etag */
|
|
13
12
|
/** @typedef {import("../Compiler")} Compiler */
|
|
14
|
-
/** @typedef {import("../Module")} Module */
|
|
15
13
|
|
|
16
14
|
class MemoryCachePlugin {
|
|
17
15
|
/**
|
|
@@ -7,11 +7,9 @@
|
|
|
7
7
|
|
|
8
8
|
const Cache = require("../Cache");
|
|
9
9
|
|
|
10
|
-
/** @typedef {import("webpack-sources").Source} Source */
|
|
11
10
|
/** @typedef {import("../Cache").Data} Data */
|
|
12
11
|
/** @typedef {import("../Cache").Etag} Etag */
|
|
13
12
|
/** @typedef {import("../Compiler")} Compiler */
|
|
14
|
-
/** @typedef {import("../Module")} Module */
|
|
15
13
|
|
|
16
14
|
/**
|
|
17
15
|
* @typedef {object} MemoryWithGcCachePluginOptions
|
|
@@ -51,11 +51,17 @@ class PackContainer {
|
|
|
51
51
|
resolveResults,
|
|
52
52
|
resolveBuildDependenciesSnapshot
|
|
53
53
|
) {
|
|
54
|
+
/** @type {Pack | (() => Pack) } */
|
|
54
55
|
this.data = data;
|
|
56
|
+
/** @type {string} */
|
|
55
57
|
this.version = version;
|
|
58
|
+
/** @type {Snapshot} */
|
|
56
59
|
this.buildSnapshot = buildSnapshot;
|
|
60
|
+
/** @type {BuildDependencies} */
|
|
57
61
|
this.buildDependencies = buildDependencies;
|
|
62
|
+
/** @type {ResolveResults} */
|
|
58
63
|
this.resolveResults = resolveResults;
|
|
64
|
+
/** @type {Snapshot} */
|
|
59
65
|
this.resolveBuildDependenciesSnapshot = resolveBuildDependenciesSnapshot;
|
|
60
66
|
}
|
|
61
67
|
|
|
@@ -104,10 +110,15 @@ class PackItemInfo {
|
|
|
104
110
|
* @param {Data} value fresh value of item
|
|
105
111
|
*/
|
|
106
112
|
constructor(identifier, etag, value) {
|
|
113
|
+
/** @type {string} */
|
|
107
114
|
this.identifier = identifier;
|
|
115
|
+
/** @type {string | null | undefined} */
|
|
108
116
|
this.etag = etag;
|
|
117
|
+
/** @type {number} */
|
|
109
118
|
this.location = -1;
|
|
119
|
+
/** @type {number} */
|
|
110
120
|
this.lastAccess = Date.now();
|
|
121
|
+
/** @type {Data} */
|
|
111
122
|
this.freshValue = value;
|
|
112
123
|
}
|
|
113
124
|
}
|
|
@@ -1285,7 +1296,9 @@ class PackFileCacheStrategy {
|
|
|
1285
1296
|
logger.timeEnd("check build dependencies");
|
|
1286
1297
|
if (buildSnapshotValid && resolveValid) {
|
|
1287
1298
|
logger.time("restore cache content metadata");
|
|
1288
|
-
const d =
|
|
1299
|
+
const d =
|
|
1300
|
+
/** @type {() => Pack} */
|
|
1301
|
+
(packContainer.data)();
|
|
1289
1302
|
logger.timeEnd("restore cache content metadata");
|
|
1290
1303
|
return d;
|
|
1291
1304
|
}
|