@eriche/webpack 4.47.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/LICENSE +20 -0
- package/README.md +784 -0
- package/SECURITY.md +9 -0
- package/bin/webpack.js +171 -0
- package/buildin/amd-define.js +3 -0
- package/buildin/amd-options.js +2 -0
- package/buildin/global.js +20 -0
- package/buildin/harmony-module.js +24 -0
- package/buildin/module.js +22 -0
- package/buildin/system.js +7 -0
- package/declarations/WebpackOptions.d.ts +1466 -0
- package/declarations/plugins/BannerPlugin.d.ts +49 -0
- package/declarations/plugins/DllPlugin.d.ts +32 -0
- package/declarations/plugins/DllReferencePlugin.d.ts +126 -0
- package/declarations/plugins/HashedModuleIdsPlugin.d.ts +24 -0
- package/declarations/plugins/IgnorePlugin.d.ts +27 -0
- package/declarations/plugins/LoaderOptionsPlugin.d.ts +27 -0
- package/declarations/plugins/ProgressPlugin.d.ts +42 -0
- package/declarations/plugins/SourceMapDevToolPlugin.d.ts +94 -0
- package/declarations/plugins/WatchIgnorePlugin.d.ts +10 -0
- package/declarations/plugins/debug/ProfilingPlugin.d.ts +12 -0
- package/declarations/plugins/optimize/AggressiveSplittingPlugin.d.ts +24 -0
- package/declarations/plugins/optimize/LimitChunkCountPlugin.d.ts +16 -0
- package/declarations/plugins/optimize/MinChunkSizePlugin.d.ts +12 -0
- package/declarations/plugins/optimize/OccurrenceOrderChunkIdsPlugin.d.ts +12 -0
- package/declarations/plugins/optimize/OccurrenceOrderModuleIdsPlugin.d.ts +12 -0
- package/hot/dev-server.js +61 -0
- package/hot/emitter.js +2 -0
- package/hot/log-apply-result.js +44 -0
- package/hot/log.js +59 -0
- package/hot/only-dev-server.js +102 -0
- package/hot/poll.js +37 -0
- package/hot/signal.js +62 -0
- package/lib/APIPlugin.js +84 -0
- package/lib/AbstractMethodError.js +43 -0
- package/lib/AmdMainTemplatePlugin.js +106 -0
- package/lib/AsyncDependenciesBlock.js +110 -0
- package/lib/AsyncDependencyToInitialChunkError.js +31 -0
- package/lib/AutomaticPrefetchPlugin.js +57 -0
- package/lib/BannerPlugin.js +122 -0
- package/lib/BasicEvaluatedExpression.js +248 -0
- package/lib/CachePlugin.js +100 -0
- package/lib/CaseSensitiveModulesWarning.js +67 -0
- package/lib/Chunk.js +875 -0
- package/lib/ChunkGroup.js +513 -0
- package/lib/ChunkRenderError.js +32 -0
- package/lib/ChunkTemplate.js +87 -0
- package/lib/CommentCompilationWarning.js +32 -0
- package/lib/CommonJsStuffPlugin.js +116 -0
- package/lib/CompatibilityPlugin.js +70 -0
- package/lib/Compilation.js +2327 -0
- package/lib/Compiler.js +735 -0
- package/lib/ConcurrentCompilationError.js +19 -0
- package/lib/ConstPlugin.js +348 -0
- package/lib/ContextExclusionPlugin.js +28 -0
- package/lib/ContextModule.js +872 -0
- package/lib/ContextModuleFactory.js +262 -0
- package/lib/ContextReplacementPlugin.js +133 -0
- package/lib/DefinePlugin.js +289 -0
- package/lib/DelegatedModule.js +114 -0
- package/lib/DelegatedModuleFactoryPlugin.js +95 -0
- package/lib/DelegatedPlugin.js +39 -0
- package/lib/DependenciesBlock.js +124 -0
- package/lib/DependenciesBlockVariable.js +72 -0
- package/lib/Dependency.js +89 -0
- package/lib/DllEntryPlugin.js +54 -0
- package/lib/DllModule.js +60 -0
- package/lib/DllModuleFactory.js +29 -0
- package/lib/DllPlugin.js +49 -0
- package/lib/DllReferencePlugin.js +156 -0
- package/lib/DynamicEntryPlugin.js +94 -0
- package/lib/EntryModuleNotFoundError.js +21 -0
- package/lib/EntryOptionPlugin.js +46 -0
- package/lib/Entrypoint.js +64 -0
- package/lib/EnvironmentPlugin.js +72 -0
- package/lib/ErrorHelpers.js +60 -0
- package/lib/EvalDevToolModulePlugin.js +27 -0
- package/lib/EvalDevToolModuleTemplatePlugin.js +61 -0
- package/lib/EvalSourceMapDevToolModuleTemplatePlugin.js +120 -0
- package/lib/EvalSourceMapDevToolPlugin.js +41 -0
- package/lib/ExportPropertyMainTemplatePlugin.js +53 -0
- package/lib/ExtendedAPIPlugin.js +88 -0
- package/lib/ExternalModule.js +179 -0
- package/lib/ExternalModuleFactoryPlugin.js +110 -0
- package/lib/ExternalsPlugin.js +23 -0
- package/lib/FlagAllModulesAsUsedPlugin.js +38 -0
- package/lib/FlagDependencyExportsPlugin.js +174 -0
- package/lib/FlagDependencyUsagePlugin.js +116 -0
- package/lib/FlagInitialModulesAsUsedPlugin.js +36 -0
- package/lib/FunctionModulePlugin.js +19 -0
- package/lib/FunctionModuleTemplatePlugin.js +102 -0
- package/lib/Generator.js +60 -0
- package/lib/GraphHelpers.js +65 -0
- package/lib/HarmonyLinkingError.js +17 -0
- package/lib/HashedModuleIdsPlugin.js +63 -0
- package/lib/HotModuleReplacement.runtime.js +721 -0
- package/lib/HotModuleReplacementPlugin.js +425 -0
- package/lib/HotUpdateChunk.js +17 -0
- package/lib/HotUpdateChunkTemplate.js +78 -0
- package/lib/IgnorePlugin.js +91 -0
- package/lib/JavascriptGenerator.js +229 -0
- package/lib/JavascriptModulesPlugin.js +185 -0
- package/lib/JsonGenerator.js +57 -0
- package/lib/JsonModulesPlugin.js +30 -0
- package/lib/JsonParser.js +27 -0
- package/lib/LibManifestPlugin.js +90 -0
- package/lib/LibraryTemplatePlugin.js +186 -0
- package/lib/LoaderOptionsPlugin.js +58 -0
- package/lib/LoaderTargetPlugin.js +24 -0
- package/lib/MainTemplate.js +568 -0
- package/lib/MemoryOutputFileSystem.js +5 -0
- package/lib/Module.js +435 -0
- package/lib/ModuleBuildError.js +52 -0
- package/lib/ModuleDependencyError.js +35 -0
- package/lib/ModuleDependencyWarning.js +25 -0
- package/lib/ModuleError.js +36 -0
- package/lib/ModuleFilenameHelpers.js +179 -0
- package/lib/ModuleNotFoundError.js +23 -0
- package/lib/ModuleParseError.js +67 -0
- package/lib/ModuleReason.js +48 -0
- package/lib/ModuleTemplate.js +93 -0
- package/lib/ModuleWarning.js +36 -0
- package/lib/MultiCompiler.js +290 -0
- package/lib/MultiEntryPlugin.js +80 -0
- package/lib/MultiModule.js +87 -0
- package/lib/MultiModuleFactory.js +23 -0
- package/lib/MultiStats.js +92 -0
- package/lib/MultiWatching.js +50 -0
- package/lib/NamedChunksPlugin.js +29 -0
- package/lib/NamedModulesPlugin.js +58 -0
- package/lib/NoEmitOnErrorsPlugin.js +20 -0
- package/lib/NoModeWarning.js +23 -0
- package/lib/NodeStuffPlugin.js +118 -0
- package/lib/NormalModule.js +582 -0
- package/lib/NormalModuleFactory.js +528 -0
- package/lib/NormalModuleReplacementPlugin.js +51 -0
- package/lib/NullFactory.js +12 -0
- package/lib/OptionsApply.js +10 -0
- package/lib/OptionsDefaulter.js +141 -0
- package/lib/Parser.js +2454 -0
- package/lib/ParserHelpers.js +103 -0
- package/lib/PrefetchPlugin.js +37 -0
- package/lib/ProgressPlugin.js +307 -0
- package/lib/ProvidePlugin.js +86 -0
- package/lib/RawModule.js +56 -0
- package/lib/RecordIdsPlugin.js +236 -0
- package/lib/RemovedPluginError.js +11 -0
- package/lib/RequestShortener.js +83 -0
- package/lib/RequireJsStuffPlugin.js +66 -0
- package/lib/ResolverFactory.js +74 -0
- package/lib/RuleSet.js +567 -0
- package/lib/RuntimeTemplate.js +336 -0
- package/lib/SetVarMainTemplatePlugin.js +69 -0
- package/lib/SingleEntryPlugin.js +63 -0
- package/lib/SizeFormatHelpers.js +24 -0
- package/lib/SourceMapDevToolModuleOptionsPlugin.js +49 -0
- package/lib/SourceMapDevToolPlugin.js +418 -0
- package/lib/Stats.js +1685 -0
- package/lib/SystemMainTemplatePlugin.js +137 -0
- package/lib/Template.js +291 -0
- package/lib/TemplatedPathPlugin.js +188 -0
- package/lib/UmdMainTemplatePlugin.js +305 -0
- package/lib/UnsupportedFeatureWarning.js +30 -0
- package/lib/UseStrictPlugin.js +54 -0
- package/lib/WarnCaseSensitiveModulesPlugin.js +37 -0
- package/lib/WarnNoModeSetPlugin.js +17 -0
- package/lib/WatchIgnorePlugin.js +106 -0
- package/lib/Watching.js +211 -0
- package/lib/WebpackError.js +31 -0
- package/lib/WebpackOptionsApply.js +546 -0
- package/lib/WebpackOptionsDefaulter.js +391 -0
- package/lib/WebpackOptionsValidationError.js +390 -0
- package/lib/buildChunkGraph.js +712 -0
- package/lib/compareLocations.js +52 -0
- package/lib/debug/ProfilingPlugin.js +442 -0
- package/lib/dependencies/AMDDefineDependency.js +137 -0
- package/lib/dependencies/AMDDefineDependencyParserPlugin.js +336 -0
- package/lib/dependencies/AMDPlugin.js +249 -0
- package/lib/dependencies/AMDRequireArrayDependency.js +49 -0
- package/lib/dependencies/AMDRequireContextDependency.js +20 -0
- package/lib/dependencies/AMDRequireDependenciesBlock.js +47 -0
- package/lib/dependencies/AMDRequireDependenciesBlockParserPlugin.js +274 -0
- package/lib/dependencies/AMDRequireDependency.js +135 -0
- package/lib/dependencies/AMDRequireItemDependency.js +22 -0
- package/lib/dependencies/CommonJsPlugin.js +158 -0
- package/lib/dependencies/CommonJsRequireContextDependency.js +23 -0
- package/lib/dependencies/CommonJsRequireDependency.js +22 -0
- package/lib/dependencies/CommonJsRequireDependencyParserPlugin.js +138 -0
- package/lib/dependencies/ConstDependency.js +33 -0
- package/lib/dependencies/ContextDependency.js +68 -0
- package/lib/dependencies/ContextDependencyHelpers.js +232 -0
- package/lib/dependencies/ContextDependencyTemplateAsId.js +43 -0
- package/lib/dependencies/ContextDependencyTemplateAsRequireCall.js +39 -0
- package/lib/dependencies/ContextElementDependency.js +21 -0
- package/lib/dependencies/CriticalDependencyWarning.js +20 -0
- package/lib/dependencies/DelegatedExportsDependency.js +33 -0
- package/lib/dependencies/DelegatedSourceDependency.js +18 -0
- package/lib/dependencies/DependencyReference.js +64 -0
- package/lib/dependencies/DllEntryDependency.js +20 -0
- package/lib/dependencies/HarmonyAcceptDependency.js +48 -0
- package/lib/dependencies/HarmonyAcceptImportDependency.js +23 -0
- package/lib/dependencies/HarmonyCompatibilityDependency.js +31 -0
- package/lib/dependencies/HarmonyDetectionParserPlugin.js +96 -0
- package/lib/dependencies/HarmonyExportDependencyParserPlugin.js +154 -0
- package/lib/dependencies/HarmonyExportExpressionDependency.js +58 -0
- package/lib/dependencies/HarmonyExportHeaderDependency.js +30 -0
- package/lib/dependencies/HarmonyExportImportedSpecifierDependency.js +659 -0
- package/lib/dependencies/HarmonyExportSpecifierDependency.js +54 -0
- package/lib/dependencies/HarmonyImportDependency.js +109 -0
- package/lib/dependencies/HarmonyImportDependencyParserPlugin.js +222 -0
- package/lib/dependencies/HarmonyImportSideEffectDependency.js +31 -0
- package/lib/dependencies/HarmonyImportSpecifierDependency.js +163 -0
- package/lib/dependencies/HarmonyInitDependency.js +60 -0
- package/lib/dependencies/HarmonyModulesPlugin.js +143 -0
- package/lib/dependencies/HarmonyTopLevelThisParserPlugin.js +26 -0
- package/lib/dependencies/ImportContextDependency.js +23 -0
- package/lib/dependencies/ImportDependenciesBlock.js +18 -0
- package/lib/dependencies/ImportDependency.js +34 -0
- package/lib/dependencies/ImportEagerDependency.js +32 -0
- package/lib/dependencies/ImportParserPlugin.js +248 -0
- package/lib/dependencies/ImportPlugin.js +79 -0
- package/lib/dependencies/ImportWeakDependency.js +34 -0
- package/lib/dependencies/JsonExportsDependency.js +26 -0
- package/lib/dependencies/LoaderDependency.js +21 -0
- package/lib/dependencies/LoaderPlugin.js +115 -0
- package/lib/dependencies/LocalModule.js +23 -0
- package/lib/dependencies/LocalModuleDependency.js +28 -0
- package/lib/dependencies/LocalModulesHelpers.js +52 -0
- package/lib/dependencies/ModuleDependency.js +23 -0
- package/lib/dependencies/ModuleDependencyTemplateAsId.js +17 -0
- package/lib/dependencies/ModuleDependencyTemplateAsRequireId.js +17 -0
- package/lib/dependencies/ModuleHotAcceptDependency.js +23 -0
- package/lib/dependencies/ModuleHotDeclineDependency.js +23 -0
- package/lib/dependencies/MultiEntryDependency.js +25 -0
- package/lib/dependencies/NullDependency.js +20 -0
- package/lib/dependencies/PrefetchDependency.js +18 -0
- package/lib/dependencies/RequireContextDependency.js +22 -0
- package/lib/dependencies/RequireContextDependencyParserPlugin.js +56 -0
- package/lib/dependencies/RequireContextPlugin.js +143 -0
- package/lib/dependencies/RequireEnsureDependenciesBlock.js +33 -0
- package/lib/dependencies/RequireEnsureDependenciesBlockParserPlugin.js +116 -0
- package/lib/dependencies/RequireEnsureDependency.js +58 -0
- package/lib/dependencies/RequireEnsureItemDependency.js +21 -0
- package/lib/dependencies/RequireEnsurePlugin.js +74 -0
- package/lib/dependencies/RequireHeaderDependency.js +26 -0
- package/lib/dependencies/RequireIncludeDependency.js +39 -0
- package/lib/dependencies/RequireIncludeDependencyParserPlugin.js +23 -0
- package/lib/dependencies/RequireIncludePlugin.js +61 -0
- package/lib/dependencies/RequireResolveContextDependency.js +23 -0
- package/lib/dependencies/RequireResolveDependency.js +22 -0
- package/lib/dependencies/RequireResolveDependencyParserPlugin.js +86 -0
- package/lib/dependencies/RequireResolveHeaderDependency.js +26 -0
- package/lib/dependencies/SingleEntryDependency.js +21 -0
- package/lib/dependencies/SystemPlugin.js +122 -0
- package/lib/dependencies/UnsupportedDependency.js +27 -0
- package/lib/dependencies/WebAssemblyExportImportedDependency.js +31 -0
- package/lib/dependencies/WebAssemblyImportDependency.js +54 -0
- package/lib/dependencies/WebpackMissingModule.js +20 -0
- package/lib/dependencies/getFunctionExpression.js +52 -0
- package/lib/formatLocation.js +75 -0
- package/lib/logging/Logger.js +128 -0
- package/lib/logging/createConsoleLogger.js +210 -0
- package/lib/logging/runtime.js +36 -0
- package/lib/logging/truncateArgs.js +76 -0
- package/lib/node/NodeChunkTemplatePlugin.js +31 -0
- package/lib/node/NodeEnvironmentPlugin.js +44 -0
- package/lib/node/NodeHotUpdateChunkTemplatePlugin.js +36 -0
- package/lib/node/NodeMainTemplate.runtime.js +32 -0
- package/lib/node/NodeMainTemplateAsync.runtime.js +50 -0
- package/lib/node/NodeMainTemplatePlugin.js +321 -0
- package/lib/node/NodeOutputFileSystem.js +22 -0
- package/lib/node/NodeSourcePlugin.js +141 -0
- package/lib/node/NodeTargetPlugin.js +19 -0
- package/lib/node/NodeTemplatePlugin.js +31 -0
- package/lib/node/NodeWatchFileSystem.js +109 -0
- package/lib/node/ReadFileCompileWasmTemplatePlugin.js +61 -0
- package/lib/node/nodeConsole.js +135 -0
- package/lib/optimize/AggressiveMergingPlugin.js +87 -0
- package/lib/optimize/AggressiveSplittingPlugin.js +294 -0
- package/lib/optimize/ChunkModuleIdRangePlugin.js +66 -0
- package/lib/optimize/ConcatenatedModule.js +1477 -0
- package/lib/optimize/EnsureChunkConditionsPlugin.js +70 -0
- package/lib/optimize/FlagIncludedChunksPlugin.js +99 -0
- package/lib/optimize/LimitChunkCountPlugin.js +231 -0
- package/lib/optimize/MergeDuplicateChunksPlugin.js +78 -0
- package/lib/optimize/MinChunkSizePlugin.js +82 -0
- package/lib/optimize/MinMaxSizeWarning.js +29 -0
- package/lib/optimize/ModuleConcatenationPlugin.js +485 -0
- package/lib/optimize/NaturalChunkOrderPlugin.js +41 -0
- package/lib/optimize/OccurrenceChunkOrderPlugin.js +66 -0
- package/lib/optimize/OccurrenceModuleOrderPlugin.js +112 -0
- package/lib/optimize/OccurrenceOrderPlugin.js +135 -0
- package/lib/optimize/RemoveEmptyChunksPlugin.js +42 -0
- package/lib/optimize/RemoveParentModulesPlugin.js +127 -0
- package/lib/optimize/RuntimeChunkPlugin.js +41 -0
- package/lib/optimize/SideEffectsFlagPlugin.js +352 -0
- package/lib/optimize/SplitChunksPlugin.js +971 -0
- package/lib/performance/AssetsOverSizeLimitWarning.js +30 -0
- package/lib/performance/EntrypointsOverSizeLimitWarning.js +30 -0
- package/lib/performance/NoAsyncChunksWarning.js +21 -0
- package/lib/performance/SizeLimitsPlugin.js +125 -0
- package/lib/util/LazyBucketSortedSet.js +235 -0
- package/lib/util/Queue.js +46 -0
- package/lib/util/Semaphore.js +53 -0
- package/lib/util/SetHelpers.js +48 -0
- package/lib/util/SortableSet.js +140 -0
- package/lib/util/StackedSetMap.js +142 -0
- package/lib/util/TrackingSet.js +35 -0
- package/lib/util/cachedMerge.js +35 -0
- package/lib/util/cleverMerge.js +77 -0
- package/lib/util/createHash.js +174 -0
- package/lib/util/deterministicGrouping.js +274 -0
- package/lib/util/hash/BatchedHash.js +71 -0
- package/lib/util/hash/md4.js +25 -0
- package/lib/util/hash/wasm-hash.js +174 -0
- package/lib/util/identifier.js +127 -0
- package/lib/util/objectToMap.js +16 -0
- package/lib/validateSchema.js +67 -0
- package/lib/wasm/UnsupportedWebAssemblyFeatureError.js +17 -0
- package/lib/wasm/WasmFinalizeExportsPlugin.js +69 -0
- package/lib/wasm/WasmMainTemplatePlugin.js +341 -0
- package/lib/wasm/WebAssemblyGenerator.js +458 -0
- package/lib/wasm/WebAssemblyInInitialChunkError.js +88 -0
- package/lib/wasm/WebAssemblyJavascriptGenerator.js +152 -0
- package/lib/wasm/WebAssemblyModulesPlugin.js +128 -0
- package/lib/wasm/WebAssemblyParser.js +175 -0
- package/lib/wasm/WebAssemblyUtils.js +59 -0
- package/lib/web/FetchCompileWasmTemplatePlugin.js +37 -0
- package/lib/web/JsonpChunkTemplatePlugin.js +71 -0
- package/lib/web/JsonpExportMainTemplatePlugin.js +50 -0
- package/lib/web/JsonpHotUpdateChunkTemplatePlugin.js +39 -0
- package/lib/web/JsonpMainTemplate.runtime.js +71 -0
- package/lib/web/JsonpMainTemplatePlugin.js +615 -0
- package/lib/web/JsonpTemplatePlugin.js +23 -0
- package/lib/web/WebEnvironmentPlugin.js +18 -0
- package/lib/webpack.js +206 -0
- package/lib/webpack.web.js +31 -0
- package/lib/webworker/WebWorkerChunkTemplatePlugin.js +35 -0
- package/lib/webworker/WebWorkerHotUpdateChunkTemplatePlugin.js +40 -0
- package/lib/webworker/WebWorkerMainTemplate.runtime.js +73 -0
- package/lib/webworker/WebWorkerMainTemplatePlugin.js +192 -0
- package/lib/webworker/WebWorkerTemplatePlugin.js +25 -0
- package/package.json +211 -0
- package/schemas/WebpackOptions.json +2285 -0
- package/schemas/ajv.absolutePath.js +57 -0
- package/schemas/plugins/BannerPlugin.json +101 -0
- package/schemas/plugins/DllPlugin.json +36 -0
- package/schemas/plugins/DllReferencePlugin.json +205 -0
- package/schemas/plugins/HashedModuleIdsPlugin.json +26 -0
- package/schemas/plugins/IgnorePlugin.json +37 -0
- package/schemas/plugins/LoaderOptionsPlugin.json +27 -0
- package/schemas/plugins/ProgressPlugin.json +52 -0
- package/schemas/plugins/SourceMapDevToolPlugin.json +185 -0
- package/schemas/plugins/WatchIgnorePlugin.json +18 -0
- package/schemas/plugins/debug/ProfilingPlugin.json +13 -0
- package/schemas/plugins/optimize/AggressiveSplittingPlugin.json +23 -0
- package/schemas/plugins/optimize/LimitChunkCountPlugin.json +16 -0
- package/schemas/plugins/optimize/MinChunkSizePlugin.json +12 -0
- package/schemas/plugins/optimize/OccurrenceOrderChunkIdsPlugin.json +11 -0
- package/schemas/plugins/optimize/OccurrenceOrderModuleIdsPlugin.json +11 -0
- package/web_modules/node-libs-browser.js +0 -0
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
/*
|
|
2
|
+
MIT License http://www.opensource.org/licenses/mit-license.php
|
|
3
|
+
Author Joel Denning @joeldenning
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
"use strict";
|
|
7
|
+
|
|
8
|
+
const { ConcatSource } = require("webpack-sources");
|
|
9
|
+
const Template = require("./Template");
|
|
10
|
+
|
|
11
|
+
/** @typedef {import("./Compilation")} Compilation */
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* @typedef {Object} SystemMainTemplatePluginOptions
|
|
15
|
+
* @param {string=} name the library name
|
|
16
|
+
*/
|
|
17
|
+
|
|
18
|
+
class SystemMainTemplatePlugin {
|
|
19
|
+
/**
|
|
20
|
+
* @param {SystemMainTemplatePluginOptions} options the plugin options
|
|
21
|
+
*/
|
|
22
|
+
constructor(options) {
|
|
23
|
+
this.name = options.name;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* @param {Compilation} compilation the compilation instance
|
|
28
|
+
* @returns {void}
|
|
29
|
+
*/
|
|
30
|
+
apply(compilation) {
|
|
31
|
+
const { mainTemplate, chunkTemplate } = compilation;
|
|
32
|
+
|
|
33
|
+
const onRenderWithEntry = (source, chunk, hash) => {
|
|
34
|
+
const externals = chunk
|
|
35
|
+
.getModules()
|
|
36
|
+
.filter(m => m.external && m.externalType === "system");
|
|
37
|
+
|
|
38
|
+
// The name this bundle should be registered as with System
|
|
39
|
+
const name = this.name
|
|
40
|
+
? `${JSON.stringify(
|
|
41
|
+
mainTemplate.getAssetPath(this.name, { hash, chunk })
|
|
42
|
+
)}, `
|
|
43
|
+
: "";
|
|
44
|
+
|
|
45
|
+
// The array of dependencies that are external to webpack and will be provided by System
|
|
46
|
+
const systemDependencies = JSON.stringify(
|
|
47
|
+
externals.map(m =>
|
|
48
|
+
typeof m.request === "object" ? m.request.amd : m.request
|
|
49
|
+
)
|
|
50
|
+
);
|
|
51
|
+
|
|
52
|
+
// The name of the variable provided by System for exporting
|
|
53
|
+
const dynamicExport = "__WEBPACK_DYNAMIC_EXPORT__";
|
|
54
|
+
|
|
55
|
+
// An array of the internal variable names for the webpack externals
|
|
56
|
+
const externalWebpackNames = externals.map(
|
|
57
|
+
m => `__WEBPACK_EXTERNAL_MODULE_${Template.toIdentifier(`${m.id}`)}__`
|
|
58
|
+
);
|
|
59
|
+
|
|
60
|
+
// Declaring variables for the internal variable names for the webpack externals
|
|
61
|
+
const externalVarDeclarations =
|
|
62
|
+
externalWebpackNames.length > 0
|
|
63
|
+
? `var ${externalWebpackNames.join(", ")};`
|
|
64
|
+
: "";
|
|
65
|
+
|
|
66
|
+
// The system.register format requires an array of setter functions for externals.
|
|
67
|
+
const setters =
|
|
68
|
+
externalWebpackNames.length === 0
|
|
69
|
+
? ""
|
|
70
|
+
: Template.asString([
|
|
71
|
+
"setters: [",
|
|
72
|
+
Template.indent(
|
|
73
|
+
externalWebpackNames
|
|
74
|
+
.map(external =>
|
|
75
|
+
Template.asString([
|
|
76
|
+
"function(module) {",
|
|
77
|
+
Template.indent(`${external} = module;`),
|
|
78
|
+
"}"
|
|
79
|
+
])
|
|
80
|
+
)
|
|
81
|
+
.join(",\n")
|
|
82
|
+
),
|
|
83
|
+
"],"
|
|
84
|
+
]);
|
|
85
|
+
|
|
86
|
+
return new ConcatSource(
|
|
87
|
+
Template.asString([
|
|
88
|
+
`System.register(${name}${systemDependencies}, function(${dynamicExport}) {`,
|
|
89
|
+
Template.indent([
|
|
90
|
+
externalVarDeclarations,
|
|
91
|
+
"return {",
|
|
92
|
+
Template.indent([
|
|
93
|
+
setters,
|
|
94
|
+
"execute: function() {",
|
|
95
|
+
Template.indent(`${dynamicExport}(`)
|
|
96
|
+
])
|
|
97
|
+
])
|
|
98
|
+
]) + "\n",
|
|
99
|
+
source,
|
|
100
|
+
"\n" +
|
|
101
|
+
Template.asString([
|
|
102
|
+
Template.indent([
|
|
103
|
+
Template.indent([Template.indent([");"]), "}"]),
|
|
104
|
+
"};"
|
|
105
|
+
]),
|
|
106
|
+
"})"
|
|
107
|
+
])
|
|
108
|
+
);
|
|
109
|
+
};
|
|
110
|
+
|
|
111
|
+
for (const template of [mainTemplate, chunkTemplate]) {
|
|
112
|
+
template.hooks.renderWithEntry.tap(
|
|
113
|
+
"SystemMainTemplatePlugin",
|
|
114
|
+
onRenderWithEntry
|
|
115
|
+
);
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
mainTemplate.hooks.globalHashPaths.tap(
|
|
119
|
+
"SystemMainTemplatePlugin",
|
|
120
|
+
paths => {
|
|
121
|
+
if (this.name) {
|
|
122
|
+
paths.push(this.name);
|
|
123
|
+
}
|
|
124
|
+
return paths;
|
|
125
|
+
}
|
|
126
|
+
);
|
|
127
|
+
|
|
128
|
+
mainTemplate.hooks.hash.tap("SystemMainTemplatePlugin", hash => {
|
|
129
|
+
hash.update("exports system");
|
|
130
|
+
if (this.name) {
|
|
131
|
+
hash.update(this.name);
|
|
132
|
+
}
|
|
133
|
+
});
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
module.exports = SystemMainTemplatePlugin;
|
package/lib/Template.js
ADDED
|
@@ -0,0 +1,291 @@
|
|
|
1
|
+
/*
|
|
2
|
+
MIT License http://www.opensource.org/licenses/mit-license.php
|
|
3
|
+
Author Tobias Koppers @sokra
|
|
4
|
+
*/
|
|
5
|
+
/** @typedef {import("./Module")} Module */
|
|
6
|
+
/** @typedef {import("./Chunk")} Chunk */
|
|
7
|
+
/** @typedef {import("./ModuleTemplate")} ModuleTemplate */
|
|
8
|
+
/** @typedef {import("webpack-sources").ConcatSource} ConcatSource */
|
|
9
|
+
|
|
10
|
+
const { ConcatSource } = require("webpack-sources");
|
|
11
|
+
const HotUpdateChunk = require("./HotUpdateChunk");
|
|
12
|
+
|
|
13
|
+
const START_LOWERCASE_ALPHABET_CODE = "a".charCodeAt(0);
|
|
14
|
+
const START_UPPERCASE_ALPHABET_CODE = "A".charCodeAt(0);
|
|
15
|
+
const DELTA_A_TO_Z = "z".charCodeAt(0) - START_LOWERCASE_ALPHABET_CODE + 1;
|
|
16
|
+
const FUNCTION_CONTENT_REGEX = /^function\s?\(\)\s?\{\r?\n?|\r?\n?\}$/g;
|
|
17
|
+
const INDENT_MULTILINE_REGEX = /^\t/gm;
|
|
18
|
+
const LINE_SEPARATOR_REGEX = /\r?\n/g;
|
|
19
|
+
const IDENTIFIER_NAME_REPLACE_REGEX = /^([^a-zA-Z$_])/;
|
|
20
|
+
const IDENTIFIER_ALPHA_NUMERIC_NAME_REPLACE_REGEX = /[^a-zA-Z0-9$]+/g;
|
|
21
|
+
const COMMENT_END_REGEX = /\*\//g;
|
|
22
|
+
const PATH_NAME_NORMALIZE_REPLACE_REGEX = /[^a-zA-Z0-9_!§$()=\-^°]+/g;
|
|
23
|
+
const MATCH_PADDED_HYPHENS_REPLACE_REGEX = /^-|-$/g;
|
|
24
|
+
|
|
25
|
+
/** @typedef {import("webpack-sources").Source} Source */
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* @typedef {Object} HasId
|
|
29
|
+
* @property {number | string} id
|
|
30
|
+
*/
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* @typedef {function(Module, number): boolean} ModuleFilterPredicate
|
|
34
|
+
*/
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* @param {HasId} a first id object to be sorted
|
|
38
|
+
* @param {HasId} b second id object to be sorted against
|
|
39
|
+
* @returns {-1|0|1} the sort value
|
|
40
|
+
*/
|
|
41
|
+
const stringifyIdSortPredicate = (a, b) => {
|
|
42
|
+
const aId = a.id + "";
|
|
43
|
+
const bId = b.id + "";
|
|
44
|
+
if (aId < bId) return -1;
|
|
45
|
+
if (aId > bId) return 1;
|
|
46
|
+
return 0;
|
|
47
|
+
};
|
|
48
|
+
|
|
49
|
+
class Template {
|
|
50
|
+
/**
|
|
51
|
+
*
|
|
52
|
+
* @param {Function} fn a runtime function (.runtime.js) "template"
|
|
53
|
+
* @returns {string} the updated and normalized function string
|
|
54
|
+
*/
|
|
55
|
+
static getFunctionContent(fn) {
|
|
56
|
+
return fn
|
|
57
|
+
.toString()
|
|
58
|
+
.replace(FUNCTION_CONTENT_REGEX, "")
|
|
59
|
+
.replace(INDENT_MULTILINE_REGEX, "")
|
|
60
|
+
.replace(LINE_SEPARATOR_REGEX, "\n");
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
/**
|
|
64
|
+
* @param {string} str the string converted to identifier
|
|
65
|
+
* @returns {string} created identifier
|
|
66
|
+
*/
|
|
67
|
+
static toIdentifier(str) {
|
|
68
|
+
if (typeof str !== "string") return "";
|
|
69
|
+
return str
|
|
70
|
+
.replace(IDENTIFIER_NAME_REPLACE_REGEX, "_$1")
|
|
71
|
+
.replace(IDENTIFIER_ALPHA_NUMERIC_NAME_REPLACE_REGEX, "_");
|
|
72
|
+
}
|
|
73
|
+
/**
|
|
74
|
+
*
|
|
75
|
+
* @param {string} str string to be converted to commented in bundle code
|
|
76
|
+
* @returns {string} returns a commented version of string
|
|
77
|
+
*/
|
|
78
|
+
static toComment(str) {
|
|
79
|
+
if (!str) return "";
|
|
80
|
+
return `/*! ${str.replace(COMMENT_END_REGEX, "* /")} */`;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
/**
|
|
84
|
+
*
|
|
85
|
+
* @param {string} str string to be converted to "normal comment"
|
|
86
|
+
* @returns {string} returns a commented version of string
|
|
87
|
+
*/
|
|
88
|
+
static toNormalComment(str) {
|
|
89
|
+
if (!str) return "";
|
|
90
|
+
return `/* ${str.replace(COMMENT_END_REGEX, "* /")} */`;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
/**
|
|
94
|
+
* @param {string} str string path to be normalized
|
|
95
|
+
* @returns {string} normalized bundle-safe path
|
|
96
|
+
*/
|
|
97
|
+
static toPath(str) {
|
|
98
|
+
if (typeof str !== "string") return "";
|
|
99
|
+
return str
|
|
100
|
+
.replace(PATH_NAME_NORMALIZE_REPLACE_REGEX, "-")
|
|
101
|
+
.replace(MATCH_PADDED_HYPHENS_REPLACE_REGEX, "");
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
// map number to a single character a-z, A-Z or <_ + number> if number is too big
|
|
105
|
+
/**
|
|
106
|
+
*
|
|
107
|
+
* @param {number} n number to convert to ident
|
|
108
|
+
* @returns {string} returns single character ident
|
|
109
|
+
*/
|
|
110
|
+
static numberToIdentifer(n) {
|
|
111
|
+
// lower case
|
|
112
|
+
if (n < DELTA_A_TO_Z) {
|
|
113
|
+
return String.fromCharCode(START_LOWERCASE_ALPHABET_CODE + n);
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
// upper case
|
|
117
|
+
if (n < DELTA_A_TO_Z * 2) {
|
|
118
|
+
return String.fromCharCode(
|
|
119
|
+
START_UPPERCASE_ALPHABET_CODE + n - DELTA_A_TO_Z
|
|
120
|
+
);
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
// use multiple letters
|
|
124
|
+
return (
|
|
125
|
+
Template.numberToIdentifer(n % (2 * DELTA_A_TO_Z)) +
|
|
126
|
+
Template.numberToIdentifer(Math.floor(n / (2 * DELTA_A_TO_Z)))
|
|
127
|
+
);
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
/**
|
|
131
|
+
*
|
|
132
|
+
* @param {string | string[]} s string to convert to identity
|
|
133
|
+
* @returns {string} converted identity
|
|
134
|
+
*/
|
|
135
|
+
static indent(s) {
|
|
136
|
+
if (Array.isArray(s)) {
|
|
137
|
+
return s.map(Template.indent).join("\n");
|
|
138
|
+
} else {
|
|
139
|
+
const str = s.trimRight();
|
|
140
|
+
if (!str) return "";
|
|
141
|
+
const ind = str[0] === "\n" ? "" : "\t";
|
|
142
|
+
return ind + str.replace(/\n([^\n])/g, "\n\t$1");
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
/**
|
|
147
|
+
*
|
|
148
|
+
* @param {string|string[]} s string to create prefix for
|
|
149
|
+
* @param {string} prefix prefix to compose
|
|
150
|
+
* @returns {string} returns new prefix string
|
|
151
|
+
*/
|
|
152
|
+
static prefix(s, prefix) {
|
|
153
|
+
const str = Template.asString(s).trim();
|
|
154
|
+
if (!str) return "";
|
|
155
|
+
const ind = str[0] === "\n" ? "" : prefix;
|
|
156
|
+
return ind + str.replace(/\n([^\n])/g, "\n" + prefix + "$1");
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
/**
|
|
160
|
+
*
|
|
161
|
+
* @param {string|string[]} str string or string collection
|
|
162
|
+
* @returns {string} returns a single string from array
|
|
163
|
+
*/
|
|
164
|
+
static asString(str) {
|
|
165
|
+
if (Array.isArray(str)) {
|
|
166
|
+
return str.join("\n");
|
|
167
|
+
}
|
|
168
|
+
return str;
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
/**
|
|
172
|
+
* @typedef {Object} WithId
|
|
173
|
+
* @property {string|number} id
|
|
174
|
+
*/
|
|
175
|
+
|
|
176
|
+
/**
|
|
177
|
+
* @param {WithId[]} modules a collection of modules to get array bounds for
|
|
178
|
+
* @returns {[number, number] | false} returns the upper and lower array bounds
|
|
179
|
+
* or false if not every module has a number based id
|
|
180
|
+
*/
|
|
181
|
+
static getModulesArrayBounds(modules) {
|
|
182
|
+
let maxId = -Infinity;
|
|
183
|
+
let minId = Infinity;
|
|
184
|
+
for (const module of modules) {
|
|
185
|
+
if (typeof module.id !== "number") return false;
|
|
186
|
+
if (maxId < module.id) maxId = /** @type {number} */ (module.id);
|
|
187
|
+
if (minId > module.id) minId = /** @type {number} */ (module.id);
|
|
188
|
+
}
|
|
189
|
+
if (minId < 16 + ("" + minId).length) {
|
|
190
|
+
// add minId x ',' instead of 'Array(minId).concat(…)'
|
|
191
|
+
minId = 0;
|
|
192
|
+
}
|
|
193
|
+
const objectOverhead = modules
|
|
194
|
+
.map(module => (module.id + "").length + 2)
|
|
195
|
+
.reduce((a, b) => a + b, -1);
|
|
196
|
+
const arrayOverhead =
|
|
197
|
+
minId === 0 ? maxId : 16 + ("" + minId).length + maxId;
|
|
198
|
+
return arrayOverhead < objectOverhead ? [minId, maxId] : false;
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
/**
|
|
202
|
+
* @param {Chunk} chunk chunk whose modules will be rendered
|
|
203
|
+
* @param {ModuleFilterPredicate} filterFn function used to filter modules from chunk to render
|
|
204
|
+
* @param {ModuleTemplate} moduleTemplate ModuleTemplate instance used to render modules
|
|
205
|
+
* @param {TODO | TODO[]} dependencyTemplates templates needed for each module to render dependencies
|
|
206
|
+
* @param {string=} prefix applying prefix strings
|
|
207
|
+
* @returns {ConcatSource} rendered chunk modules in a Source object
|
|
208
|
+
*/
|
|
209
|
+
static renderChunkModules(
|
|
210
|
+
chunk,
|
|
211
|
+
filterFn,
|
|
212
|
+
moduleTemplate,
|
|
213
|
+
dependencyTemplates,
|
|
214
|
+
prefix = ""
|
|
215
|
+
) {
|
|
216
|
+
const source = new ConcatSource();
|
|
217
|
+
const modules = chunk.getModules().filter(filterFn);
|
|
218
|
+
let removedModules;
|
|
219
|
+
if (chunk instanceof HotUpdateChunk) {
|
|
220
|
+
removedModules = chunk.removedModules;
|
|
221
|
+
}
|
|
222
|
+
if (
|
|
223
|
+
modules.length === 0 &&
|
|
224
|
+
(!removedModules || removedModules.length === 0)
|
|
225
|
+
) {
|
|
226
|
+
source.add("[]");
|
|
227
|
+
return source;
|
|
228
|
+
}
|
|
229
|
+
/** @type {{id: string|number, source: Source|string}[]} */
|
|
230
|
+
const allModules = modules.map(module => {
|
|
231
|
+
return {
|
|
232
|
+
id: module.id,
|
|
233
|
+
source: moduleTemplate.render(module, dependencyTemplates, {
|
|
234
|
+
chunk
|
|
235
|
+
})
|
|
236
|
+
};
|
|
237
|
+
});
|
|
238
|
+
if (removedModules && removedModules.length > 0) {
|
|
239
|
+
for (const id of removedModules) {
|
|
240
|
+
allModules.push({
|
|
241
|
+
id,
|
|
242
|
+
source: "false"
|
|
243
|
+
});
|
|
244
|
+
}
|
|
245
|
+
}
|
|
246
|
+
const bounds = Template.getModulesArrayBounds(allModules);
|
|
247
|
+
if (bounds) {
|
|
248
|
+
// Render a spare array
|
|
249
|
+
const minId = bounds[0];
|
|
250
|
+
const maxId = bounds[1];
|
|
251
|
+
if (minId !== 0) {
|
|
252
|
+
source.add(`Array(${minId}).concat(`);
|
|
253
|
+
}
|
|
254
|
+
source.add("[\n");
|
|
255
|
+
/** @type {Map<string|number, {id: string|number, source: Source|string}>} */
|
|
256
|
+
const modules = new Map();
|
|
257
|
+
for (const module of allModules) {
|
|
258
|
+
modules.set(module.id, module);
|
|
259
|
+
}
|
|
260
|
+
for (let idx = minId; idx <= maxId; idx++) {
|
|
261
|
+
const module = modules.get(idx);
|
|
262
|
+
if (idx !== minId) {
|
|
263
|
+
source.add(",\n");
|
|
264
|
+
}
|
|
265
|
+
source.add(`/* ${idx} */`);
|
|
266
|
+
if (module) {
|
|
267
|
+
source.add("\n");
|
|
268
|
+
source.add(module.source);
|
|
269
|
+
}
|
|
270
|
+
}
|
|
271
|
+
source.add("\n" + prefix + "]");
|
|
272
|
+
if (minId !== 0) {
|
|
273
|
+
source.add(")");
|
|
274
|
+
}
|
|
275
|
+
} else {
|
|
276
|
+
// Render an object
|
|
277
|
+
source.add("{\n");
|
|
278
|
+
allModules.sort(stringifyIdSortPredicate).forEach((module, idx) => {
|
|
279
|
+
if (idx !== 0) {
|
|
280
|
+
source.add(",\n");
|
|
281
|
+
}
|
|
282
|
+
source.add(`\n/***/ ${JSON.stringify(module.id)}:\n`);
|
|
283
|
+
source.add(module.source);
|
|
284
|
+
});
|
|
285
|
+
source.add(`\n\n${prefix}}`);
|
|
286
|
+
}
|
|
287
|
+
return source;
|
|
288
|
+
}
|
|
289
|
+
}
|
|
290
|
+
|
|
291
|
+
module.exports = Template;
|
|
@@ -0,0 +1,188 @@
|
|
|
1
|
+
/*
|
|
2
|
+
MIT License http://www.opensource.org/licenses/mit-license.php
|
|
3
|
+
Author Jason Anderson @diurnalist
|
|
4
|
+
*/
|
|
5
|
+
"use strict";
|
|
6
|
+
|
|
7
|
+
const REGEXP_HASH = /\[hash(?::(\d+))?\]/gi,
|
|
8
|
+
REGEXP_CHUNKHASH = /\[chunkhash(?::(\d+))?\]/gi,
|
|
9
|
+
REGEXP_MODULEHASH = /\[modulehash(?::(\d+))?\]/gi,
|
|
10
|
+
REGEXP_CONTENTHASH = /\[contenthash(?::(\d+))?\]/gi,
|
|
11
|
+
REGEXP_NAME = /\[name\]/gi,
|
|
12
|
+
REGEXP_ID = /\[id\]/gi,
|
|
13
|
+
REGEXP_MODULEID = /\[moduleid\]/gi,
|
|
14
|
+
REGEXP_FILE = /\[file\]/gi,
|
|
15
|
+
REGEXP_QUERY = /\[query\]/gi,
|
|
16
|
+
REGEXP_FILEBASE = /\[filebase\]/gi,
|
|
17
|
+
REGEXP_URL = /\[url\]/gi;
|
|
18
|
+
|
|
19
|
+
// Using global RegExp for .test is dangerous
|
|
20
|
+
// We use a normal RegExp instead of .test
|
|
21
|
+
const REGEXP_HASH_FOR_TEST = new RegExp(REGEXP_HASH.source, "i"),
|
|
22
|
+
REGEXP_CHUNKHASH_FOR_TEST = new RegExp(REGEXP_CHUNKHASH.source, "i"),
|
|
23
|
+
REGEXP_CONTENTHASH_FOR_TEST = new RegExp(REGEXP_CONTENTHASH.source, "i"),
|
|
24
|
+
REGEXP_NAME_FOR_TEST = new RegExp(REGEXP_NAME.source, "i");
|
|
25
|
+
|
|
26
|
+
const withHashLength = (replacer, handlerFn, assetInfo) => {
|
|
27
|
+
const fn = (match, hashLength, ...args) => {
|
|
28
|
+
if (assetInfo) assetInfo.immutable = true;
|
|
29
|
+
const length = hashLength && parseInt(hashLength, 10);
|
|
30
|
+
if (length && handlerFn) {
|
|
31
|
+
return handlerFn(length);
|
|
32
|
+
}
|
|
33
|
+
const hash = replacer(match, hashLength, ...args);
|
|
34
|
+
return length ? hash.slice(0, length) : hash;
|
|
35
|
+
};
|
|
36
|
+
return fn;
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
const getReplacer = (value, allowEmpty) => {
|
|
40
|
+
const fn = (match, ...args) => {
|
|
41
|
+
// last argument in replacer is the entire input string
|
|
42
|
+
const input = args[args.length - 1];
|
|
43
|
+
if (value === null || value === undefined) {
|
|
44
|
+
if (!allowEmpty) {
|
|
45
|
+
throw new Error(
|
|
46
|
+
`Path variable ${match} not implemented in this context: ${input}`
|
|
47
|
+
);
|
|
48
|
+
}
|
|
49
|
+
return "";
|
|
50
|
+
} else {
|
|
51
|
+
return `${escapePathVariables(value)}`;
|
|
52
|
+
}
|
|
53
|
+
};
|
|
54
|
+
return fn;
|
|
55
|
+
};
|
|
56
|
+
|
|
57
|
+
const escapePathVariables = value => {
|
|
58
|
+
return typeof value === "string"
|
|
59
|
+
? value.replace(/\[(\\*[\w:]+\\*)\]/gi, "[\\$1\\]")
|
|
60
|
+
: value;
|
|
61
|
+
};
|
|
62
|
+
|
|
63
|
+
const replacePathVariables = (path, data, assetInfo) => {
|
|
64
|
+
const chunk = data.chunk;
|
|
65
|
+
const chunkId = chunk && chunk.id;
|
|
66
|
+
const chunkName = chunk && (chunk.name || chunk.id);
|
|
67
|
+
const chunkHash = chunk && (chunk.renderedHash || chunk.hash);
|
|
68
|
+
const chunkHashWithLength = chunk && chunk.hashWithLength;
|
|
69
|
+
const contentHashType = data.contentHashType;
|
|
70
|
+
const contentHash =
|
|
71
|
+
(chunk && chunk.contentHash && chunk.contentHash[contentHashType]) ||
|
|
72
|
+
data.contentHash;
|
|
73
|
+
const contentHashWithLength =
|
|
74
|
+
(chunk &&
|
|
75
|
+
chunk.contentHashWithLength &&
|
|
76
|
+
chunk.contentHashWithLength[contentHashType]) ||
|
|
77
|
+
data.contentHashWithLength;
|
|
78
|
+
const module = data.module;
|
|
79
|
+
const moduleId = module && module.id;
|
|
80
|
+
const moduleHash = module && (module.renderedHash || module.hash);
|
|
81
|
+
const moduleHashWithLength = module && module.hashWithLength;
|
|
82
|
+
|
|
83
|
+
if (typeof path === "function") {
|
|
84
|
+
path = path(data);
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
if (
|
|
88
|
+
data.noChunkHash &&
|
|
89
|
+
(REGEXP_CHUNKHASH_FOR_TEST.test(path) ||
|
|
90
|
+
REGEXP_CONTENTHASH_FOR_TEST.test(path))
|
|
91
|
+
) {
|
|
92
|
+
throw new Error(
|
|
93
|
+
`Cannot use [chunkhash] or [contenthash] for chunk in '${path}' (use [hash] instead)`
|
|
94
|
+
);
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
return (
|
|
98
|
+
path
|
|
99
|
+
.replace(
|
|
100
|
+
REGEXP_HASH,
|
|
101
|
+
withHashLength(getReplacer(data.hash), data.hashWithLength, assetInfo)
|
|
102
|
+
)
|
|
103
|
+
.replace(
|
|
104
|
+
REGEXP_CHUNKHASH,
|
|
105
|
+
withHashLength(getReplacer(chunkHash), chunkHashWithLength, assetInfo)
|
|
106
|
+
)
|
|
107
|
+
.replace(
|
|
108
|
+
REGEXP_CONTENTHASH,
|
|
109
|
+
withHashLength(
|
|
110
|
+
getReplacer(contentHash),
|
|
111
|
+
contentHashWithLength,
|
|
112
|
+
assetInfo
|
|
113
|
+
)
|
|
114
|
+
)
|
|
115
|
+
.replace(
|
|
116
|
+
REGEXP_MODULEHASH,
|
|
117
|
+
withHashLength(getReplacer(moduleHash), moduleHashWithLength, assetInfo)
|
|
118
|
+
)
|
|
119
|
+
.replace(REGEXP_ID, getReplacer(chunkId))
|
|
120
|
+
.replace(REGEXP_MODULEID, getReplacer(moduleId))
|
|
121
|
+
.replace(REGEXP_NAME, getReplacer(chunkName))
|
|
122
|
+
.replace(REGEXP_FILE, getReplacer(data.filename))
|
|
123
|
+
.replace(REGEXP_FILEBASE, getReplacer(data.basename))
|
|
124
|
+
// query is optional, it's OK if it's in a path but there's nothing to replace it with
|
|
125
|
+
.replace(REGEXP_QUERY, getReplacer(data.query, true))
|
|
126
|
+
// only available in sourceMappingURLComment
|
|
127
|
+
.replace(REGEXP_URL, getReplacer(data.url))
|
|
128
|
+
.replace(/\[\\(\\*[\w:]+\\*)\\\]/gi, "[$1]")
|
|
129
|
+
);
|
|
130
|
+
};
|
|
131
|
+
|
|
132
|
+
class TemplatedPathPlugin {
|
|
133
|
+
apply(compiler) {
|
|
134
|
+
compiler.hooks.compilation.tap("TemplatedPathPlugin", compilation => {
|
|
135
|
+
const mainTemplate = compilation.mainTemplate;
|
|
136
|
+
|
|
137
|
+
mainTemplate.hooks.assetPath.tap(
|
|
138
|
+
"TemplatedPathPlugin",
|
|
139
|
+
replacePathVariables
|
|
140
|
+
);
|
|
141
|
+
|
|
142
|
+
mainTemplate.hooks.globalHash.tap(
|
|
143
|
+
"TemplatedPathPlugin",
|
|
144
|
+
(chunk, paths) => {
|
|
145
|
+
const outputOptions = mainTemplate.outputOptions;
|
|
146
|
+
const publicPath = outputOptions.publicPath || "";
|
|
147
|
+
const filename = outputOptions.filename || "";
|
|
148
|
+
const chunkFilename =
|
|
149
|
+
outputOptions.chunkFilename || outputOptions.filename;
|
|
150
|
+
if (
|
|
151
|
+
REGEXP_HASH_FOR_TEST.test(publicPath) ||
|
|
152
|
+
REGEXP_CHUNKHASH_FOR_TEST.test(publicPath) ||
|
|
153
|
+
REGEXP_CONTENTHASH_FOR_TEST.test(publicPath) ||
|
|
154
|
+
REGEXP_NAME_FOR_TEST.test(publicPath)
|
|
155
|
+
)
|
|
156
|
+
return true;
|
|
157
|
+
if (REGEXP_HASH_FOR_TEST.test(filename)) return true;
|
|
158
|
+
if (REGEXP_HASH_FOR_TEST.test(chunkFilename)) return true;
|
|
159
|
+
if (REGEXP_HASH_FOR_TEST.test(paths.join("|"))) return true;
|
|
160
|
+
}
|
|
161
|
+
);
|
|
162
|
+
|
|
163
|
+
mainTemplate.hooks.hashForChunk.tap(
|
|
164
|
+
"TemplatedPathPlugin",
|
|
165
|
+
(hash, chunk) => {
|
|
166
|
+
const outputOptions = mainTemplate.outputOptions;
|
|
167
|
+
const chunkFilename =
|
|
168
|
+
outputOptions.chunkFilename || outputOptions.filename;
|
|
169
|
+
if (REGEXP_CHUNKHASH_FOR_TEST.test(chunkFilename)) {
|
|
170
|
+
hash.update(JSON.stringify(chunk.getChunkMaps(true).hash));
|
|
171
|
+
}
|
|
172
|
+
if (REGEXP_CONTENTHASH_FOR_TEST.test(chunkFilename)) {
|
|
173
|
+
hash.update(
|
|
174
|
+
JSON.stringify(
|
|
175
|
+
chunk.getChunkMaps(true).contentHash.javascript || {}
|
|
176
|
+
)
|
|
177
|
+
);
|
|
178
|
+
}
|
|
179
|
+
if (REGEXP_NAME_FOR_TEST.test(chunkFilename)) {
|
|
180
|
+
hash.update(JSON.stringify(chunk.getChunkMaps(true).name));
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
);
|
|
184
|
+
});
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
module.exports = TemplatedPathPlugin;
|