webpack 5.104.1 → 5.105.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/bin/webpack.js +6 -3
- package/lib/APIPlugin.js +85 -15
- package/lib/AbstractMethodError.js +1 -0
- package/lib/AsyncDependenciesBlock.js +13 -1
- package/lib/AsyncDependencyToInitialChunkError.js +1 -0
- package/lib/AutomaticPrefetchPlugin.js +1 -1
- package/lib/BannerPlugin.js +2 -0
- package/lib/CacheFacade.js +2 -2
- package/lib/CaseSensitiveModulesWarning.js +1 -0
- package/lib/Chunk.js +8 -4
- package/lib/ChunkGraph.js +30 -9
- package/lib/ChunkGroup.js +6 -3
- package/lib/ChunkRenderError.js +2 -0
- package/lib/CleanPlugin.js +4 -1
- package/lib/CodeGenerationError.js +7 -1
- package/lib/CodeGenerationResults.js +10 -3
- package/lib/CommentCompilationWarning.js +2 -1
- package/lib/Compilation.js +280 -236
- package/lib/Compiler.js +3 -2
- package/lib/ConcatenationScope.js +2 -1
- package/lib/ConcurrentCompilationError.js +3 -3
- package/lib/ContextModule.js +248 -111
- package/lib/ContextModuleFactory.js +14 -2
- package/lib/DefinePlugin.js +3 -1
- package/lib/DelegatedModule.js +6 -0
- package/lib/DelegatedModuleFactoryPlugin.js +2 -0
- package/lib/Dependency.js +6 -1
- package/lib/DependencyTemplates.js +3 -2
- package/lib/DllModule.js +2 -0
- package/lib/DllReferencePlugin.js +1 -0
- package/lib/DotenvPlugin.js +11 -5
- package/lib/DynamicEntryPlugin.js +1 -0
- package/lib/EnvironmentNotSupportAsyncWarning.js +1 -0
- package/lib/EvalSourceMapDevToolPlugin.js +17 -13
- package/lib/ExportsInfo.js +8 -4
- package/lib/ExternalModule.js +16 -0
- package/lib/FalseIIFEUmdWarning.js +1 -0
- package/lib/FileSystemInfo.js +49 -25
- package/lib/FlagDependencyExportsPlugin.js +8 -1
- package/lib/FlagDependencyUsagePlugin.js +9 -7
- package/lib/HarmonyLinkingError.js +1 -0
- package/lib/HookWebpackError.js +2 -0
- package/lib/HotModuleReplacementPlugin.js +16 -2
- package/lib/InitFragment.js +1 -0
- package/lib/InvalidDependenciesModuleWarning.js +1 -0
- package/lib/LibManifestPlugin.js +1 -0
- package/lib/ManifestPlugin.js +4 -1
- package/lib/Module.js +7 -4
- package/lib/ModuleBuildError.js +3 -1
- package/lib/ModuleDependencyError.js +1 -0
- package/lib/ModuleDependencyWarning.js +1 -0
- package/lib/ModuleError.js +2 -1
- package/lib/ModuleFilenameHelpers.js +2 -1
- package/lib/ModuleGraph.js +3 -0
- package/lib/ModuleGraphConnection.js +10 -1
- package/lib/ModuleHashingError.js +2 -0
- package/lib/ModuleInfoHeaderPlugin.js +6 -1
- package/lib/ModuleNotFoundError.js +1 -0
- package/lib/ModuleParseError.js +5 -1
- package/lib/ModuleProfile.js +1 -1
- package/lib/ModuleRestoreError.js +2 -0
- package/lib/ModuleSourceTypeConstants.js +1 -11
- package/lib/ModuleStoreError.js +2 -0
- package/lib/ModuleWarning.js +3 -1
- package/lib/MultiCompiler.js +11 -7
- package/lib/MultiWatching.js +2 -2
- package/lib/NoModeWarning.js +1 -0
- package/lib/NodeStuffInWebError.js +1 -0
- package/lib/NormalModule.js +26 -5
- package/lib/NormalModuleFactory.js +20 -4
- package/lib/OptionsApply.js +3 -1
- package/lib/ProgressPlugin.js +4 -0
- package/lib/RawModule.js +2 -0
- package/lib/RuntimeModule.js +10 -0
- package/lib/RuntimePlugin.js +7 -9
- package/lib/RuntimeTemplate.js +14 -7
- package/lib/SourceMapDevToolPlugin.js +30 -23
- package/lib/Template.js +10 -5
- package/lib/TemplatedPathPlugin.js +4 -2
- package/lib/UnhandledSchemeError.js +1 -0
- package/lib/UnsupportedFeatureWarning.js +1 -0
- package/lib/WarnDeprecatedOptionPlugin.js +1 -0
- package/lib/WatchIgnorePlugin.js +1 -1
- package/lib/Watching.js +5 -0
- package/lib/WebpackError.js +4 -0
- package/lib/WebpackOptionsApply.js +60 -40
- package/lib/asset/AssetBytesGenerator.js +1 -0
- package/lib/asset/AssetGenerator.js +9 -3
- package/lib/asset/AssetModulesPlugin.js +33 -2
- package/lib/asset/AssetSourceGenerator.js +1 -0
- package/lib/asset/RawDataUrlModule.js +4 -0
- package/lib/async-modules/AwaitDependenciesInitFragment.js +4 -1
- package/lib/buildChunkGraph.js +31 -2
- package/lib/cache/MemoryWithGcCachePlugin.js +1 -0
- package/lib/cache/PackFileCacheStrategy.js +41 -8
- package/lib/cache/getLazyHashedEtag.js +13 -4
- package/lib/cache/mergeEtags.js +3 -1
- package/lib/cli.js +3 -1
- package/lib/config/defaults.js +65 -44
- package/lib/config/normalization.js +96 -0
- package/lib/container/ContainerEntryModule.js +4 -0
- package/lib/container/FallbackModule.js +2 -0
- package/lib/container/HoistContainerReferencesPlugin.js +6 -0
- package/lib/container/RemoteModule.js +19 -0
- package/lib/css/CssGenerator.js +31 -4
- package/lib/css/CssModulesPlugin.js +26 -30
- package/lib/css/CssParser.js +12 -9
- package/lib/debug/ProfilingPlugin.js +1 -0
- package/lib/dependencies/AMDDefineDependency.js +3 -1
- package/lib/dependencies/AMDDefineDependencyParserPlugin.js +6 -0
- package/lib/dependencies/AMDPlugin.js +1 -1
- package/lib/dependencies/AMDRequireDependenciesBlockParserPlugin.js +7 -1
- package/lib/dependencies/CachedConstDependency.js +1 -0
- package/lib/dependencies/CommonJsDependencyHelpers.js +2 -0
- package/lib/dependencies/CommonJsExportRequireDependency.js +1 -0
- package/lib/dependencies/CommonJsFullRequireDependency.js +2 -0
- package/lib/dependencies/CommonJsImportsParserPlugin.js +3 -0
- package/lib/dependencies/CommonJsRequireContextDependency.js +2 -2
- package/lib/dependencies/CommonJsSelfReferenceDependency.js +1 -0
- package/lib/dependencies/ConstDependency.js +1 -0
- package/lib/dependencies/ContextDependencyHelpers.js +11 -4
- package/lib/dependencies/ContextElementDependency.js +1 -0
- package/lib/dependencies/CriticalDependencyWarning.js +1 -0
- package/lib/dependencies/CssIcssExportDependency.js +5 -4
- package/lib/dependencies/CssIcssSymbolDependency.js +1 -0
- package/lib/dependencies/CssUrlDependency.js +2 -3
- package/lib/dependencies/ExternalModuleInitFragment.js +4 -1
- package/lib/dependencies/ExternalModuleInitFragmentDependency.js +0 -9
- package/lib/dependencies/HarmonyAcceptDependency.js +3 -0
- package/lib/dependencies/HarmonyEvaluatedImportSpecifierDependency.js +1 -0
- package/lib/dependencies/HarmonyExportExpressionDependency.js +4 -0
- package/lib/dependencies/HarmonyExportImportedSpecifierDependency.js +8 -1
- package/lib/dependencies/HarmonyExportInitFragment.js +17 -3
- package/lib/dependencies/HarmonyExportSpecifierDependency.js +4 -0
- package/lib/dependencies/HarmonyImportDependencyParserPlugin.js +266 -5
- package/lib/dependencies/HarmonyImportSpecifierDependency.js +22 -3
- package/lib/dependencies/ImportDependency.js +1 -0
- package/lib/dependencies/ImportMetaContextDependencyParserPlugin.js +1 -0
- package/lib/dependencies/ImportMetaPlugin.js +53 -11
- package/lib/dependencies/ImportParserPlugin.js +7 -12
- package/lib/dependencies/LoaderPlugin.js +3 -0
- package/lib/dependencies/ModuleDecoratorDependency.js +1 -0
- package/lib/dependencies/ModuleDependency.js +1 -0
- package/lib/dependencies/ModuleInitFragmentDependency.js +87 -0
- package/lib/dependencies/ProvidedDependency.js +1 -0
- package/lib/dependencies/RequireContextPlugin.js +1 -0
- package/lib/dependencies/RequireEnsureDependenciesBlockParserPlugin.js +7 -2
- package/lib/dependencies/RuntimeRequirementsDependency.js +1 -0
- package/lib/dependencies/WorkerDependency.js +9 -3
- package/lib/dependencies/WorkerPlugin.js +1 -0
- package/lib/dependencies/getFunctionExpression.js +3 -1
- package/lib/errors/BuildCycleError.js +4 -1
- package/lib/esm/ModuleChunkFormatPlugin.js +6 -4
- package/lib/esm/ModuleChunkLoadingPlugin.js +1 -0
- package/lib/esm/ModuleChunkLoadingRuntimeModule.js +1 -0
- package/lib/hmr/LazyCompilationPlugin.js +5 -0
- package/lib/hmr/lazyCompilationBackend.js +3 -2
- package/lib/ids/ChunkModuleIdRangePlugin.js +2 -0
- package/lib/ids/IdHelpers.js +10 -8
- package/lib/ids/OccurrenceModuleIdsPlugin.js +15 -7
- package/lib/ids/SyncModuleIdsPlugin.js +5 -1
- package/lib/javascript/BasicEvaluatedExpression.js +1 -0
- package/lib/javascript/EnableChunkLoadingPlugin.js +5 -2
- package/lib/javascript/JavascriptModulesPlugin.js +29 -8
- package/lib/javascript/JavascriptParser.js +47 -14
- package/lib/json/JsonParser.js +6 -0
- package/lib/library/AbstractLibraryPlugin.js +4 -1
- package/lib/library/AmdLibraryPlugin.js +2 -1
- package/lib/library/AssignLibraryPlugin.js +6 -2
- package/lib/library/EnableLibraryPlugin.js +1 -0
- package/lib/library/ExportPropertyLibraryPlugin.js +1 -1
- package/lib/library/JsonpLibraryPlugin.js +1 -1
- package/lib/library/ModuleLibraryPlugin.js +130 -13
- package/lib/library/SystemLibraryPlugin.js +4 -1
- package/lib/library/UmdLibraryPlugin.js +4 -3
- package/lib/logging/createConsoleLogger.js +3 -0
- package/lib/logging/truncateArgs.js +1 -1
- package/lib/node/CommonJsChunkLoadingPlugin.js +1 -0
- package/lib/node/NodeTargetPlugin.js +1 -0
- package/lib/node/NodeWatchFileSystem.js +3 -0
- package/lib/node/nodeConsole.js +18 -1
- package/lib/optimize/AggressiveMergingPlugin.js +2 -1
- package/lib/optimize/AggressiveSplittingPlugin.js +10 -6
- package/lib/optimize/ConcatenatedModule.js +33 -19
- package/lib/optimize/FlagIncludedChunksPlugin.js +11 -1
- package/lib/optimize/InnerGraph.js +5 -3
- package/lib/optimize/InnerGraphPlugin.js +25 -25
- package/lib/optimize/MangleExportsPlugin.js +14 -2
- package/lib/optimize/MergeDuplicateChunksPlugin.js +3 -0
- package/lib/optimize/MinChunkSizePlugin.js +5 -2
- package/lib/optimize/ModuleConcatenationPlugin.js +19 -4
- package/lib/optimize/RealContentHashPlugin.js +35 -27
- package/lib/optimize/RemoveParentModulesPlugin.js +12 -3
- package/lib/optimize/SideEffectsFlagPlugin.js +3 -0
- package/lib/optimize/SplitChunksPlugin.js +14 -3
- package/lib/performance/AssetsOverSizeLimitWarning.js +6 -2
- package/lib/performance/EntrypointsOverSizeLimitWarning.js +6 -2
- package/lib/performance/NoAsyncChunksWarning.js +1 -0
- package/lib/rules/BasicEffectRulePlugin.js +2 -0
- package/lib/rules/BasicMatcherRulePlugin.js +3 -0
- package/lib/rules/ObjectMatcherRulePlugin.js +5 -1
- package/lib/rules/RuleSetCompiler.js +2 -0
- package/lib/runtime/AsyncModuleRuntimeModule.js +1 -0
- package/lib/runtime/ChunkNameRuntimeModule.js +1 -0
- package/lib/runtime/CompatRuntimeModule.js +1 -0
- package/lib/runtime/EnsureChunkRuntimeModule.js +1 -0
- package/lib/runtime/GetChunkFilenameRuntimeModule.js +4 -0
- package/lib/runtime/GetMainFilenameRuntimeModule.js +2 -0
- package/lib/runtime/GetTrustedTypesPolicyRuntimeModule.js +1 -0
- package/lib/runtime/LoadScriptRuntimeModule.js +2 -0
- package/lib/runtime/MakeDeferredNamespaceObjectRuntime.js +15 -32
- package/lib/runtime/PublicPathRuntimeModule.js +1 -0
- package/lib/runtime/StartupChunkDependenciesPlugin.js +2 -0
- package/lib/runtime/StartupChunkDependenciesRuntimeModule.js +1 -0
- package/lib/runtime/StartupEntrypointRuntimeModule.js +1 -0
- package/lib/schemes/HttpUriPlugin.js +27 -7
- package/lib/schemes/VirtualUrlPlugin.js +7 -2
- package/lib/serialization/BinaryMiddleware.js +4 -0
- package/lib/serialization/FileMiddleware.js +9 -4
- package/lib/serialization/ObjectMiddleware.js +34 -11
- package/lib/serialization/PlainObjectSerializer.js +2 -0
- package/lib/sharing/ConsumeSharedModule.js +60 -0
- package/lib/sharing/ConsumeSharedPlugin.js +5 -4
- package/lib/sharing/ProvideSharedModule.js +4 -0
- package/lib/sharing/ProvideSharedPlugin.js +24 -25
- package/lib/sharing/resolveMatchedConfigs.js +2 -2
- package/lib/sharing/utils.js +8 -6
- package/lib/stats/DefaultStatsFactoryPlugin.js +14 -12
- package/lib/stats/DefaultStatsPrinterPlugin.js +6 -5
- package/lib/stats/StatsFactory.js +2 -2
- package/lib/url/URLParserPlugin.js +4 -3
- package/lib/util/AppendOnlyStackedSet.js +57 -0
- package/lib/util/Hash.js +1 -0
- package/lib/util/IterableHelpers.js +1 -0
- package/lib/util/LazyBucketSortedSet.js +1 -0
- package/lib/util/LazySet.js +1 -0
- package/lib/util/ParallelismFactorCalculator.js +1 -0
- package/lib/util/SortableSet.js +1 -0
- package/lib/util/StringXor.js +1 -0
- package/lib/util/binarySearchBounds.js +15 -8
- package/lib/util/chainedImports.js +1 -1
- package/lib/util/cleverMerge.js +6 -1
- package/lib/util/comparators.js +21 -1
- package/lib/util/compileBooleanMatcher.js +3 -3
- package/lib/util/concatenate.js +3 -2
- package/lib/util/conventions.js +3 -2
- package/lib/util/deterministicGrouping.js +13 -1
- package/lib/util/extractSourceMap.js +12 -13
- package/lib/util/fs.js +15 -19
- package/lib/util/hash/BatchedHash.js +3 -0
- package/lib/util/hash/BulkUpdateHash.js +7 -1
- package/lib/util/hash/hash-digest.js +1 -0
- package/lib/util/hash/wasm-hash.js +16 -1
- package/lib/util/identifier.js +7 -2
- package/lib/util/magicComment.js +1 -1
- package/lib/util/propertyName.js +1 -1
- package/lib/util/registerExternalSerializer.js +1 -0
- package/lib/util/runtime.js +15 -1
- package/lib/util/semver.js +1 -0
- package/lib/util/serialization.js +2 -2
- package/lib/wasm/EnableWasmLoadingPlugin.js +1 -0
- package/lib/wasm-async/AsyncWasmLoadingRuntimeModule.js +11 -3
- package/lib/wasm-async/AsyncWebAssemblyGenerator.js +1 -0
- package/lib/wasm-async/AsyncWebAssemblyModulesPlugin.js +3 -2
- package/lib/wasm-sync/UnsupportedWebAssemblyFeatureError.js +5 -1
- package/lib/wasm-sync/WasmChunkLoadingRuntimeModule.js +3 -0
- package/lib/wasm-sync/WebAssemblyInInitialChunkError.js +2 -0
- package/lib/wasm-sync/WebAssemblyJavascriptGenerator.js +7 -3
- package/lib/wasm-sync/WebAssemblyModulesPlugin.js +2 -2
- package/lib/wasm-sync/WebAssemblyParser.js +3 -1
- package/lib/web/FetchCompileWasmPlugin.js +1 -0
- package/lib/web/JsonpChunkLoadingPlugin.js +1 -0
- package/lib/web/JsonpChunkLoadingRuntimeModule.js +1 -0
- package/lib/webpack.js +13 -3
- package/lib/webworker/ImportScriptsChunkLoadingPlugin.js +1 -0
- package/package.json +20 -28
- package/schemas/WebpackOptions.check.js +1 -1
- package/schemas/WebpackOptions.json +71 -5
- package/types.d.ts +339 -93
package/lib/RuntimeTemplate.js
CHANGED
|
@@ -84,7 +84,7 @@ function getGlobalObject(definition) {
|
|
|
84
84
|
// iife
|
|
85
85
|
// call expression
|
|
86
86
|
// expression in parentheses
|
|
87
|
-
/^([_\p{L}][_0-9\p{L}]*)?\(.*\)$/iu.test(trimmed)
|
|
87
|
+
/^(?:[_\p{L}][_0-9\p{L}]*)?\(.*\)$/iu.test(trimmed)
|
|
88
88
|
) {
|
|
89
89
|
return trimmed;
|
|
90
90
|
}
|
|
@@ -356,6 +356,7 @@ class RuntimeTemplate {
|
|
|
356
356
|
* @returns {string} comment
|
|
357
357
|
*/
|
|
358
358
|
comment({ request, chunkName, chunkReason, message, exportName }) {
|
|
359
|
+
/** @type {string} */
|
|
359
360
|
let content;
|
|
360
361
|
if (this.outputOptions.pathinfo) {
|
|
361
362
|
content = [message, request, chunkName, chunkReason]
|
|
@@ -678,6 +679,7 @@ class RuntimeTemplate {
|
|
|
678
679
|
runtimeRequirements
|
|
679
680
|
});
|
|
680
681
|
|
|
682
|
+
/** @type {string} */
|
|
681
683
|
let appending;
|
|
682
684
|
let idExpr = JSON.stringify(chunkGraph.getModuleId(module));
|
|
683
685
|
const comment = this.comment({
|
|
@@ -711,7 +713,10 @@ class RuntimeTemplate {
|
|
|
711
713
|
|
|
712
714
|
if (isModuleDeferred) {
|
|
713
715
|
runtimeRequirements.add(RuntimeGlobals.makeDeferredNamespaceObject);
|
|
714
|
-
|
|
716
|
+
|
|
717
|
+
let mode = getMakeDeferredNamespaceModeFromExportsType(exportsType);
|
|
718
|
+
if (mode) mode = `${mode} | 16`;
|
|
719
|
+
|
|
715
720
|
const asyncDeps = Array.from(
|
|
716
721
|
getOutgoingAsyncModules(chunkGraph.moduleGraph, module),
|
|
717
722
|
(m) => chunkGraph.getModuleId(m)
|
|
@@ -852,14 +857,14 @@ class RuntimeTemplate {
|
|
|
852
857
|
* @param {object} options options object
|
|
853
858
|
* @param {boolean=} options.update whether a new variable should be created or the existing one updated
|
|
854
859
|
* @param {Module} options.module the module
|
|
860
|
+
* @param {Module} options.originModule module in which the statement is emitted
|
|
855
861
|
* @param {ModuleGraph} options.moduleGraph the module graph
|
|
856
862
|
* @param {ChunkGraph} options.chunkGraph the chunk graph
|
|
857
|
-
* @param {
|
|
863
|
+
* @param {RuntimeRequirements} options.runtimeRequirements if set, will be filled with runtime requirements
|
|
858
864
|
* @param {string} options.importVar name of the import variable
|
|
859
|
-
* @param {
|
|
865
|
+
* @param {string=} options.request the request that should be printed as comment
|
|
860
866
|
* @param {boolean=} options.weak true, if this is a weak dependency
|
|
861
|
-
* @param {
|
|
862
|
-
* @param {ModuleDependency} options.dependency module dependency
|
|
867
|
+
* @param {ModuleDependency=} options.dependency module dependency
|
|
863
868
|
* @returns {[string, string]} the import statement and the compat statement
|
|
864
869
|
*/
|
|
865
870
|
importStatement({
|
|
@@ -918,6 +923,8 @@ class RuntimeTemplate {
|
|
|
918
923
|
(originModule.buildMeta).strictHarmonyModule
|
|
919
924
|
);
|
|
920
925
|
runtimeRequirements.add(RuntimeGlobals.require);
|
|
926
|
+
|
|
927
|
+
/** @type {string} */
|
|
921
928
|
let importContent;
|
|
922
929
|
|
|
923
930
|
const isModuleDeferred =
|
|
@@ -961,7 +968,7 @@ class RuntimeTemplate {
|
|
|
961
968
|
* @param {string | string[]} options.exportName the export name
|
|
962
969
|
* @param {Module} options.originModule the origin module
|
|
963
970
|
* @param {boolean | undefined} options.asiSafe true, if location is safe for ASI, a bracket can be emitted
|
|
964
|
-
* @param {boolean} options.isCall true, if expression will be called
|
|
971
|
+
* @param {boolean | undefined} options.isCall true, if expression will be called
|
|
965
972
|
* @param {boolean | null} options.callContext when false, call context will not be preserved
|
|
966
973
|
* @param {boolean} options.defaultInterop when true and accessing the default exports, interop code will be generated
|
|
967
974
|
* @param {string} options.importVar the identifier name of the import variable
|
|
@@ -51,9 +51,9 @@ const validate = createSchemaValidation(
|
|
|
51
51
|
*/
|
|
52
52
|
|
|
53
53
|
const METACHARACTERS_REGEXP = /[-[\]\\/{}()*+?.^$|]/g;
|
|
54
|
-
const CONTENT_HASH_DETECT_REGEXP = /\[contenthash(
|
|
54
|
+
const CONTENT_HASH_DETECT_REGEXP = /\[contenthash(?::\w+)?\]/;
|
|
55
55
|
const CSS_AND_JS_MODULE_EXTENSIONS_REGEXP = /\.((c|m)?js|css)($|\?)/i;
|
|
56
|
-
const CSS_EXTENSION_DETECT_REGEXP = /\.css(
|
|
56
|
+
const CSS_EXTENSION_DETECT_REGEXP = /\.css(?:$|\?)/i;
|
|
57
57
|
const MAP_URL_COMMENT_REGEXP = /\[map\]/g;
|
|
58
58
|
const URL_COMMENT_REGEXP = /\[url\]/g;
|
|
59
59
|
const URL_FORMATTING_REGEXP = /^\n\/\/(.*)$/;
|
|
@@ -93,18 +93,19 @@ const getTaskForFile = (
|
|
|
93
93
|
compilation,
|
|
94
94
|
cacheItem
|
|
95
95
|
) => {
|
|
96
|
+
/** @type {string | Buffer} */
|
|
96
97
|
let source;
|
|
97
|
-
/** @type {RawSourceMap} */
|
|
98
|
+
/** @type {null | RawSourceMap} */
|
|
98
99
|
let sourceMap;
|
|
99
100
|
/**
|
|
100
101
|
* Check if asset can build source map
|
|
101
102
|
*/
|
|
102
103
|
if (asset.sourceAndMap) {
|
|
103
104
|
const sourceAndMap = asset.sourceAndMap(options);
|
|
104
|
-
sourceMap =
|
|
105
|
+
sourceMap = sourceAndMap.map;
|
|
105
106
|
source = sourceAndMap.source;
|
|
106
107
|
} else {
|
|
107
|
-
sourceMap =
|
|
108
|
+
sourceMap = asset.map(options);
|
|
108
109
|
source = asset.source();
|
|
109
110
|
}
|
|
110
111
|
if (!sourceMap || typeof source !== "string") return;
|
|
@@ -173,6 +174,7 @@ class SourceMapDevToolPlugin {
|
|
|
173
174
|
const options = this.options;
|
|
174
175
|
options.test = options.test || CSS_AND_JS_MODULE_EXTENSIONS_REGEXP;
|
|
175
176
|
|
|
177
|
+
/** @type {(filename: string) => boolean} */
|
|
176
178
|
const matchObject = ModuleFilenameHelpers.matchObject.bind(
|
|
177
179
|
undefined,
|
|
178
180
|
options
|
|
@@ -310,7 +312,7 @@ class SourceMapDevToolPlugin {
|
|
|
310
312
|
|
|
311
313
|
if (
|
|
312
314
|
typeof module === "string" &&
|
|
313
|
-
/^(data|https?):/.test(module)
|
|
315
|
+
/^(?:data|https?):/.test(module)
|
|
314
316
|
) {
|
|
315
317
|
moduleToSourceNameMapping.set(module, module);
|
|
316
318
|
continue;
|
|
@@ -416,7 +418,9 @@ class SourceMapDevToolPlugin {
|
|
|
416
418
|
asyncLib.each(
|
|
417
419
|
tasks,
|
|
418
420
|
(task, callback) => {
|
|
421
|
+
/** @type {Record<string, Source>} */
|
|
419
422
|
const assets = Object.create(null);
|
|
423
|
+
/** @type {Record<string, AssetInfo | undefined>} */
|
|
420
424
|
const assetsInfo = Object.create(null);
|
|
421
425
|
const file = task.file;
|
|
422
426
|
const chunk = fileToChunk.get(file);
|
|
@@ -434,24 +438,27 @@ class SourceMapDevToolPlugin {
|
|
|
434
438
|
moduleToSourceNameMapping.get(m)
|
|
435
439
|
);
|
|
436
440
|
sourceMap.sources = /** @type {string[]} */ (moduleFilenames);
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
}
|
|
449
|
-
return acc;
|
|
441
|
+
if (options.ignoreList) {
|
|
442
|
+
const ignoreList = sourceMap.sources.reduce(
|
|
443
|
+
/** @type {(acc: number[], sourceName: string, idx: number) => number[]} */ (
|
|
444
|
+
(acc, sourceName, idx) => {
|
|
445
|
+
const rule = /** @type {Rules} */ (
|
|
446
|
+
options.ignoreList
|
|
447
|
+
);
|
|
448
|
+
if (
|
|
449
|
+
ModuleFilenameHelpers.matchPart(sourceName, rule)
|
|
450
|
+
) {
|
|
451
|
+
acc.push(idx);
|
|
450
452
|
}
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
)
|
|
454
|
-
|
|
453
|
+
return acc;
|
|
454
|
+
}
|
|
455
|
+
),
|
|
456
|
+
[]
|
|
457
|
+
);
|
|
458
|
+
if (ignoreList.length > 0) {
|
|
459
|
+
sourceMap.ignoreList = ignoreList;
|
|
460
|
+
}
|
|
461
|
+
}
|
|
455
462
|
|
|
456
463
|
if (options.noSources) {
|
|
457
464
|
sourceMap.sourcesContent = undefined;
|
package/lib/Template.js
CHANGED
|
@@ -36,10 +36,10 @@ const NUMBER_OF_IDENTIFIER_CONTINUATION_CHARS =
|
|
|
36
36
|
const FUNCTION_CONTENT_REGEX = /^function\s?\(\)\s?\{\r?\n?|\r?\n?\}$/g;
|
|
37
37
|
const INDENT_MULTILINE_REGEX = /^\t/gm;
|
|
38
38
|
const LINE_SEPARATOR_REGEX = /\r?\n/g;
|
|
39
|
-
const IDENTIFIER_NAME_REPLACE_REGEX = /^([^a-
|
|
40
|
-
const IDENTIFIER_ALPHA_NUMERIC_NAME_REPLACE_REGEX = /[^a-
|
|
39
|
+
const IDENTIFIER_NAME_REPLACE_REGEX = /^([^a-z$_])/i;
|
|
40
|
+
const IDENTIFIER_ALPHA_NUMERIC_NAME_REPLACE_REGEX = /[^a-z0-9$]+/gi;
|
|
41
41
|
const COMMENT_END_REGEX = /\*\//g;
|
|
42
|
-
const PATH_NAME_NORMALIZE_REPLACE_REGEX = /[^a-
|
|
42
|
+
const PATH_NAME_NORMALIZE_REPLACE_REGEX = /[^a-z0-9_!§$()=\-^°]+/gi;
|
|
43
43
|
const MATCH_PADDED_HYPHENS_REPLACE_REGEX = /^-|-$/g;
|
|
44
44
|
|
|
45
45
|
/**
|
|
@@ -83,10 +83,14 @@ const MATCH_PADDED_HYPHENS_REPLACE_REGEX = /^-|-$/g;
|
|
|
83
83
|
* @typedef {(module: Module) => boolean} ModuleFilterPredicate
|
|
84
84
|
*/
|
|
85
85
|
|
|
86
|
+
/**
|
|
87
|
+
* @typedef {object} Stringable
|
|
88
|
+
* @property {() => string} toString
|
|
89
|
+
*/
|
|
90
|
+
|
|
86
91
|
class Template {
|
|
87
92
|
/**
|
|
88
|
-
* @
|
|
89
|
-
* @param {T} fn a runtime function (.runtime.js) "template"
|
|
93
|
+
* @param {Stringable} fn a runtime function (.runtime.js) "template"
|
|
90
94
|
* @returns {string} the updated and normalized function string
|
|
91
95
|
*/
|
|
92
96
|
static getFunctionContent(fn) {
|
|
@@ -359,6 +363,7 @@ class Template {
|
|
|
359
363
|
const source = new ConcatSource();
|
|
360
364
|
for (const module of runtimeModules) {
|
|
361
365
|
const codeGenerationResults = renderContext.codeGenerationResults;
|
|
366
|
+
/** @type {undefined | Source} */
|
|
362
367
|
let runtimeSource;
|
|
363
368
|
if (codeGenerationResults) {
|
|
364
369
|
runtimeSource = codeGenerationResults.getSource(
|
|
@@ -18,7 +18,7 @@ const { parseResource } = require("./util/identifier");
|
|
|
18
18
|
/** @typedef {import("./Compilation").PathData} PathData */
|
|
19
19
|
/** @typedef {import("./Compiler")} Compiler */
|
|
20
20
|
|
|
21
|
-
const REGEXP = /\[\\*([\w:]+)\\*\]/
|
|
21
|
+
const REGEXP = /\[\\*([\w:]+)\\*\]/g;
|
|
22
22
|
|
|
23
23
|
/** @type {PathData["prepareId"]} */
|
|
24
24
|
const prepareId = (id) => {
|
|
@@ -32,7 +32,7 @@ const prepareId = (id) => {
|
|
|
32
32
|
} + "").replace(/(^[.-]|[^a-zA-Z0-9_-])+/g, "_") + "`;
|
|
33
33
|
}
|
|
34
34
|
|
|
35
|
-
return id.replace(/(^[.-]|[^a-
|
|
35
|
+
return id.replace(/(^[.-]|[^a-z0-9_-])+/gi, "_");
|
|
36
36
|
};
|
|
37
37
|
|
|
38
38
|
/**
|
|
@@ -52,6 +52,7 @@ const prepareId = (id) => {
|
|
|
52
52
|
const hashLength = (replacer, handler, assetInfo, hashName) => {
|
|
53
53
|
/** @type {Replacer} */
|
|
54
54
|
const fn = (match, arg, input) => {
|
|
55
|
+
/** @type {string} */
|
|
55
56
|
let result;
|
|
56
57
|
const length = arg && Number.parseInt(arg, 10);
|
|
57
58
|
|
|
@@ -107,6 +108,7 @@ const replacer = (value, allowEmpty) => {
|
|
|
107
108
|
return fn;
|
|
108
109
|
};
|
|
109
110
|
|
|
111
|
+
/** @type {Map<string, (...args: EXPECTED_ANY[]) => EXPECTED_ANY>} */
|
|
110
112
|
const deprecationCache = new Map();
|
|
111
113
|
const deprecatedFunction = (() => () => {})();
|
|
112
114
|
/**
|
package/lib/WatchIgnorePlugin.js
CHANGED
|
@@ -8,9 +8,9 @@
|
|
|
8
8
|
const { groupBy } = require("./util/ArrayHelpers");
|
|
9
9
|
const createSchemaValidation = require("./util/create-schema-validation");
|
|
10
10
|
|
|
11
|
+
/** @typedef {import("watchpack").TimeInfoEntries} TimeInfoEntries */
|
|
11
12
|
/** @typedef {import("../declarations/plugins/WatchIgnorePlugin").WatchIgnorePluginOptions} WatchIgnorePluginOptions */
|
|
12
13
|
/** @typedef {import("./Compiler")} Compiler */
|
|
13
|
-
/** @typedef {import("./util/fs").TimeInfoEntries} TimeInfoEntries */
|
|
14
14
|
/** @typedef {import("./util/fs").WatchFileSystem} WatchFileSystem */
|
|
15
15
|
/** @typedef {import("./util/fs").WatchMethod} WatchMethod */
|
|
16
16
|
/** @typedef {import("./util/fs").Watcher} Watcher */
|
package/lib/Watching.js
CHANGED
|
@@ -15,6 +15,7 @@ const Stats = require("./Stats");
|
|
|
15
15
|
/** @typedef {import("./logging/Logger").Logger} Logger */
|
|
16
16
|
/** @typedef {import("./util/fs").TimeInfoEntries} TimeInfoEntries */
|
|
17
17
|
/** @typedef {import("./util/fs").WatchFileSystem} WatchFileSystem */
|
|
18
|
+
/** @typedef {import("./util/fs").Watcher} Watcher */
|
|
18
19
|
|
|
19
20
|
/**
|
|
20
21
|
* @template T
|
|
@@ -31,8 +32,10 @@ class Watching {
|
|
|
31
32
|
* @param {Callback<Stats>} handler completion handler
|
|
32
33
|
*/
|
|
33
34
|
constructor(compiler, watchOptions, handler) {
|
|
35
|
+
/** @type {null | number} */
|
|
34
36
|
this.startTime = null;
|
|
35
37
|
this.invalid = false;
|
|
38
|
+
/** @type {Callback<Stats>} */
|
|
36
39
|
this.handler = handler;
|
|
37
40
|
/** @type {ErrorCallback[]} */
|
|
38
41
|
this.callbacks = [];
|
|
@@ -64,7 +67,9 @@ class Watching {
|
|
|
64
67
|
this._initial = true;
|
|
65
68
|
this._invalidReported = true;
|
|
66
69
|
this._needRecords = true;
|
|
70
|
+
/** @type {undefined | null | Watcher} */
|
|
67
71
|
this.watcher = undefined;
|
|
72
|
+
/** @type {undefined | null | Watcher} */
|
|
68
73
|
this.pausedWatcher = undefined;
|
|
69
74
|
/** @type {CollectedFiles | undefined} */
|
|
70
75
|
this._collectedChangedFiles = undefined;
|
package/lib/WebpackError.js
CHANGED
|
@@ -37,6 +37,9 @@ class WebpackError extends Error {
|
|
|
37
37
|
this.file = undefined;
|
|
38
38
|
}
|
|
39
39
|
|
|
40
|
+
/**
|
|
41
|
+
* @returns {string} inspect message
|
|
42
|
+
*/
|
|
40
43
|
[inspect]() {
|
|
41
44
|
return (
|
|
42
45
|
this.stack +
|
|
@@ -74,4 +77,5 @@ class WebpackError extends Error {
|
|
|
74
77
|
|
|
75
78
|
makeSerializable(WebpackError, "webpack/lib/WebpackError");
|
|
76
79
|
|
|
80
|
+
/** @type {typeof WebpackError} */
|
|
77
81
|
module.exports = WebpackError;
|
|
@@ -76,6 +76,7 @@ const { cleverMerge } = require("./util/cleverMerge");
|
|
|
76
76
|
|
|
77
77
|
/** @typedef {import("../declarations/WebpackOptions").WebpackPluginFunction} WebpackPluginFunction */
|
|
78
78
|
/** @typedef {import("./config/defaults").WebpackOptionsNormalizedWithDefaults} WebpackOptions */
|
|
79
|
+
/** @typedef {import("./config/normalization").WebpackOptionsInterception} WebpackOptionsInterception */
|
|
79
80
|
/** @typedef {import("./Compiler")} Compiler */
|
|
80
81
|
/** @typedef {import("./util/fs").InputFileSystem} InputFileSystem */
|
|
81
82
|
/** @typedef {import("./util/fs").IntermediateFileSystem} IntermediateFileSystem */
|
|
@@ -90,9 +91,10 @@ class WebpackOptionsApply extends OptionsApply {
|
|
|
90
91
|
/**
|
|
91
92
|
* @param {WebpackOptions} options options object
|
|
92
93
|
* @param {Compiler} compiler compiler object
|
|
94
|
+
* @param {WebpackOptionsInterception=} interception intercepted options
|
|
93
95
|
* @returns {WebpackOptions} options object
|
|
94
96
|
*/
|
|
95
|
-
process(options, compiler) {
|
|
97
|
+
process(options, compiler, interception) {
|
|
96
98
|
compiler.outputPath = options.output.path;
|
|
97
99
|
compiler.recordsInputPath = options.recordsInputPath || null;
|
|
98
100
|
compiler.recordsOutputPath = options.recordsOutputPath || null;
|
|
@@ -113,11 +115,7 @@ class WebpackOptionsApply extends OptionsApply {
|
|
|
113
115
|
// Some older versions of Node.js don't support all built-in modules via import, only via `require`,
|
|
114
116
|
// but it seems like there shouldn't be a warning here since these versions are rarely used in real applications
|
|
115
117
|
new NodeTargetPlugin(
|
|
116
|
-
options.output.module
|
|
117
|
-
compiler.platform.node === null &&
|
|
118
|
-
compiler.platform.web === null
|
|
119
|
-
? "module-import"
|
|
120
|
-
: "node-commonjs"
|
|
118
|
+
options.output.module ? "module-import" : "node-commonjs"
|
|
121
119
|
).apply(compiler);
|
|
122
120
|
|
|
123
121
|
// Handle external CSS `@import` and `url()`
|
|
@@ -129,8 +127,8 @@ class WebpackOptionsApply extends OptionsApply {
|
|
|
129
127
|
"module",
|
|
130
128
|
({ request, dependencyType, contextInfo }, callback) => {
|
|
131
129
|
if (
|
|
132
|
-
/\.css(
|
|
133
|
-
/^(
|
|
130
|
+
/\.css(?:\?|$)/.test(contextInfo.issuer) &&
|
|
131
|
+
/^(?:\/\/|https?:\/\/|#)/.test(request)
|
|
134
132
|
) {
|
|
135
133
|
if (dependencyType === "url") {
|
|
136
134
|
return callback(null, `asset ${request}`);
|
|
@@ -156,7 +154,7 @@ class WebpackOptionsApply extends OptionsApply {
|
|
|
156
154
|
const ExternalsPlugin = require("./ExternalsPlugin");
|
|
157
155
|
|
|
158
156
|
new ExternalsPlugin(type, ({ request, dependencyType }, callback) => {
|
|
159
|
-
if (/^(
|
|
157
|
+
if (/^(?:\/\/|https?:\/\/|#|std:|jsr:|npm:)/.test(request)) {
|
|
160
158
|
if (dependencyType === "url") {
|
|
161
159
|
return callback(null, `asset ${request}`);
|
|
162
160
|
} else if (
|
|
@@ -166,7 +164,7 @@ class WebpackOptionsApply extends OptionsApply {
|
|
|
166
164
|
options.experiments.css
|
|
167
165
|
) {
|
|
168
166
|
return callback(null, `css-import ${request}`);
|
|
169
|
-
} else if (/^(
|
|
167
|
+
} else if (/^(?:\/\/|https?:\/\/|std:|jsr:|npm:)/.test(request)) {
|
|
170
168
|
return callback(null, `${type} ${request}`);
|
|
171
169
|
}
|
|
172
170
|
}
|
|
@@ -315,37 +313,59 @@ class WebpackOptionsApply extends OptionsApply {
|
|
|
315
313
|
).apply(compiler);
|
|
316
314
|
}
|
|
317
315
|
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
316
|
+
let devtool =
|
|
317
|
+
interception === undefined ? options.devtool : interception.devtool;
|
|
318
|
+
devtool = Array.isArray(devtool)
|
|
319
|
+
? devtool
|
|
320
|
+
: typeof devtool === "string"
|
|
321
|
+
? [{ type: "all", use: devtool }]
|
|
322
|
+
: [];
|
|
323
|
+
|
|
324
|
+
for (const item of devtool) {
|
|
325
|
+
const { type, use } = item;
|
|
326
|
+
|
|
327
|
+
if (use) {
|
|
328
|
+
if (use.includes("source-map")) {
|
|
329
|
+
const hidden = use.includes("hidden");
|
|
330
|
+
const inline = use.includes("inline");
|
|
331
|
+
const evalWrapped = use.includes("eval");
|
|
332
|
+
const cheap = use.includes("cheap");
|
|
333
|
+
const moduleMaps = use.includes("module");
|
|
334
|
+
const noSources = use.includes("nosources");
|
|
335
|
+
const debugIds = use.includes("debugids");
|
|
336
|
+
const Plugin = evalWrapped
|
|
337
|
+
? require("./EvalSourceMapDevToolPlugin")
|
|
338
|
+
: require("./SourceMapDevToolPlugin");
|
|
339
|
+
const assetExt =
|
|
340
|
+
type === "javascript"
|
|
341
|
+
? /\.((c|m)?js)($|\?)/i
|
|
342
|
+
: type === "css"
|
|
343
|
+
? /\.(css)($|\?)/i
|
|
344
|
+
: /\.((c|m)?js|css)($|\?)/i;
|
|
345
|
+
|
|
346
|
+
new Plugin({
|
|
347
|
+
test: evalWrapped ? undefined : assetExt,
|
|
348
|
+
filename: inline ? null : options.output.sourceMapFilename,
|
|
349
|
+
moduleFilenameTemplate:
|
|
350
|
+
options.output.devtoolModuleFilenameTemplate,
|
|
351
|
+
fallbackModuleFilenameTemplate:
|
|
352
|
+
options.output.devtoolFallbackModuleFilenameTemplate,
|
|
353
|
+
append: hidden ? false : undefined,
|
|
354
|
+
module: moduleMaps ? true : !cheap,
|
|
355
|
+
columns: !cheap,
|
|
356
|
+
noSources,
|
|
357
|
+
namespace: options.output.devtoolNamespace,
|
|
358
|
+
debugIds
|
|
359
|
+
}).apply(compiler);
|
|
360
|
+
} else if (use.includes("eval")) {
|
|
361
|
+
const EvalDevToolModulePlugin = require("./EvalDevToolModulePlugin");
|
|
344
362
|
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
363
|
+
new EvalDevToolModulePlugin({
|
|
364
|
+
moduleFilenameTemplate:
|
|
365
|
+
options.output.devtoolModuleFilenameTemplate,
|
|
366
|
+
namespace: options.output.devtoolNamespace
|
|
367
|
+
}).apply(compiler);
|
|
368
|
+
}
|
|
349
369
|
}
|
|
350
370
|
}
|
|
351
371
|
|
|
@@ -60,6 +60,7 @@ class AssetSourceGenerator extends Generator {
|
|
|
60
60
|
runtimeRequirements.add(RuntimeGlobals.requireScope);
|
|
61
61
|
runtimeRequirements.add(RuntimeGlobals.toBinary);
|
|
62
62
|
|
|
63
|
+
/** @type {string} */
|
|
63
64
|
let sourceContent;
|
|
64
65
|
if (concatenationScope) {
|
|
65
66
|
concatenationScope.registerNamespaceExport(
|
|
@@ -62,12 +62,13 @@ const getMimeTypes = memoize(() => require("mime-types"));
|
|
|
62
62
|
* @returns {T[] & U[]} array
|
|
63
63
|
*/
|
|
64
64
|
const mergeMaybeArrays = (a, b) => {
|
|
65
|
+
/** @type {Set<T | U | null | undefined | string | Set<T> | Set<U>>} */
|
|
65
66
|
const set = new Set();
|
|
66
67
|
if (Array.isArray(a)) for (const item of a) set.add(item);
|
|
67
68
|
else set.add(a);
|
|
68
69
|
if (Array.isArray(b)) for (const item of b) set.add(item);
|
|
69
70
|
else set.add(b);
|
|
70
|
-
return [
|
|
71
|
+
return /** @type {T[] & U[]} */ ([.../** @type {Set<T | U>} */ (set)]);
|
|
71
72
|
};
|
|
72
73
|
|
|
73
74
|
/**
|
|
@@ -333,6 +334,7 @@ class AssetGenerator extends Generator {
|
|
|
333
334
|
runtimeTemplate
|
|
334
335
|
);
|
|
335
336
|
|
|
337
|
+
/** @type {undefined | string} */
|
|
336
338
|
let assetPath;
|
|
337
339
|
|
|
338
340
|
if (generatorOptions.publicPath !== undefined && type === JAVASCRIPT_TYPE) {
|
|
@@ -457,6 +459,7 @@ class AssetGenerator extends Generator {
|
|
|
457
459
|
generateDataUri(module) {
|
|
458
460
|
const source = /** @type {Source} */ (module.originalSource());
|
|
459
461
|
|
|
462
|
+
/** @type {string} */
|
|
460
463
|
let encodedSource;
|
|
461
464
|
|
|
462
465
|
if (typeof this.dataUrlOptions === "function") {
|
|
@@ -480,6 +483,7 @@ class AssetGenerator extends Generator {
|
|
|
480
483
|
}
|
|
481
484
|
const mimeType = this.getMimeType(module);
|
|
482
485
|
|
|
486
|
+
/** @type {string} */
|
|
483
487
|
let encodedContent;
|
|
484
488
|
|
|
485
489
|
if (
|
|
@@ -490,7 +494,9 @@ class AssetGenerator extends Generator {
|
|
|
490
494
|
/** @type {string} */ (module.resourceResolveData.encodedContent)
|
|
491
495
|
).equals(source.buffer())
|
|
492
496
|
) {
|
|
493
|
-
encodedContent =
|
|
497
|
+
encodedContent =
|
|
498
|
+
/** @type {string} */
|
|
499
|
+
(module.resourceResolveData.encodedContent);
|
|
494
500
|
} else {
|
|
495
501
|
encodedContent = encodeDataUri(
|
|
496
502
|
/** @type {"base64" | false} */ (encoding),
|
|
@@ -520,10 +526,10 @@ class AssetGenerator extends Generator {
|
|
|
520
526
|
concatenationScope
|
|
521
527
|
} = generateContext;
|
|
522
528
|
|
|
529
|
+
/** @type {string} */
|
|
523
530
|
let content;
|
|
524
531
|
|
|
525
532
|
const needContent = type === JAVASCRIPT_TYPE || type === CSS_URL_TYPE;
|
|
526
|
-
|
|
527
533
|
const data = getData ? getData() : undefined;
|
|
528
534
|
|
|
529
535
|
if (
|
|
@@ -12,17 +12,22 @@ const {
|
|
|
12
12
|
ASSET_MODULE_TYPE_RESOURCE,
|
|
13
13
|
ASSET_MODULE_TYPE_SOURCE
|
|
14
14
|
} = require("../ModuleTypeConstants");
|
|
15
|
-
const {
|
|
15
|
+
const { compareModulesByFullName } = 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
20
|
/** @typedef {import("schema-utils").Schema} Schema */
|
|
21
|
+
/** @typedef {import("../../declarations/WebpackOptions").AssetGeneratorDataUrl} AssetGeneratorDataUrl */
|
|
22
|
+
/** @typedef {import("../../declarations/WebpackOptions").AssetModuleOutputPath} AssetModuleOutputPath */
|
|
23
|
+
/** @typedef {import("../../declarations/WebpackOptions").RawPublicPath} RawPublicPath */
|
|
24
|
+
/** @typedef {import("../../declarations/WebpackOptions").FilenameTemplate} FilenameTemplate */
|
|
21
25
|
/** @typedef {import("../Compilation").AssetInfo} AssetInfo */
|
|
22
26
|
/** @typedef {import("../Compiler")} Compiler */
|
|
23
27
|
/** @typedef {import("../Module").BuildInfo} BuildInfo */
|
|
24
28
|
/** @typedef {import("../Module").CodeGenerationResult} CodeGenerationResult */
|
|
25
29
|
/** @typedef {import("../NormalModule")} NormalModule */
|
|
30
|
+
/** @typedef {import("../NormalModule").NormalModuleCreateData} NormalModuleCreateData */
|
|
26
31
|
|
|
27
32
|
/**
|
|
28
33
|
* @param {string} name name of definitions
|
|
@@ -76,6 +81,7 @@ const getAssetSourceGenerator = memoize(() =>
|
|
|
76
81
|
require("./AssetSourceGenerator")
|
|
77
82
|
);
|
|
78
83
|
const getAssetBytesGenerator = memoize(() => require("./AssetBytesGenerator"));
|
|
84
|
+
const getNormalModule = memoize(() => require("../NormalModule"));
|
|
79
85
|
|
|
80
86
|
const type = ASSET_MODULE_TYPE;
|
|
81
87
|
const PLUGIN_NAME = "AssetModulesPlugin";
|
|
@@ -90,6 +96,27 @@ class AssetModulesPlugin {
|
|
|
90
96
|
compiler.hooks.compilation.tap(
|
|
91
97
|
PLUGIN_NAME,
|
|
92
98
|
(compilation, { normalModuleFactory }) => {
|
|
99
|
+
const NormalModule = getNormalModule();
|
|
100
|
+
for (const type of [
|
|
101
|
+
ASSET_MODULE_TYPE,
|
|
102
|
+
ASSET_MODULE_TYPE_BYTES,
|
|
103
|
+
ASSET_MODULE_TYPE_INLINE,
|
|
104
|
+
ASSET_MODULE_TYPE_RESOURCE,
|
|
105
|
+
ASSET_MODULE_TYPE_SOURCE
|
|
106
|
+
]) {
|
|
107
|
+
normalModuleFactory.hooks.createModuleClass
|
|
108
|
+
.for(type)
|
|
109
|
+
.tap(PLUGIN_NAME, (createData, _resolveData) => {
|
|
110
|
+
// TODO create the module via new AssetModule with its own properties
|
|
111
|
+
const module = new NormalModule(
|
|
112
|
+
/** @type {NormalModuleCreateData} */
|
|
113
|
+
(createData)
|
|
114
|
+
);
|
|
115
|
+
module.factoryMeta = { sideEffectFree: true };
|
|
116
|
+
return module;
|
|
117
|
+
});
|
|
118
|
+
}
|
|
119
|
+
|
|
93
120
|
normalModuleFactory.hooks.createParser
|
|
94
121
|
.for(ASSET_MODULE_TYPE)
|
|
95
122
|
.tap(PLUGIN_NAME, (parserOptions) => {
|
|
@@ -146,6 +173,7 @@ class AssetModulesPlugin {
|
|
|
146
173
|
.tap(PLUGIN_NAME, (generatorOptions) => {
|
|
147
174
|
validateGeneratorOptions[type](generatorOptions);
|
|
148
175
|
|
|
176
|
+
/** @type {undefined | AssetGeneratorDataUrl} */
|
|
149
177
|
let dataUrl;
|
|
150
178
|
if (type !== ASSET_MODULE_TYPE_RESOURCE) {
|
|
151
179
|
dataUrl = generatorOptions.dataUrl;
|
|
@@ -158,8 +186,11 @@ class AssetModulesPlugin {
|
|
|
158
186
|
}
|
|
159
187
|
}
|
|
160
188
|
|
|
189
|
+
/** @type {undefined | FilenameTemplate} */
|
|
161
190
|
let filename;
|
|
191
|
+
/** @type {undefined | RawPublicPath} */
|
|
162
192
|
let publicPath;
|
|
193
|
+
/** @type {undefined | AssetModuleOutputPath} */
|
|
163
194
|
let outputPath;
|
|
164
195
|
if (type !== ASSET_MODULE_TYPE_INLINE) {
|
|
165
196
|
filename = generatorOptions.filename;
|
|
@@ -202,7 +233,7 @@ class AssetModulesPlugin {
|
|
|
202
233
|
const modules = chunkGraph.getOrderedChunkModulesIterableBySourceType(
|
|
203
234
|
chunk,
|
|
204
235
|
ASSET_MODULE_TYPE,
|
|
205
|
-
|
|
236
|
+
compareModulesByFullName(compilation.compiler)
|
|
206
237
|
);
|
|
207
238
|
if (modules) {
|
|
208
239
|
for (const module of modules) {
|
|
@@ -59,6 +59,7 @@ class AssetSourceGenerator extends Generator {
|
|
|
59
59
|
const encodedSource =
|
|
60
60
|
typeof content === "string" ? content : content.toString("utf8");
|
|
61
61
|
|
|
62
|
+
/** @type {string} */
|
|
62
63
|
let sourceContent;
|
|
63
64
|
if (concatenationScope) {
|
|
64
65
|
concatenationScope.registerNamespaceExport(
|