From 62bdd9732825bba28da7d4a94c6a3943496a549c Mon Sep 17 00:00:00 2001 From: LingyuCoder Date: Wed, 22 Jan 2025 17:03:20 +0800 Subject: [PATCH 1/4] feat: add runtime plugin hooks --- Cargo.lock | 3 + crates/node_binding/Cargo.toml | 1 + crates/node_binding/binding.d.ts | 23 +- .../node_binding/src/plugins/interceptor.rs | 110 ++++++++- crates/node_binding/src/plugins/mod.rs | 48 ++++ crates/rspack_binding_values/src/chunk.rs | 6 +- crates/rspack_binding_values/src/runtime.rs | 61 +++++ crates/rspack_plugin_runtime/Cargo.toml | 8 +- crates/rspack_plugin_runtime/src/drive.rs | 42 ++++ crates/rspack_plugin_runtime/src/lib.rs | 2 + .../src/runtime_module/jsonp_chunk_loading.rs | 71 +++++- .../src/runtime_module/load_script.rs | 146 +++++++---- .../jsonp_chunk_loading_with_prefetch.js | 9 +- .../jsonp_chunk_loading_with_preload.js | 10 +- .../src/runtime_module/runtime/load_script.js | 13 +- .../src/runtime_plugin.rs | 52 +++- ...NewCodeSplitting-stats-output.test.js.snap | 26 +- .../__snapshots__/StatsOutput.test.js.snap | 26 +- .../configCases/hooks/create-script/a.js | 1 + .../configCases/hooks/create-script/index.js | 5 + .../hooks/create-script/rspack.config.js | 21 ++ .../hooks/create-script/test.config.js | 3 + .../hooks/link-prefetch-preload/chunk1-a.js | 0 .../hooks/link-prefetch-preload/chunk1-b.js | 0 .../hooks/link-prefetch-preload/chunk1-c.js | 0 .../hooks/link-prefetch-preload/chunk1.js | 5 + .../hooks/link-prefetch-preload/chunk2.js | 4 + .../hooks/link-prefetch-preload/index.js | 22 ++ .../link-prefetch-preload/rspack.config.js | 24 ++ .../link-prefetch-preload/test.config.js | 3 + .../tests/statsAPICases/chunk-group.js | 16 +- .../tests/statsAPICases/chunks.js | 4 +- packages/rspack/etc/core.api.md | 25 ++ packages/rspack/src/Compiler.ts | 8 +- .../src/builtin-plugin/RuntimePlugin.ts | 95 ++++++- packages/rspack/src/exports.ts | 1 + ...$.css => async.$f4608fdcfef13de69f10$.css} | 0 ...7$.css => main.$f4608fdcfef13de69f10$.css} | 0 .../chunkFilename-fullhash/expected/main.js | 7 +- .../cases/hmr-locals/expected/main.js | 5 +- .../css-extract/cases/hmr/expected/main.js | 5 +- .../cases/insert-function/expected/main.js | 5 +- .../cases/insert-string/expected/main.js | 5 +- .../cases/insert-undefined/expected/main.js | 5 +- .../cases/issue-6649/expected/main.js | 7 +- .../cases/no-runtime/expected/main.js | 5 +- .../cases/runtime/expected/runtime~main.js | 5 +- .../StatsTestCases.basictest.js.snap | 232 +++++++++--------- 48 files changed, 895 insertions(+), 280 deletions(-) create mode 100644 crates/rspack_plugin_runtime/src/drive.rs create mode 100644 packages/rspack-test-tools/tests/configCases/hooks/create-script/a.js create mode 100644 packages/rspack-test-tools/tests/configCases/hooks/create-script/index.js create mode 100644 packages/rspack-test-tools/tests/configCases/hooks/create-script/rspack.config.js create mode 100644 packages/rspack-test-tools/tests/configCases/hooks/create-script/test.config.js create mode 100644 packages/rspack-test-tools/tests/configCases/hooks/link-prefetch-preload/chunk1-a.js create mode 100644 packages/rspack-test-tools/tests/configCases/hooks/link-prefetch-preload/chunk1-b.js create mode 100644 packages/rspack-test-tools/tests/configCases/hooks/link-prefetch-preload/chunk1-c.js create mode 100644 packages/rspack-test-tools/tests/configCases/hooks/link-prefetch-preload/chunk1.js create mode 100644 packages/rspack-test-tools/tests/configCases/hooks/link-prefetch-preload/chunk2.js create mode 100644 packages/rspack-test-tools/tests/configCases/hooks/link-prefetch-preload/index.js create mode 100644 packages/rspack-test-tools/tests/configCases/hooks/link-prefetch-preload/rspack.config.js create mode 100644 packages/rspack-test-tools/tests/configCases/hooks/link-prefetch-preload/test.config.js rename tests/plugin-test/css-extract/cases/chunkFilename-fullhash/expected/{async.$d026823092eb39bd50f7$.css => async.$f4608fdcfef13de69f10$.css} (100%) rename tests/plugin-test/css-extract/cases/chunkFilename-fullhash/expected/{main.$d026823092eb39bd50f7$.css => main.$f4608fdcfef13de69f10$.css} (100%) diff --git a/Cargo.lock b/Cargo.lock index 2a992b83ac1e..e943976d7101 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -4681,6 +4681,7 @@ dependencies = [ "rspack_paths", "rspack_plugin_html", "rspack_plugin_javascript", + "rspack_plugin_runtime", "rspack_tracing", "rspack_util", "tracing", @@ -5191,9 +5192,11 @@ version = "0.2.0" dependencies = [ "async-trait", "cow-utils", + "dashmap 6.1.0", "derive_more 1.0.0", "indexmap 2.7.0", "itertools 0.14.0", + "pollster", "rspack_cacheable", "rspack_collections", "rspack_core", diff --git a/crates/node_binding/Cargo.toml b/crates/node_binding/Cargo.toml index 8f22cf09c42b..5c6cafbf2952 100644 --- a/crates/node_binding/Cargo.toml +++ b/crates/node_binding/Cargo.toml @@ -28,6 +28,7 @@ rspack_napi = { workspace = true } rspack_paths = { workspace = true } rspack_plugin_html = { workspace = true } rspack_plugin_javascript = { workspace = true } +rspack_plugin_runtime = { workspace = true } rspack_util = { workspace = true } rspack_tracing = { workspace = true } diff --git a/crates/node_binding/binding.d.ts b/crates/node_binding/binding.d.ts index 3ea10d5d3bef..80fcec46a8cf 100644 --- a/crates/node_binding/binding.d.ts +++ b/crates/node_binding/binding.d.ts @@ -592,6 +592,11 @@ export interface JsCreateData { resource: string } +export interface JsCreateScriptData { + code: string + chunk: JsChunk +} + export interface JsDefaultObjectRedirectWarnObject { ignore: boolean } @@ -719,6 +724,16 @@ export interface JsLibraryOptions { amdContainer?: string } +export interface JsLinkPrefetchData { + code: string + chunk: JsChunk +} + +export interface JsLinkPreloadData { + code: string + chunk: JsChunk +} + export interface JsLoaderContext { resourceData: Readonly /** Will be deprecated. Use module.module_identifier instead */ @@ -2117,7 +2132,10 @@ export declare enum RegisterJsTapKind { HtmlPluginAlterAssetTagGroups = 37, HtmlPluginAfterTemplateExecution = 38, HtmlPluginBeforeEmit = 39, - HtmlPluginAfterEmit = 40 + HtmlPluginAfterEmit = 40, + RuntimePluginCreateScript = 41, + RuntimePluginLinkPreload = 42, + RuntimePluginLinkPrefetch = 43 } export interface RegisterJsTaps { @@ -2162,6 +2180,9 @@ export interface RegisterJsTaps { registerHtmlPluginAfterTemplateExecutionTaps: (stages: Array) => Array<{ function: ((arg: JsAfterTemplateExecutionData) => JsAfterTemplateExecutionData); stage: number; }> registerHtmlPluginBeforeEmitTaps: (stages: Array) => Array<{ function: ((arg: JsBeforeEmitData) => JsBeforeEmitData); stage: number; }> registerHtmlPluginAfterEmitTaps: (stages: Array) => Array<{ function: ((arg: JsAfterEmitData) => JsAfterEmitData); stage: number; }> + registerRuntimePluginCreateScriptTaps: (stages: Array) => Array<{ function: ((arg: JsCreateScriptData) => String); stage: number; }> + registerRuntimePluginLinkPreloadTaps: (stages: Array) => Array<{ function: ((arg: JsLinkPreloadData) => String); stage: number; }> + registerRuntimePluginLinkPrefetchTaps: (stages: Array) => Array<{ function: ((arg: JsLinkPrefetchData) => String); stage: number; }> } export interface ThreadsafeNodeFS { diff --git a/crates/node_binding/src/plugins/interceptor.rs b/crates/node_binding/src/plugins/interceptor.rs index dfe1e60e1854..037319edbbdd 100644 --- a/crates/node_binding/src/plugins/interceptor.rs +++ b/crates/node_binding/src/plugins/interceptor.rs @@ -17,10 +17,11 @@ use rspack_binding_values::{ JsChunkAssetArgs, JsChunkWrapper, JsCompilationWrapper, JsContextModuleFactoryAfterResolveDataWrapper, JsContextModuleFactoryAfterResolveResult, JsContextModuleFactoryBeforeResolveDataWrapper, JsContextModuleFactoryBeforeResolveResult, - JsCreateData, JsExecuteModuleArg, JsFactorizeArgs, JsFactorizeOutput, JsModuleWrapper, - JsNormalModuleFactoryCreateModuleArgs, JsResolveArgs, JsResolveForSchemeArgs, - JsResolveForSchemeOutput, JsResolveOutput, JsRuntimeGlobals, JsRuntimeModule, JsRuntimeModuleArg, - JsRuntimeRequirementInTreeArg, JsRuntimeRequirementInTreeResult, ToJsCompatSourceOwned, + JsCreateData, JsCreateScriptData, JsExecuteModuleArg, JsFactorizeArgs, JsFactorizeOutput, + JsLinkPrefetchData, JsLinkPreloadData, JsModuleWrapper, JsNormalModuleFactoryCreateModuleArgs, + JsResolveArgs, JsResolveForSchemeArgs, JsResolveForSchemeOutput, JsResolveOutput, + JsRuntimeGlobals, JsRuntimeModule, JsRuntimeModuleArg, JsRuntimeRequirementInTreeArg, + JsRuntimeRequirementInTreeResult, ToJsCompatSourceOwned, }; use rspack_collections::IdentifierSet; use rspack_core::{ @@ -67,6 +68,11 @@ use rspack_plugin_html::{ HtmlPluginBeforeAssetTagGenerationHook, HtmlPluginBeforeEmit, HtmlPluginBeforeEmitHook, }; use rspack_plugin_javascript::{JavascriptModulesChunkHash, JavascriptModulesChunkHashHook}; +use rspack_plugin_runtime::{ + CreateScriptData, LinkPrefetchData, LinkPreloadData, RuntimePluginCreateScript, + RuntimePluginCreateScriptHook, RuntimePluginLinkPrefetch, RuntimePluginLinkPrefetchHook, + RuntimePluginLinkPreload, RuntimePluginLinkPreloadHook, +}; #[napi(object)] pub struct JsTap<'f> { @@ -386,6 +392,9 @@ pub enum RegisterJsTapKind { HtmlPluginAfterTemplateExecution, HtmlPluginBeforeEmit, HtmlPluginAfterEmit, + RuntimePluginCreateScript, + RuntimePluginLinkPreload, + RuntimePluginLinkPrefetch, } #[derive(Default, Clone)] @@ -589,6 +598,21 @@ pub struct RegisterJsTaps { )] pub register_html_plugin_after_emit_taps: RegisterFunction>, + #[napi( + ts_type = "(stages: Array) => Array<{ function: ((arg: JsCreateScriptData) => String); stage: number; }>" + )] + pub register_runtime_plugin_create_script_taps: + RegisterFunction>, + #[napi( + ts_type = "(stages: Array) => Array<{ function: ((arg: JsLinkPreloadData) => String); stage: number; }>" + )] + pub register_runtime_plugin_link_preload_taps: + RegisterFunction>, + #[napi( + ts_type = "(stages: Array) => Array<{ function: ((arg: JsLinkPrefetchData) => String); stage: number; }>" + )] + pub register_runtime_plugin_link_prefetch_taps: + RegisterFunction>, } /* Compiler Hooks */ @@ -935,6 +959,30 @@ define_register!( kind = RegisterJsTapKind::HtmlPluginAfterEmit, skip = true, ); +define_register!( + RegisterRuntimePluginCreateScriptTaps, + tap = RuntimePluginCreateScriptTap> @ RuntimePluginCreateScriptHook, + cache = true, + sync = false, + kind = RegisterJsTapKind::RuntimePluginCreateScript, + skip = true, +); +define_register!( + RegisterRuntimePluginLinkPreloadTaps, + tap = RuntimePluginLinkPreloadTap> @ RuntimePluginLinkPreloadHook, + cache = true, + sync = false, + kind = RegisterJsTapKind::RuntimePluginLinkPreload, + skip = true, +); +define_register!( + RegisterRuntimePluginLinkPrefetchTaps, + tap = RuntimePluginLinkPrefetchTap> @ RuntimePluginLinkPrefetchHook, + cache = true, + sync = false, + kind = RegisterJsTapKind::RuntimePluginLinkPrefetch, + skip = true, +); #[async_trait] impl CompilerThisCompilation for CompilerThisCompilationTap { @@ -1768,3 +1816,57 @@ impl HtmlPluginAfterEmit for HtmlPluginAfterEmitTap { self.stage } } + +#[async_trait] +impl RuntimePluginCreateScript for RuntimePluginCreateScriptTap { + async fn run(&self, mut data: CreateScriptData) -> rspack_error::Result { + if let Some(code) = self + .function + .call_with_sync(JsCreateScriptData::from(data.clone())) + .await? + { + data.code = code; + } + Ok(data) + } + + fn stage(&self) -> i32 { + self.stage + } +} + +#[async_trait] +impl RuntimePluginLinkPreload for RuntimePluginLinkPreloadTap { + async fn run(&self, mut data: LinkPreloadData) -> rspack_error::Result { + if let Some(code) = self + .function + .call_with_sync(JsLinkPreloadData::from(data.clone())) + .await? + { + data.code = code; + } + Ok(data) + } + + fn stage(&self) -> i32 { + self.stage + } +} + +#[async_trait] +impl RuntimePluginLinkPrefetch for RuntimePluginLinkPrefetchTap { + async fn run(&self, mut data: LinkPrefetchData) -> rspack_error::Result { + if let Some(code) = self + .function + .call_with_sync(JsLinkPrefetchData::from(data.clone())) + .await? + { + data.code = code; + } + Ok(data) + } + + fn stage(&self) -> i32 { + self.stage + } +} diff --git a/crates/node_binding/src/plugins/mod.rs b/crates/node_binding/src/plugins/mod.rs index 5e792a537b35..8710a8137b7c 100644 --- a/crates/node_binding/src/plugins/mod.rs +++ b/crates/node_binding/src/plugins/mod.rs @@ -14,6 +14,7 @@ use rspack_hook::plugin_hook; use rspack_hook::Hook as _; use rspack_plugin_html::HtmlRspackPlugin; use rspack_plugin_javascript::JsPlugin; +use rspack_plugin_runtime::RuntimePlugin; use self::interceptor::*; @@ -67,6 +68,9 @@ pub struct JsHooksAdapterPlugin { register_html_plugin_after_template_execution_taps: RegisterHtmlPluginAfterTemplateExecutionTaps, register_html_plugin_before_emit_taps: RegisterHtmlPluginBeforeEmitTaps, register_html_plugin_after_emit_taps: RegisterHtmlPluginAfterEmitTaps, + register_runtime_plugin_create_script_taps: RegisterRuntimePluginCreateScriptTaps, + register_runtime_plugin_link_preload_taps: RegisterRuntimePluginLinkPreloadTaps, + register_runtime_plugin_link_prefetch_taps: RegisterRuntimePluginLinkPrefetchTaps, } impl fmt::Debug for JsHooksAdapterPlugin { @@ -311,6 +315,12 @@ impl rspack_core::Plugin for JsHooksAdapterPlugin { .compilation .tap(html_hooks_adapter_compilation::new(self)); + ctx + .context + .compiler_hooks + .compilation + .tap(runtime_hooks_adapter_compilation::new(self)); + Ok(()) } @@ -396,6 +406,13 @@ impl rspack_core::Plugin for JsHooksAdapterPlugin { .clear_cache(); self.register_html_plugin_before_emit_taps.clear_cache(); self.register_html_plugin_after_emit_taps.clear_cache(); + self + .register_runtime_plugin_create_script_taps + .clear_cache(); + self.register_runtime_plugin_link_preload_taps.clear_cache(); + self + .register_runtime_plugin_link_prefetch_taps + .clear_cache(); } } @@ -448,6 +465,25 @@ async fn html_hooks_adapter_compilation( Ok(()) } +#[plugin_hook(CompilerCompilation for JsHooksAdapterPlugin)] +async fn runtime_hooks_adapter_compilation( + &self, + compilation: &mut Compilation, + _params: &mut CompilationParams, +) -> rspack_error::Result<()> { + let mut hooks = RuntimePlugin::get_compilation_hooks_mut(compilation); + hooks + .create_script + .intercept(self.register_runtime_plugin_create_script_taps.clone()); + hooks + .link_preload + .intercept(self.register_runtime_plugin_link_preload_taps.clone()); + hooks + .link_prefetch + .intercept(self.register_runtime_plugin_link_prefetch_taps.clone()); + Ok(()) +} + impl JsHooksAdapterPlugin { pub fn from_js_hooks(_env: Env, register_js_taps: RegisterJsTaps) -> Result { let non_skippable_registers = NonSkippableRegisters::default(); @@ -632,6 +668,18 @@ impl JsHooksAdapterPlugin { register_js_taps.register_html_plugin_after_emit_taps, non_skippable_registers.clone(), ), + register_runtime_plugin_create_script_taps: RegisterRuntimePluginCreateScriptTaps::new( + register_js_taps.register_runtime_plugin_create_script_taps, + non_skippable_registers.clone(), + ), + register_runtime_plugin_link_preload_taps: RegisterRuntimePluginLinkPreloadTaps::new( + register_js_taps.register_runtime_plugin_link_preload_taps, + non_skippable_registers.clone(), + ), + register_runtime_plugin_link_prefetch_taps: RegisterRuntimePluginLinkPrefetchTaps::new( + register_js_taps.register_runtime_plugin_link_prefetch_taps, + non_skippable_registers.clone(), + ), non_skippable_registers, } .into(), diff --git a/crates/rspack_binding_values/src/chunk.rs b/crates/rspack_binding_values/src/chunk.rs index feb6529f289e..132775098186 100644 --- a/crates/rspack_binding_values/src/chunk.rs +++ b/crates/rspack_binding_values/src/chunk.rs @@ -241,9 +241,9 @@ thread_local! { } pub struct JsChunkWrapper { - chunk_ukey: ChunkUkey, - compilation_id: CompilationId, - compilation: NonNull, + pub chunk_ukey: ChunkUkey, + pub compilation_id: CompilationId, + pub compilation: NonNull, } unsafe impl Send for JsChunkWrapper {} diff --git a/crates/rspack_binding_values/src/runtime.rs b/crates/rspack_binding_values/src/runtime.rs index d9f2be2c252f..ae62604750b6 100644 --- a/crates/rspack_binding_values/src/runtime.rs +++ b/crates/rspack_binding_values/src/runtime.rs @@ -4,6 +4,9 @@ use cow_utils::CowUtils; use heck::{ToLowerCamelCase, ToSnakeCase}; use napi_derive::napi; use rspack_core::RuntimeGlobals; +use rspack_plugin_runtime::{ + CreateScriptData, LinkPrefetchData, LinkPreloadData, RuntimeModuleChunkWrapper, +}; use rustc_hash::FxHashMap; use crate::JsChunkWrapper; @@ -174,3 +177,61 @@ impl JsRuntimeRequirementInTreeResult { runtime_requirements } } + +#[napi(object, object_from_js = false)] +pub struct JsCreateScriptData { + pub code: String, + #[napi(ts_type = "JsChunk")] + pub chunk: JsChunkWrapper, +} + +impl From for JsCreateScriptData { + fn from(value: CreateScriptData) -> Self { + Self { + code: value.code, + chunk: value.chunk.into(), + } + } +} + +#[napi(object, object_from_js = false)] +pub struct JsLinkPreloadData { + pub code: String, + #[napi(ts_type = "JsChunk")] + pub chunk: JsChunkWrapper, +} + +impl From for JsLinkPreloadData { + fn from(value: LinkPreloadData) -> Self { + Self { + code: value.code, + chunk: value.chunk.into(), + } + } +} + +#[napi(object, object_from_js = false)] +pub struct JsLinkPrefetchData { + pub code: String, + #[napi(ts_type = "JsChunk")] + pub chunk: JsChunkWrapper, +} + +impl From for JsLinkPrefetchData { + fn from(value: LinkPrefetchData) -> Self { + Self { + code: value.code, + chunk: value.chunk.into(), + } + } +} + +impl From for JsChunkWrapper { + fn from(value: RuntimeModuleChunkWrapper) -> Self { + Self { + chunk_ukey: value.chunk_ukey, + compilation_id: value.compilation_id, + compilation: value.compilation, + } + } +} diff --git a/crates/rspack_plugin_runtime/Cargo.toml b/crates/rspack_plugin_runtime/Cargo.toml index 57abb588a87e..4764620bcedd 100644 --- a/crates/rspack_plugin_runtime/Cargo.toml +++ b/crates/rspack_plugin_runtime/Cargo.toml @@ -10,9 +10,11 @@ version = "0.2.0" [dependencies] async-trait = { workspace = true } cow-utils = { workspace = true } +dashmap = { workspace = true } derive_more = { workspace = true, features = ["debug"] } indexmap = { workspace = true } itertools = { workspace = true } +pollster = { workspace = true } rspack_cacheable = { workspace = true } rspack_collections = { workspace = true } rspack_core = { workspace = true } @@ -22,9 +24,9 @@ rspack_hook = { workspace = true } rspack_plugin_javascript = { workspace = true } rspack_util = { workspace = true } -rustc-hash = { workspace = true } -serde_json = { workspace = true } -tracing = { workspace = true } +rustc-hash = { workspace = true } +serde_json = { workspace = true } +tracing = { workspace = true } [package.metadata.cargo-shear] ignored = ["tracing"] diff --git a/crates/rspack_plugin_runtime/src/drive.rs b/crates/rspack_plugin_runtime/src/drive.rs new file mode 100644 index 000000000000..8ab2515411c7 --- /dev/null +++ b/crates/rspack_plugin_runtime/src/drive.rs @@ -0,0 +1,42 @@ +use std::ptr::NonNull; + +use rspack_core::{ChunkUkey, Compilation, CompilationId}; +use rspack_hook::define_hook; + +#[derive(Debug, Clone)] +pub struct CreateScriptData { + pub code: String, + pub chunk: RuntimeModuleChunkWrapper, +} + +#[derive(Debug, Clone)] +pub struct LinkPreloadData { + pub code: String, + pub chunk: RuntimeModuleChunkWrapper, +} + +#[derive(Debug, Clone)] +pub struct LinkPrefetchData { + pub code: String, + pub chunk: RuntimeModuleChunkWrapper, +} + +#[derive(Debug, Clone)] +pub struct RuntimeModuleChunkWrapper { + pub chunk_ukey: ChunkUkey, + pub compilation_id: CompilationId, + pub compilation: NonNull, +} + +unsafe impl Send for RuntimeModuleChunkWrapper {} + +define_hook!(RuntimePluginCreateScript: AsyncSeriesWaterfall(data: CreateScriptData) -> CreateScriptData); +define_hook!(RuntimePluginLinkPreload: AsyncSeriesWaterfall(data: LinkPreloadData) -> LinkPreloadData); +define_hook!(RuntimePluginLinkPrefetch: AsyncSeriesWaterfall(data: LinkPrefetchData) -> LinkPrefetchData); + +#[derive(Debug, Default)] +pub struct RuntimePluginHooks { + pub create_script: RuntimePluginCreateScriptHook, + pub link_preload: RuntimePluginLinkPreloadHook, + pub link_prefetch: RuntimePluginLinkPrefetchHook, +} diff --git a/crates/rspack_plugin_runtime/src/lib.rs b/crates/rspack_plugin_runtime/src/lib.rs index a6cae0c42af9..ec315627e0f7 100644 --- a/crates/rspack_plugin_runtime/src/lib.rs +++ b/crates/rspack_plugin_runtime/src/lib.rs @@ -31,6 +31,8 @@ mod bundler_info; pub use bundler_info::{BundlerInfoForceMode, BundlerInfoPlugin}; mod runtime_module_from_js; pub use runtime_module_from_js::RuntimeModuleFromJs; +mod drive; +pub use drive::*; pub fn enable_chunk_loading_plugin(loading_type: ChunkLoadingType, plugins: &mut Vec) { match loading_type { diff --git a/crates/rspack_plugin_runtime/src/runtime_module/jsonp_chunk_loading.rs b/crates/rspack_plugin_runtime/src/runtime_module/jsonp_chunk_loading.rs index 1740d38deba8..974141c6226c 100644 --- a/crates/rspack_plugin_runtime/src/runtime_module/jsonp_chunk_loading.rs +++ b/crates/rspack_plugin_runtime/src/runtime_module/jsonp_chunk_loading.rs @@ -1,4 +1,7 @@ +use std::ptr::NonNull; + use cow_utils::CowUtils; +use pollster::block_on; use rspack_collections::{DatabaseItem, Identifier}; use rspack_core::{ compile_boolean_matcher, impl_runtime_module, @@ -11,6 +14,7 @@ use super::generate_javascript_hmr_runtime; use crate::{ get_chunk_runtime_requirements, runtime_module::utils::{chunk_has_js, get_initial_chunk_ids, stringify_chunks}, + LinkPrefetchData, LinkPreloadData, RuntimeModuleChunkWrapper, RuntimePlugin, }; #[impl_runtime_module] @@ -63,6 +67,8 @@ impl RuntimeModule for JsonpChunkLoadingRuntimeModule { let cross_origin_loading = &compilation.options.output.cross_origin_loading; let script_type = &compilation.options.output.script_type; + let hooks = RuntimePlugin::get_compilation_hooks(compilation.id()); + let condition_map = compilation .chunk_graph @@ -142,10 +148,38 @@ impl RuntimeModule for JsonpChunkLoadingRuntimeModule { format!("link.crossOrigin = {}", cross_origin_loading) } }; + let link_prefetch_code = r#" + var link = document.createElement('link'); + $CROSS_ORIGIN$ + if (__webpack_require__.nc) { + link.setAttribute("nonce", __webpack_require__.nc); + } + link.rel = "prefetch"; + link.as = "script"; + link.href = __webpack_require__.p + __webpack_require__.u(chunkId); + "# + .cow_replace("$CROSS_ORIGIN$", cross_origin.as_str()) + .to_string(); + + let chunk_ukey = self.chunk.expect("The chunk should be attached"); + let res = block_on(async { + hooks + .link_prefetch + .call(LinkPrefetchData { + code: link_prefetch_code, + chunk: RuntimeModuleChunkWrapper { + chunk_ukey, + compilation_id: compilation.id(), + compilation: NonNull::from(compilation), + }, + }) + .await + })?; + source.add(RawStringSource::from( include_str!("runtime/jsonp_chunk_loading_with_prefetch.js") .cow_replace("$JS_MATCHER$", &js_matcher) - .cow_replace("$CROSS_ORIGIN$", cross_origin.as_str()) + .cow_replace("$LINK_PREFETCH$", &res.code) .into_owned(), )); } @@ -185,12 +219,41 @@ impl RuntimeModule for JsonpChunkLoadingRuntimeModule { "# }; + let link_preload_code = r#" + var link = document.createElement('link'); + $SCRIPT_TYPE_LINK_PRE$ + link.charset = 'utf-8'; + if (__webpack_require__.nc) { + link.setAttribute("nonce", __webpack_require__.nc); + } + $SCRIPT_TYPE_LINK_POST$ + link.href = __webpack_require__.p + __webpack_require__.u(chunkId); + $CROSS_ORIGIN$ + "# + .cow_replace("$CROSS_ORIGIN$", cross_origin.as_str()) + .cow_replace("$SCRIPT_TYPE_LINK_PRE$", script_type_link_pre.as_str()) + .cow_replace("$SCRIPT_TYPE_LINK_POST$", script_type_link_post) + .to_string(); + + let chunk_ukey = self.chunk.expect("The chunk should be attached"); + let res = block_on(async { + hooks + .link_preload + .call(LinkPreloadData { + code: link_preload_code, + chunk: RuntimeModuleChunkWrapper { + chunk_ukey, + compilation_id: compilation.id(), + compilation: NonNull::from(compilation), + }, + }) + .await + })?; + source.add(RawStringSource::from( include_str!("runtime/jsonp_chunk_loading_with_preload.js") .cow_replace("$JS_MATCHER$", &js_matcher) - .cow_replace("$CROSS_ORIGIN$", cross_origin.as_str()) - .cow_replace("$SCRIPT_TYPE_LINK_PRE$", script_type_link_pre.as_str()) - .cow_replace("$SCRIPT_TYPE_LINK_POST$", script_type_link_post) + .cow_replace("$LINK_PRELOAD$", &res.code) .into_owned(), )); } diff --git a/crates/rspack_plugin_runtime/src/runtime_module/load_script.rs b/crates/rspack_plugin_runtime/src/runtime_module/load_script.rs index 442291066d63..c8031012c99f 100644 --- a/crates/rspack_plugin_runtime/src/runtime_module/load_script.rs +++ b/crates/rspack_plugin_runtime/src/runtime_module/load_script.rs @@ -1,4 +1,7 @@ +use std::ptr::NonNull; + use cow_utils::CowUtils; +use pollster::block_on; use rspack_collections::Identifier; use rspack_core::{ impl_runtime_module, @@ -6,7 +9,9 @@ use rspack_core::{ ChunkUkey, Compilation, CrossOriginLoading, RuntimeGlobals, RuntimeModule, }; -use crate::get_chunk_runtime_requirements; +use crate::{ + get_chunk_runtime_requirements, CreateScriptData, RuntimeModuleChunkWrapper, RuntimePlugin, +}; #[impl_runtime_module] #[derive(Debug)] @@ -50,9 +55,9 @@ impl RuntimeModule for LoadScriptRuntimeModule { } else { format!( r#" - if (script.src.indexOf(window.location.origin + '/') !== 0) {{ - script.crossOrigin = "{cross_origin}"; - }} + if (script.src.indexOf(window.location.origin + '/') !== 0) {{ + script.crossOrigin = "{cross_origin}"; + }} "# ) } @@ -83,50 +88,99 @@ impl RuntimeModule for LoadScriptRuntimeModule { "".to_string() }; - Ok(RawStringSource::from( - include_str!("runtime/load_script.js") - .cow_replace( - "__CROSS_ORIGIN_LOADING_PLACEHOLDER__", - &cross_origin_loading, - ) - .cow_replace("$URL$", &url) - .cow_replace("$SCRIPT_TYPE$", &script_type) - .cow_replace("$SCRIPT_CHARSET$", &script_charset) - .cow_replace("$CHUNK_LOAD_TIMEOUT$", &compilation.options.output.chunk_load_timeout.to_string()) - .cow_replace("$CHUNK_LOAD_TIMEOUT_IN_SECONDS$", &compilation.options.output.chunk_load_timeout.saturating_div(1000).to_string()) - .cow_replace( - "$UNIQUE_GET_ATTRIBUTE$", - match unique_prefix { - Some(_) => r#"s.getAttribute("src") == url || s.getAttribute("data-webpack") == dataWebpackPrefix + key"#, - None => r#"s.getAttribute("src") == url"#, + let create_script_code = r#" + script = document.createElement('script'); + $SCRIPT_TYPE$ + $SCRIPT_CHARSET$ + script.timeout = $CHUNK_LOAD_TIMEOUT_IN_SECONDS$; + if (__webpack_require__.nc) { + script.setAttribute("nonce", __webpack_require__.nc); + } + $UNIQUE_SET_ATTRIBUTE$ + $FETCH_PRIORITY_SET_ATTRIBUTE$ + script.src = $URL$; + $CROSS_ORIGIN_LOADING$ + "# + .cow_replace("$SCRIPT_TYPE$", &script_type) + .cow_replace("$SCRIPT_CHARSET$", &script_charset) + .cow_replace( + "$CHUNK_LOAD_TIMEOUT_IN_SECONDS$", + &compilation + .options + .output + .chunk_load_timeout + .saturating_div(1000) + .to_string(), + ) + .cow_replace( + "$UNIQUE_SET_ATTRIBUTE$", + match unique_prefix { + Some(_) => r#"script.setAttribute("data-webpack", dataWebpackPrefix + key);"#, + None => "", + }, + ) + .cow_replace( + "$FETCH_PRIORITY_SET_ATTRIBUTE$", + if with_fetch_priority { + r#" + if(fetchPriority) { + script.setAttribute("fetchpriority", fetchPriority); + } + "# + } else { + "" + }, + ) + .cow_replace("$URL$", &url) + .cow_replace("$CROSS_ORIGIN_LOADING$", &cross_origin_loading) + .to_string(); + + let hooks = RuntimePlugin::get_compilation_hooks(compilation.id()); + let chunk_ukey = self.chunk_ukey; + let res = block_on(async { + hooks + .create_script + .call(CreateScriptData { + code: create_script_code, + chunk: RuntimeModuleChunkWrapper { + chunk_ukey, + compilation_id: compilation.id(), + compilation: NonNull::from(compilation), }, - ) - .cow_replace("$FETCH_PRIORITY_SET_ATTRIBUTE$", if with_fetch_priority { - r#" - if(fetchPriority) { - script.setAttribute("fetchpriority", fetchPriority); - } - "# - } else { - "" - }) - .cow_replace("$FETCH_PRIORITY$", if with_fetch_priority { - ", fetchPriority" - } else { - "" }) - .cow_replace( - "$UNIQUE_SET_ATTRIBUTE$", - match unique_prefix { - Some(_) => r#"script.setAttribute("data-webpack", dataWebpackPrefix + key);"#, - None => "", - }, - ) - .cow_replace( - "$UNIQUE_PREFIX$", - unique_prefix.unwrap_or_default().as_str(), - ).into_owned(), + .await + })?; + + Ok( + RawStringSource::from( + include_str!("runtime/load_script.js") + .cow_replace("$CREATE_SCRIPT$", &res.code) + .cow_replace( + "$CHUNK_LOAD_TIMEOUT$", + &compilation.options.output.chunk_load_timeout.to_string(), + ) + .cow_replace( + "$FETCH_PRIORITY$", + if with_fetch_priority { + ", fetchPriority" + } else { + "" + }, + ) + .cow_replace( + "$UNIQUE_GET_ATTRIBUTE$", + match unique_prefix { + Some(_) => r#"s.getAttribute("src") == url || s.getAttribute("data-webpack") == dataWebpackPrefix + key"#, + None => r#"s.getAttribute("src") == url"#, + }, + ) + .cow_replace( + "$UNIQUE_PREFIX$", + unique_prefix.unwrap_or_default().as_str(), + ) + .into_owned(), + ) + .boxed(), ) - .boxed()) } } diff --git a/crates/rspack_plugin_runtime/src/runtime_module/runtime/jsonp_chunk_loading_with_prefetch.js b/crates/rspack_plugin_runtime/src/runtime_module/runtime/jsonp_chunk_loading_with_prefetch.js index ae594c9e6f24..3275bd18e1c2 100644 --- a/crates/rspack_plugin_runtime/src/runtime_module/runtime/jsonp_chunk_loading_with_prefetch.js +++ b/crates/rspack_plugin_runtime/src/runtime_module/runtime/jsonp_chunk_loading_with_prefetch.js @@ -1,14 +1,7 @@ __webpack_require__.F.j = function (chunkId) { if ((!__webpack_require__.o(installedChunks, chunkId) || installedChunks[chunkId] === undefined) && $JS_MATCHER$) { installedChunks[chunkId] = null; - var link = document.createElement('link'); - $CROSS_ORIGIN$ - if (__webpack_require__.nc) { - link.setAttribute("nonce", __webpack_require__.nc); - } - link.rel = "prefetch"; - link.as = "script"; - link.href = __webpack_require__.p + __webpack_require__.u(chunkId); + $LINK_PREFETCH$ document.head.appendChild(link); } }; diff --git a/crates/rspack_plugin_runtime/src/runtime_module/runtime/jsonp_chunk_loading_with_preload.js b/crates/rspack_plugin_runtime/src/runtime_module/runtime/jsonp_chunk_loading_with_preload.js index 910789c50e25..19b3d071dd05 100644 --- a/crates/rspack_plugin_runtime/src/runtime_module/runtime/jsonp_chunk_loading_with_preload.js +++ b/crates/rspack_plugin_runtime/src/runtime_module/runtime/jsonp_chunk_loading_with_preload.js @@ -1,15 +1,7 @@ __webpack_require__.H.j = function (chunkId) { if ((!__webpack_require__.o(installedChunks, chunkId) || installedChunks[chunkId] === undefined) && $JS_MATCHER$) { installedChunks[chunkId] = null; - var link = document.createElement('link'); - $SCRIPT_TYPE_LINK_PRE$ - link.charset = 'utf-8'; - if (__webpack_require__.nc) { - link.setAttribute("nonce", __webpack_require__.nc); - } - $SCRIPT_TYPE_LINK_POST$ - link.href = __webpack_require__.p + __webpack_require__.u(chunkId); - $CROSS_ORIGIN$ + $LINK_PRELOAD$ document.head.appendChild(link); } }; diff --git a/crates/rspack_plugin_runtime/src/runtime_module/runtime/load_script.js b/crates/rspack_plugin_runtime/src/runtime_module/runtime/load_script.js index 327c7858ab41..b0740cce037c 100644 --- a/crates/rspack_plugin_runtime/src/runtime_module/runtime/load_script.js +++ b/crates/rspack_plugin_runtime/src/runtime_module/runtime/load_script.js @@ -20,18 +20,7 @@ __webpack_require__.l = function (url, done, key, chunkId$FETCH_PRIORITY$) { } if (!script) { needAttach = true; - script = document.createElement('script'); - $SCRIPT_TYPE$ - $SCRIPT_CHARSET$ - script.timeout = $CHUNK_LOAD_TIMEOUT_IN_SECONDS$; - if (__webpack_require__.nc) { - script.setAttribute("nonce", __webpack_require__.nc); - } - $UNIQUE_SET_ATTRIBUTE$ - $FETCH_PRIORITY_SET_ATTRIBUTE$ - script.src = $URL$; - - __CROSS_ORIGIN_LOADING_PLACEHOLDER__ + $CREATE_SCRIPT$ } inProgress[url] = [done]; var onScriptComplete = function (prev, event) { diff --git a/crates/rspack_plugin_runtime/src/runtime_plugin.rs b/crates/rspack_plugin_runtime/src/runtime_plugin.rs index 48727cd9ea4a..e1bff18dbfe3 100644 --- a/crates/rspack_plugin_runtime/src/runtime_plugin.rs +++ b/crates/rspack_plugin_runtime/src/runtime_plugin.rs @@ -5,7 +5,7 @@ use async_trait::async_trait; use rspack_collections::DatabaseItem; use rspack_core::{ get_css_chunk_filename_template, get_js_chunk_filename_template, has_hash_placeholder, - ApplyContext, ChunkLoading, ChunkUkey, Compilation, CompilationParams, + ApplyContext, ChunkLoading, ChunkUkey, Compilation, CompilationId, CompilationParams, CompilationRuntimeRequirementInModule, CompilationRuntimeRequirementInTree, CompilerCompilation, CompilerOptions, ModuleIdentifier, Plugin, PluginContext, PublicPath, RuntimeGlobals, RuntimeModuleExt, SourceType, @@ -14,21 +14,28 @@ use rspack_error::Result; use rspack_hash::RspackHash; use rspack_hook::{plugin, plugin_hook}; use rspack_plugin_javascript::{JavascriptModulesChunkHash, JsPlugin}; +use rspack_util::fx_hash::FxDashMap; -use crate::runtime_module::{ - chunk_has_css, chunk_has_js, is_enabled_for_chunk, AmdDefineRuntimeModule, - AmdOptionsRuntimeModule, AsyncRuntimeModule, AutoPublicPathRuntimeModule, BaseUriRuntimeModule, - ChunkNameRuntimeModule, ChunkPrefetchPreloadFunctionRuntimeModule, - CompatGetDefaultExportRuntimeModule, CreateFakeNamespaceObjectRuntimeModule, - CreateScriptRuntimeModule, CreateScriptUrlRuntimeModule, DefinePropertyGettersRuntimeModule, - ESMModuleDecoratorRuntimeModule, EnsureChunkRuntimeModule, GetChunkFilenameRuntimeModule, - GetChunkUpdateFilenameRuntimeModule, GetFullHashRuntimeModule, GetMainFilenameRuntimeModule, - GetTrustedTypesPolicyRuntimeModule, GlobalRuntimeModule, HasOwnPropertyRuntimeModule, - LoadScriptRuntimeModule, MakeNamespaceObjectRuntimeModule, NodeModuleDecoratorRuntimeModule, - NonceRuntimeModule, OnChunkLoadedRuntimeModule, PublicPathRuntimeModule, - RelativeUrlRuntimeModule, RuntimeIdRuntimeModule, SystemContextRuntimeModule, +use crate::{ + runtime_module::{ + chunk_has_css, chunk_has_js, is_enabled_for_chunk, AmdDefineRuntimeModule, + AmdOptionsRuntimeModule, AsyncRuntimeModule, AutoPublicPathRuntimeModule, BaseUriRuntimeModule, + ChunkNameRuntimeModule, ChunkPrefetchPreloadFunctionRuntimeModule, + CompatGetDefaultExportRuntimeModule, CreateFakeNamespaceObjectRuntimeModule, + CreateScriptRuntimeModule, CreateScriptUrlRuntimeModule, DefinePropertyGettersRuntimeModule, + ESMModuleDecoratorRuntimeModule, EnsureChunkRuntimeModule, GetChunkFilenameRuntimeModule, + GetChunkUpdateFilenameRuntimeModule, GetFullHashRuntimeModule, GetMainFilenameRuntimeModule, + GetTrustedTypesPolicyRuntimeModule, GlobalRuntimeModule, HasOwnPropertyRuntimeModule, + LoadScriptRuntimeModule, MakeNamespaceObjectRuntimeModule, NodeModuleDecoratorRuntimeModule, + NonceRuntimeModule, OnChunkLoadedRuntimeModule, PublicPathRuntimeModule, + RelativeUrlRuntimeModule, RuntimeIdRuntimeModule, SystemContextRuntimeModule, + }, + RuntimePluginHooks, }; +static COMPILATION_HOOKS_MAP: LazyLock>> = + LazyLock::new(Default::default); + static GLOBALS_ON_REQUIRE: LazyLock> = LazyLock::new(|| { vec![ RuntimeGlobals::CHUNK_NAME, @@ -151,6 +158,25 @@ fn handle_dependency_globals( #[derive(Debug, Default)] pub struct RuntimePlugin; +impl RuntimePlugin { + pub fn get_compilation_hooks( + id: CompilationId, + ) -> dashmap::mapref::one::Ref<'static, CompilationId, Box> { + if !COMPILATION_HOOKS_MAP.contains_key(&id) { + COMPILATION_HOOKS_MAP.insert(id, Default::default()); + } + COMPILATION_HOOKS_MAP + .get(&id) + .expect("should have js plugin drive") + } + + pub fn get_compilation_hooks_mut( + compilation: &Compilation, + ) -> dashmap::mapref::one::RefMut<'_, CompilationId, Box> { + COMPILATION_HOOKS_MAP.entry(compilation.id()).or_default() + } +} + #[plugin_hook(CompilerCompilation for RuntimePlugin)] async fn compilation( &self, diff --git a/packages/rspack-test-tools/tests/__snapshots__/NewCodeSplitting-stats-output.test.js.snap b/packages/rspack-test-tools/tests/__snapshots__/NewCodeSplitting-stats-output.test.js.snap index ddb59115d681..65b4a84d3685 100644 --- a/packages/rspack-test-tools/tests/__snapshots__/NewCodeSplitting-stats-output.test.js.snap +++ b/packages/rspack-test-tools/tests/__snapshots__/NewCodeSplitting-stats-output.test.js.snap @@ -96,9 +96,9 @@ Rspack x.x.x compiled successfully in X s `; exports[`new code splitting stats output new code splitting stats output/filename should print correct stats for: NewCodeSplittingStatsOutput 1`] = ` -asset 909.xxxx.js 9.14 KiB [emitted] (name: main) +asset 909.xxxx.js 9.15 KiB [emitted] (name: main) asset 521.xxxx.js 322 bytes [emitted] -runtime modules 7.54 KiB 11 modules +runtime modules 7.55 KiB 11 modules cacheable modules 70 bytes ./index.js 38 bytes [built] [code generated] ./dynamic.js 32 bytes [built] [code generated] @@ -154,7 +154,7 @@ exports[`new code splitting stats output new code splitting stats output/limit-c chunk (runtime: main) 76.bundle2.js (c) 74 bytes <{76}> <{909}> >{76}< [rendered] dependent modules 44 bytes [dependent] 2 modules ./c.js 30 bytes [built] [code generated] - chunk (runtime: main) bundle2.js (main) 145 bytes (javascript) 8.73 KiB (runtime) >{76}< [entry] [rendered] + chunk (runtime: main) bundle2.js (main) 145 bytes (javascript) 8.74 KiB (runtime) >{76}< [entry] [rendered] dependent modules 22 bytes [dependent] 1 module ./index.js 123 bytes [built] [code generated] 2 chunks (Rspack x.x.x) compiled successfully in X s @@ -168,7 +168,7 @@ exports[`new code splitting stats output new code splitting stats output/limit-c ./e.js 22 bytes [built] [code generated] chunk (runtime: main) 76.bundle3.js (c) 30 bytes <{909}> >{345}< [rendered] ./c.js 30 bytes [built] [code generated] - chunk (runtime: main) bundle3.js (main) 145 bytes (javascript) 8.73 KiB (runtime) >{76}< [entry] [rendered] + chunk (runtime: main) bundle3.js (main) 145 bytes (javascript) 8.74 KiB (runtime) >{76}< [entry] [rendered] dependent modules 22 bytes [dependent] 1 module ./index.js 123 bytes [built] [code generated] 3 chunks (Rspack x.x.x) compiled successfully in X s @@ -184,7 +184,7 @@ exports[`new code splitting stats output new code splitting stats output/limit-c ./d.js 22 bytes [built] [code generated] chunk (runtime: main) 76.bundle4.js (c) 30 bytes <{909}> >{697}< >{753}< [rendered] ./c.js 30 bytes [built] [code generated] - chunk (runtime: main) bundle4.js (main) 145 bytes (javascript) 8.73 KiB (runtime) >{76}< [entry] [rendered] + chunk (runtime: main) bundle4.js (main) 145 bytes (javascript) 8.74 KiB (runtime) >{76}< [entry] [rendered] dependent modules 22 bytes [dependent] 1 module ./index.js 123 bytes [built] [code generated] 4 chunks (Rspack x.x.x) compiled successfully in X s @@ -217,7 +217,7 @@ Rspack compiled with 1 error `; exports[`new code splitting stats output new code splitting stats output/named-chunk-group should print correct stats for: NewCodeSplittingStatsOutput 1`] = ` -Entrypoint main 9.13 KiB = main.js +Entrypoint main 9.14 KiB = main.js Chunk Group cimanyd 322 bytes = cimanyd.js `; @@ -238,8 +238,8 @@ Entrypoint e2 10.6 KiB = e2.js chunk (runtime: e1) 0.js 24 bytes [rendered] chunk (runtime: e1) 1.js 52 bytes [rendered] chunk (runtime: e1, e2) 2.js 22 bytes [rendered] -chunk (runtime: e1) e1.js (e1) 74 bytes (javascript) 8.72 KiB (runtime) [entry] [rendered] -chunk (runtime: e2) e2.js (e2) 51 bytes (javascript) 8.72 KiB (runtime) [entry] [rendered] +chunk (runtime: e1) e1.js (e1) 74 bytes (javascript) 8.73 KiB (runtime) [entry] [rendered] +chunk (runtime: e2) e2.js (e2) 51 bytes (javascript) 8.73 KiB (runtime) [entry] [rendered] `; exports[`new code splitting stats output new code splitting stats output/optimization-runtime-chunk should print correct stats for: NewCodeSplittingStatsOutput 1`] = ` @@ -301,7 +301,7 @@ asset main.js 304 KiB [emitted] (name: main) asset 697.js 130 bytes [emitted] asset 753.js 130 bytes [emitted] Entrypoint main 304 KiB = main.js -runtime modules 8.72 KiB 12 modules +runtime modules 8.73 KiB 12 modules cacheable modules 293 KiB ./index.js 49 bytes [built] [code generated] ./a.js 293 KiB [built] [code generated] @@ -317,7 +317,7 @@ asset main.js 304 KiB [emitted] [big] (name: main) asset 697.js 130 bytes [emitted] asset 753.js 130 bytes [emitted] Entrypoint main [big] 304 KiB = main.js -runtime modules 8.72 KiB 12 modules +runtime modules 8.73 KiB 12 modules cacheable modules 293 KiB ./index.js 48 bytes [built] [code generated] ./a.js 293 KiB [built] [code generated] @@ -327,11 +327,11 @@ cacheable modules 293 KiB ./e.js 22 bytes [built] [code generated] ERROR in × asset size limit: The following asset(s) exceed the recommended size limit (244.141 KiB). This can impact web performance.Assets: - │ main.js (303.818 KiB) + │ main.js (303.829 KiB) ERROR in × entrypoint size limit: The following entrypoint(s) combined asset size exceeds the recommended limit (244.141 KiB). This can impact web performance.Entrypoints: - │ main (303.818 KiB) + │ main (303.829 KiB) │ main.js @@ -343,7 +343,7 @@ asset main.js 304 KiB [emitted] [big] (name: main) asset 697.js 130 bytes [emitted] asset 753.js 130 bytes [emitted] Entrypoint main [big] 304 KiB = main.js -runtime modules 8.72 KiB 12 modules +runtime modules 8.73 KiB 12 modules cacheable modules 293 KiB ./index.js 48 bytes [built] [code generated] ./a.js 293 KiB [built] [code generated] diff --git a/packages/rspack-test-tools/tests/__snapshots__/StatsOutput.test.js.snap b/packages/rspack-test-tools/tests/__snapshots__/StatsOutput.test.js.snap index 8731ad3a89ef..37cf420adb49 100644 --- a/packages/rspack-test-tools/tests/__snapshots__/StatsOutput.test.js.snap +++ b/packages/rspack-test-tools/tests/__snapshots__/StatsOutput.test.js.snap @@ -96,9 +96,9 @@ Rspack x.x.x compiled successfully in X s `; exports[`statsOutput statsOutput/filename should print correct stats for 1`] = ` -asset 909.xxxx.js 9.14 KiB [emitted] (name: main) +asset 909.xxxx.js 9.15 KiB [emitted] (name: main) asset 521.xxxx.js 322 bytes [emitted] -runtime modules 7.54 KiB 11 modules +runtime modules 7.55 KiB 11 modules cacheable modules 70 bytes ./index.js 38 bytes [built] [code generated] ./dynamic.js 32 bytes [built] [code generated] @@ -154,7 +154,7 @@ exports[`statsOutput statsOutput/limit-chunk-count-plugin should print correct s chunk (runtime: main) 76.bundle2.js (c) 74 bytes <{76}> <{909}> >{76}< [rendered] dependent modules 44 bytes [dependent] 2 modules ./c.js 30 bytes [built] [code generated] - chunk (runtime: main) bundle2.js (main) 145 bytes (javascript) 8.73 KiB (runtime) >{76}< [entry] [rendered] + chunk (runtime: main) bundle2.js (main) 145 bytes (javascript) 8.74 KiB (runtime) >{76}< [entry] [rendered] dependent modules 22 bytes [dependent] 1 module ./index.js 123 bytes [built] [code generated] 2 chunks (Rspack x.x.x) compiled successfully in X s @@ -168,7 +168,7 @@ exports[`statsOutput statsOutput/limit-chunk-count-plugin should print correct s ./e.js 22 bytes [built] [code generated] chunk (runtime: main) 76.bundle3.js (c) 30 bytes <{909}> >{345}< [rendered] ./c.js 30 bytes [built] [code generated] - chunk (runtime: main) bundle3.js (main) 145 bytes (javascript) 8.73 KiB (runtime) >{76}< [entry] [rendered] + chunk (runtime: main) bundle3.js (main) 145 bytes (javascript) 8.74 KiB (runtime) >{76}< [entry] [rendered] dependent modules 22 bytes [dependent] 1 module ./index.js 123 bytes [built] [code generated] 3 chunks (Rspack x.x.x) compiled successfully in X s @@ -184,7 +184,7 @@ exports[`statsOutput statsOutput/limit-chunk-count-plugin should print correct s ./d.js 22 bytes [built] [code generated] chunk (runtime: main) 76.bundle4.js (c) 30 bytes <{909}> >{697}< >{753}< [rendered] ./c.js 30 bytes [built] [code generated] - chunk (runtime: main) bundle4.js (main) 145 bytes (javascript) 8.73 KiB (runtime) >{76}< [entry] [rendered] + chunk (runtime: main) bundle4.js (main) 145 bytes (javascript) 8.74 KiB (runtime) >{76}< [entry] [rendered] dependent modules 22 bytes [dependent] 1 module ./index.js 123 bytes [built] [code generated] 4 chunks (Rspack x.x.x) compiled successfully in X s @@ -217,7 +217,7 @@ Rspack compiled with 1 error `; exports[`statsOutput statsOutput/named-chunk-group should print correct stats for 1`] = ` -Entrypoint main 9.13 KiB = main.js +Entrypoint main 9.14 KiB = main.js Chunk Group cimanyd 322 bytes = cimanyd.js `; @@ -238,8 +238,8 @@ Entrypoint e2 10.6 KiB = e2.js chunk (runtime: e1) 0.js 24 bytes [rendered] chunk (runtime: e1) 1.js 52 bytes [rendered] chunk (runtime: e1, e2) 2.js 22 bytes [rendered] -chunk (runtime: e1) e1.js (e1) 74 bytes (javascript) 8.72 KiB (runtime) [entry] [rendered] -chunk (runtime: e2) e2.js (e2) 51 bytes (javascript) 8.72 KiB (runtime) [entry] [rendered] +chunk (runtime: e1) e1.js (e1) 74 bytes (javascript) 8.73 KiB (runtime) [entry] [rendered] +chunk (runtime: e2) e2.js (e2) 51 bytes (javascript) 8.73 KiB (runtime) [entry] [rendered] `; exports[`statsOutput statsOutput/optimization-runtime-chunk should print correct stats for 1`] = ` @@ -301,7 +301,7 @@ asset main.js 304 KiB [emitted] (name: main) asset 697.js 130 bytes [emitted] asset 753.js 130 bytes [emitted] Entrypoint main 304 KiB = main.js -runtime modules 8.72 KiB 12 modules +runtime modules 8.73 KiB 12 modules cacheable modules 293 KiB ./index.js 49 bytes [built] [code generated] ./a.js 293 KiB [built] [code generated] @@ -317,7 +317,7 @@ asset main.js 304 KiB [emitted] [big] (name: main) asset 697.js 130 bytes [emitted] asset 753.js 130 bytes [emitted] Entrypoint main [big] 304 KiB = main.js -runtime modules 8.72 KiB 12 modules +runtime modules 8.73 KiB 12 modules cacheable modules 293 KiB ./index.js 48 bytes [built] [code generated] ./a.js 293 KiB [built] [code generated] @@ -327,11 +327,11 @@ cacheable modules 293 KiB ./e.js 22 bytes [built] [code generated] ERROR in × asset size limit: The following asset(s) exceed the recommended size limit (244.141 KiB). This can impact web performance.Assets: - │ main.js (303.818 KiB) + │ main.js (303.829 KiB) ERROR in × entrypoint size limit: The following entrypoint(s) combined asset size exceeds the recommended limit (244.141 KiB). This can impact web performance.Entrypoints: - │ main (303.818 KiB) + │ main (303.829 KiB) │ main.js @@ -343,7 +343,7 @@ asset main.js 304 KiB [emitted] [big] (name: main) asset 697.js 130 bytes [emitted] asset 753.js 130 bytes [emitted] Entrypoint main [big] 304 KiB = main.js -runtime modules 8.72 KiB 12 modules +runtime modules 8.73 KiB 12 modules cacheable modules 293 KiB ./index.js 48 bytes [built] [code generated] ./a.js 293 KiB [built] [code generated] diff --git a/packages/rspack-test-tools/tests/configCases/hooks/create-script/a.js b/packages/rspack-test-tools/tests/configCases/hooks/create-script/a.js new file mode 100644 index 000000000000..d852a426b2bf --- /dev/null +++ b/packages/rspack-test-tools/tests/configCases/hooks/create-script/a.js @@ -0,0 +1 @@ +export const a = 1; \ No newline at end of file diff --git a/packages/rspack-test-tools/tests/configCases/hooks/create-script/index.js b/packages/rspack-test-tools/tests/configCases/hooks/create-script/index.js new file mode 100644 index 000000000000..065ea085cb90 --- /dev/null +++ b/packages/rspack-test-tools/tests/configCases/hooks/create-script/index.js @@ -0,0 +1,5 @@ +it("should run", async () => { + import("./a.js"); + const script = document.head._children[0]; + expect(script.getAttribute("data-create-script-injected")).toBe("true"); +}); diff --git a/packages/rspack-test-tools/tests/configCases/hooks/create-script/rspack.config.js b/packages/rspack-test-tools/tests/configCases/hooks/create-script/rspack.config.js new file mode 100644 index 000000000000..c10afe3accc3 --- /dev/null +++ b/packages/rspack-test-tools/tests/configCases/hooks/create-script/rspack.config.js @@ -0,0 +1,21 @@ +/** @type {import('@rspack/core').Configuration} */ +module.exports = { + target: "web", + output: { + chunkLoading: "jsonp", + crossOriginLoading: "anonymous" + }, + plugins: [ + { + apply(compiler) { + const RuntimePlugin = compiler.webpack.RuntimePlugin; + compiler.hooks.compilation.tap("mock-plugin", compilation => { + const hooks = RuntimePlugin.getCompilationHooks(compilation); + hooks.createScript.tap("mock-plugin", (code, chunk) => { + return `${code}\nscript.setAttribute("data-create-script-injected", "true");`; + }); + }); + } + } + ] +}; diff --git a/packages/rspack-test-tools/tests/configCases/hooks/create-script/test.config.js b/packages/rspack-test-tools/tests/configCases/hooks/create-script/test.config.js new file mode 100644 index 000000000000..7ccc7bf8829b --- /dev/null +++ b/packages/rspack-test-tools/tests/configCases/hooks/create-script/test.config.js @@ -0,0 +1,3 @@ +module.exports = { + documentType: 'jsdom' +} diff --git a/packages/rspack-test-tools/tests/configCases/hooks/link-prefetch-preload/chunk1-a.js b/packages/rspack-test-tools/tests/configCases/hooks/link-prefetch-preload/chunk1-a.js new file mode 100644 index 000000000000..e69de29bb2d1 diff --git a/packages/rspack-test-tools/tests/configCases/hooks/link-prefetch-preload/chunk1-b.js b/packages/rspack-test-tools/tests/configCases/hooks/link-prefetch-preload/chunk1-b.js new file mode 100644 index 000000000000..e69de29bb2d1 diff --git a/packages/rspack-test-tools/tests/configCases/hooks/link-prefetch-preload/chunk1-c.js b/packages/rspack-test-tools/tests/configCases/hooks/link-prefetch-preload/chunk1-c.js new file mode 100644 index 000000000000..e69de29bb2d1 diff --git a/packages/rspack-test-tools/tests/configCases/hooks/link-prefetch-preload/chunk1.js b/packages/rspack-test-tools/tests/configCases/hooks/link-prefetch-preload/chunk1.js new file mode 100644 index 000000000000..60d6f1685b7d --- /dev/null +++ b/packages/rspack-test-tools/tests/configCases/hooks/link-prefetch-preload/chunk1.js @@ -0,0 +1,5 @@ +export default function() { + import(/* webpackPrefetch: true, webpackChunkName: "chunk1-a" */ "./chunk1-a"); + import(/* webpackPreload: true, webpackChunkName: "chunk1-b" */ "./chunk1-b"); + import(/* webpackPrefetch: 10, webpackChunkName: "chunk1-c" */ "./chunk1-c"); +} diff --git a/packages/rspack-test-tools/tests/configCases/hooks/link-prefetch-preload/chunk2.js b/packages/rspack-test-tools/tests/configCases/hooks/link-prefetch-preload/chunk2.js new file mode 100644 index 000000000000..a225cae317f4 --- /dev/null +++ b/packages/rspack-test-tools/tests/configCases/hooks/link-prefetch-preload/chunk2.js @@ -0,0 +1,4 @@ +export default function() { + import(/* webpackPrefetch: true, webpackChunkName: "chunk1-a" */ "./chunk1-a"); + import(/* webpackPreload: true, webpackChunkName: "chunk1-b" */ "./chunk1-b"); +} diff --git a/packages/rspack-test-tools/tests/configCases/hooks/link-prefetch-preload/index.js b/packages/rspack-test-tools/tests/configCases/hooks/link-prefetch-preload/index.js new file mode 100644 index 000000000000..d17e9cbc8374 --- /dev/null +++ b/packages/rspack-test-tools/tests/configCases/hooks/link-prefetch-preload/index.js @@ -0,0 +1,22 @@ +// This config need to be set on initial evaluation to be effective +__webpack_nonce__ = "nonce"; + +it("should prefetch and preload child chunks on chunk load", async () => { + let link, script; + + expect(document.head._children).toHaveLength(1); + + // Test prefetch from entry chunk + link = document.head._children[0]; + expect(link.getAttribute("data-prefetch-injected")).toBe("true"); + expect(link.getAttribute("data-preload-injected")).toBeFalsy(); + + const promise = import( + /* webpackChunkName: "chunk1", webpackPrefetch: true */ "./chunk1" + ); + + // Test preload of chunk1-b + link = document.head._children[2]; + expect(link.getAttribute("data-preload-injected")).toBe("true"); + expect(link.getAttribute("data-prefetch-injected")).toBeFalsy(); +}); diff --git a/packages/rspack-test-tools/tests/configCases/hooks/link-prefetch-preload/rspack.config.js b/packages/rspack-test-tools/tests/configCases/hooks/link-prefetch-preload/rspack.config.js new file mode 100644 index 000000000000..260e5bc5ae5c --- /dev/null +++ b/packages/rspack-test-tools/tests/configCases/hooks/link-prefetch-preload/rspack.config.js @@ -0,0 +1,24 @@ +/** @type {import("@rspack/core").Configuration} */ +module.exports = { + target: "web", + output: { + chunkFilename: "[name].js", + crossOriginLoading: "anonymous" + }, + plugins: [ + { + apply(compiler) { + const RuntimePlugin = compiler.webpack.RuntimePlugin; + compiler.hooks.compilation.tap("mock-plugin", compilation => { + const hooks = RuntimePlugin.getCompilationHooks(compilation); + hooks.linkPrefetch.tap("mock-plugin", (code, chunk) => { + return `${code}\nlink.setAttribute("data-prefetch-injected", "true");`; + }); + hooks.linkPreload.tap("mock-plugin", (code, chunk) => { + return `${code}\nlink.setAttribute("data-preload-injected", "true");`; + }); + }); + } + } + ] +}; diff --git a/packages/rspack-test-tools/tests/configCases/hooks/link-prefetch-preload/test.config.js b/packages/rspack-test-tools/tests/configCases/hooks/link-prefetch-preload/test.config.js new file mode 100644 index 000000000000..7ccc7bf8829b --- /dev/null +++ b/packages/rspack-test-tools/tests/configCases/hooks/link-prefetch-preload/test.config.js @@ -0,0 +1,3 @@ +module.exports = { + documentType: 'jsdom' +} diff --git a/packages/rspack-test-tools/tests/statsAPICases/chunk-group.js b/packages/rspack-test-tools/tests/statsAPICases/chunk-group.js index 754a5d3db9c9..2153f05f47bc 100644 --- a/packages/rspack-test-tools/tests/statsAPICases/chunk-group.js +++ b/packages/rspack-test-tools/tests/statsAPICases/chunk-group.js @@ -26,17 +26,17 @@ module.exports = { assets: Array [ Object { name: main.js, - size: 14505, + size: 14544, }, ], - assetsSize: 14505, + assetsSize: 14544, auxiliaryAssets: Array [ Object { name: main.js.map, - size: 684, + size: 689, }, ], - auxiliaryAssetsSize: 684, + auxiliaryAssetsSize: 689, childAssets: Object {}, children: Object { prefetch: Array [ @@ -215,17 +215,17 @@ module.exports = { assets: Array [ Object { name: main.js, - size: 14505, + size: 14544, }, ], - assetsSize: 14505, + assetsSize: 14544, auxiliaryAssets: Array [ Object { name: main.js.map, - size: 684, + size: 689, }, ], - auxiliaryAssetsSize: 684, + auxiliaryAssetsSize: 689, childAssets: Object {}, children: Object { prefetch: Array [ diff --git a/packages/rspack-test-tools/tests/statsAPICases/chunks.js b/packages/rspack-test-tools/tests/statsAPICases/chunks.js index a8e892fddc77..2cba1a3a91b8 100644 --- a/packages/rspack-test-tools/tests/statsAPICases/chunks.js +++ b/packages/rspack-test-tools/tests/statsAPICases/chunks.js @@ -150,7 +150,7 @@ module.exports = { main.js, ], filteredModules: undefined, - hash: ecb98ed10bf9b94d, + hash: 277ca3c6aa3cd84e, id: 909, idHints: Array [], initial: true, @@ -247,7 +247,7 @@ module.exports = { size: 85, sizes: Object { javascript: 85, - runtime: 9129, + runtime: 9140, }, type: chunk, }, diff --git a/packages/rspack/etc/core.api.md b/packages/rspack/etc/core.api.md index 45d55c530858..e5930c428552 100644 --- a/packages/rspack/etc/core.api.md +++ b/packages/rspack/etc/core.api.md @@ -5167,6 +5167,7 @@ declare namespace rspackExports { HotModuleReplacementPlugin, NoEmitOnErrorsPlugin, WarnCaseSensitiveModulesPlugin, + RuntimePlugin, DllPlugin, DllPluginOptions, DllReferencePlugin, @@ -9897,6 +9898,30 @@ enum RuntimeModuleStage { TRIGGER = 20 } +// @public (undocumented) +export const RuntimePlugin: typeof RuntimePluginImpl & { + getHooks: (compilation: Compilation) => RuntimePluginHooks; + getCompilationHooks: (compilation: Compilation) => RuntimePluginHooks; +}; + +// @public (undocumented) +type RuntimePluginHooks = { + createScript: liteTapable.SyncWaterfallHook<[string, Chunk]>; + linkPreload: liteTapable.SyncWaterfallHook<[string, Chunk]>; + linkPrefetch: liteTapable.SyncWaterfallHook<[string, Chunk]>; +}; + +// @public (undocumented) +const RuntimePluginImpl: { + new (): { + name: binding.BuiltinPluginName; + _args: []; + affectedHooks: "done" | "environment" | "make" | "compile" | "emit" | "afterEmit" | "invalid" | "thisCompilation" | "afterDone" | "compilation" | "normalModuleFactory" | "contextModuleFactory" | "initialize" | "shouldEmit" | "infrastructureLog" | "beforeRun" | "run" | "assetEmitted" | "failed" | "shutdown" | "watchRun" | "watchClose" | "afterEnvironment" | "afterPlugins" | "afterResolvers" | "beforeCompile" | "afterCompile" | "finishMake" | "entryOption" | "additionalPass" | undefined; + raw(compiler: Compiler_2): binding.BuiltinPlugin; + apply(compiler: Compiler_2): void; + }; +}; + // @public (undocumented) type RuntimePlugins = string[]; diff --git a/packages/rspack/src/Compiler.ts b/packages/rspack/src/Compiler.ts index 7c5e34a83077..922e3b4e64fa 100644 --- a/packages/rspack/src/Compiler.ts +++ b/packages/rspack/src/Compiler.ts @@ -19,7 +19,10 @@ import { __from_binding_runtime_globals, __to_binding_runtime_globals } from "./RuntimeGlobals"; -import { JsLoaderRspackPlugin } from "./builtin-plugin"; +import { + JsLoaderRspackPlugin, + createRuntimePluginHooksRegisters +} from "./builtin-plugin"; import type { Chunk } from "./Chunk"; import { Compilation } from "./Compilation"; @@ -849,7 +852,8 @@ class Compiler { createTap, createMapTap ), - ...createHtmlPluginHooksRegisters(getCompiler, createTap, createMapTap) + ...createHtmlPluginHooksRegisters(getCompiler, createTap, createMapTap), + ...createRuntimePluginHooksRegisters(getCompiler, createTap, createMapTap) }; } diff --git a/packages/rspack/src/builtin-plugin/RuntimePlugin.ts b/packages/rspack/src/builtin-plugin/RuntimePlugin.ts index 5a638e3141cb..9f34712b50ea 100644 --- a/packages/rspack/src/builtin-plugin/RuntimePlugin.ts +++ b/packages/rspack/src/builtin-plugin/RuntimePlugin.ts @@ -1,9 +1,98 @@ -import { BuiltinPluginName } from "@rspack/binding"; +import * as binding from "@rspack/binding"; +import * as liteTapable from "@rspack/lite-tapable"; +import { Chunk } from "../Chunk"; +import { Compilation } from "../Compilation"; +import type { CreatePartialRegisters } from "../taps/types"; import { create } from "./base"; -export const RuntimePlugin = create( - BuiltinPluginName.RuntimePlugin, +export const RuntimePluginImpl = create( + binding.BuiltinPluginName.RuntimePlugin, () => {}, "compilation" ); + +export type RuntimePluginHooks = { + createScript: liteTapable.SyncWaterfallHook<[string, Chunk]>; + linkPreload: liteTapable.SyncWaterfallHook<[string, Chunk]>; + linkPrefetch: liteTapable.SyncWaterfallHook<[string, Chunk]>; +}; + +const RuntimePlugin = RuntimePluginImpl as typeof RuntimePluginImpl & { + /** + * @deprecated Use `getCompilationHooks` instead. + */ + getHooks: (compilation: Compilation) => RuntimePluginHooks; + getCompilationHooks: (compilation: Compilation) => RuntimePluginHooks; +}; + +const compilationHooksMap: WeakMap = + new WeakMap(); + +RuntimePlugin.getHooks = RuntimePlugin.getCompilationHooks = ( + compilation: Compilation +) => { + if (!(compilation instanceof Compilation)) { + throw new TypeError( + "The 'compilation' argument must be an instance of Compilation" + ); + } + let hooks = compilationHooksMap.get(compilation); + if (hooks === undefined) { + hooks = { + createScript: new liteTapable.SyncWaterfallHook(["code", "chunk"]), + linkPreload: new liteTapable.SyncWaterfallHook(["code", "chunk"]), + linkPrefetch: new liteTapable.SyncWaterfallHook(["code", "chunk"]) + }; + compilationHooksMap.set(compilation, hooks); + } + return hooks; +}; + +export const createRuntimePluginHooksRegisters: CreatePartialRegisters< + `RuntimePlugin` +> = (getCompiler, createTap, createMapTap) => { + return { + registerRuntimePluginCreateScriptTaps: createTap( + binding.RegisterJsTapKind.RuntimePluginCreateScript, + function () { + return RuntimePlugin.getCompilationHooks( + getCompiler().__internal__get_compilation()! + ).createScript; + }, + function (queried) { + return function (data: binding.JsCreateScriptData) { + return queried.call(data.code, Chunk.__from_binding(data.chunk)); + }; + } + ), + registerRuntimePluginLinkPreloadTaps: createTap( + binding.RegisterJsTapKind.RuntimePluginLinkPreload, + function () { + return RuntimePlugin.getCompilationHooks( + getCompiler().__internal__get_compilation()! + ).linkPreload; + }, + function (queried) { + return function (data: binding.JsLinkPreloadData) { + return queried.call(data.code, Chunk.__from_binding(data.chunk)); + }; + } + ), + registerRuntimePluginLinkPrefetchTaps: createTap( + binding.RegisterJsTapKind.RuntimePluginLinkPrefetch, + function () { + return RuntimePlugin.getCompilationHooks( + getCompiler().__internal__get_compilation()! + ).linkPrefetch; + }, + function (queried) { + return function (data: binding.JsLinkPrefetchData) { + return queried.call(data.code, Chunk.__from_binding(data.chunk)); + }; + } + ) + }; +}; + +export { RuntimePlugin }; diff --git a/packages/rspack/src/exports.ts b/packages/rspack/src/exports.ts index 9ca4bbacab42..9dbe81ad4847 100644 --- a/packages/rspack/src/exports.ts +++ b/packages/rspack/src/exports.ts @@ -104,6 +104,7 @@ export { ExternalsPlugin } from "./builtin-plugin"; export { HotModuleReplacementPlugin } from "./builtin-plugin"; export { NoEmitOnErrorsPlugin } from "./builtin-plugin"; export { WarnCaseSensitiveModulesPlugin } from "./builtin-plugin"; +export { RuntimePlugin } from "./builtin-plugin"; export { DllPlugin, type DllPluginOptions } from "./lib/DllPlugin"; export { DllReferencePlugin, diff --git a/tests/plugin-test/css-extract/cases/chunkFilename-fullhash/expected/async.$d026823092eb39bd50f7$.css b/tests/plugin-test/css-extract/cases/chunkFilename-fullhash/expected/async.$f4608fdcfef13de69f10$.css similarity index 100% rename from tests/plugin-test/css-extract/cases/chunkFilename-fullhash/expected/async.$d026823092eb39bd50f7$.css rename to tests/plugin-test/css-extract/cases/chunkFilename-fullhash/expected/async.$f4608fdcfef13de69f10$.css diff --git a/tests/plugin-test/css-extract/cases/chunkFilename-fullhash/expected/main.$d026823092eb39bd50f7$.css b/tests/plugin-test/css-extract/cases/chunkFilename-fullhash/expected/main.$f4608fdcfef13de69f10$.css similarity index 100% rename from tests/plugin-test/css-extract/cases/chunkFilename-fullhash/expected/main.$d026823092eb39bd50f7$.css rename to tests/plugin-test/css-extract/cases/chunkFilename-fullhash/expected/main.$f4608fdcfef13de69f10$.css diff --git a/tests/plugin-test/css-extract/cases/chunkFilename-fullhash/expected/main.js b/tests/plugin-test/css-extract/cases/chunkFilename-fullhash/expected/main.js index 2f1c98306662..7eea77a3c270 100644 --- a/tests/plugin-test/css-extract/cases/chunkFilename-fullhash/expected/main.js +++ b/tests/plugin-test/css-extract/cases/chunkFilename-fullhash/expected/main.js @@ -77,7 +77,7 @@ __webpack_require__.e = function (chunkId) { // webpack/runtime/get_full_hash (() => { __webpack_require__.h = function () { - return "d026823092eb39bd50f7"; + return "f4608fdcfef13de69f10"; }; })(); @@ -124,8 +124,9 @@ __webpack_require__.l = function (url, done, key, chunkId) { } if (!script) { needAttach = true; - script = document.createElement('script'); + script = document.createElement('script'); + script.charset = 'utf-8'; script.timeout = 120; if (__webpack_require__.nc) { @@ -134,8 +135,8 @@ __webpack_require__.l = function (url, done, key, chunkId) { script.src = url; - + } inProgress[url] = [done]; var onScriptComplete = function (prev, event) { diff --git a/tests/plugin-test/css-extract/cases/hmr-locals/expected/main.js b/tests/plugin-test/css-extract/cases/hmr-locals/expected/main.js index b471d783b314..68126974ad4d 100644 --- a/tests/plugin-test/css-extract/cases/hmr-locals/expected/main.js +++ b/tests/plugin-test/css-extract/cases/hmr-locals/expected/main.js @@ -758,8 +758,9 @@ __webpack_require__.l = function (url, done, key, chunkId) { } if (!script) { needAttach = true; - script = document.createElement('script'); + script = document.createElement('script'); + script.charset = 'utf-8'; script.timeout = 120; if (__webpack_require__.nc) { @@ -768,8 +769,8 @@ __webpack_require__.l = function (url, done, key, chunkId) { script.src = url; - + } inProgress[url] = [done]; var onScriptComplete = function (prev, event) { diff --git a/tests/plugin-test/css-extract/cases/hmr/expected/main.js b/tests/plugin-test/css-extract/cases/hmr/expected/main.js index 8a924f282b0d..a5dcc4901c96 100644 --- a/tests/plugin-test/css-extract/cases/hmr/expected/main.js +++ b/tests/plugin-test/css-extract/cases/hmr/expected/main.js @@ -743,8 +743,9 @@ __webpack_require__.l = function (url, done, key, chunkId) { } if (!script) { needAttach = true; - script = document.createElement('script'); + script = document.createElement('script'); + script.charset = 'utf-8'; script.timeout = 120; if (__webpack_require__.nc) { @@ -753,8 +754,8 @@ __webpack_require__.l = function (url, done, key, chunkId) { script.src = url; - + } inProgress[url] = [done]; var onScriptComplete = function (prev, event) { diff --git a/tests/plugin-test/css-extract/cases/insert-function/expected/main.js b/tests/plugin-test/css-extract/cases/insert-function/expected/main.js index 88d6288130ab..fd661c44b7d5 100644 --- a/tests/plugin-test/css-extract/cases/insert-function/expected/main.js +++ b/tests/plugin-test/css-extract/cases/insert-function/expected/main.js @@ -108,8 +108,9 @@ __webpack_require__.l = function (url, done, key, chunkId) { } if (!script) { needAttach = true; - script = document.createElement('script'); + script = document.createElement('script'); + script.charset = 'utf-8'; script.timeout = 120; if (__webpack_require__.nc) { @@ -118,8 +119,8 @@ __webpack_require__.l = function (url, done, key, chunkId) { script.src = url; - + } inProgress[url] = [done]; var onScriptComplete = function (prev, event) { diff --git a/tests/plugin-test/css-extract/cases/insert-string/expected/main.js b/tests/plugin-test/css-extract/cases/insert-string/expected/main.js index a150581e1783..0c219fdf74e7 100644 --- a/tests/plugin-test/css-extract/cases/insert-string/expected/main.js +++ b/tests/plugin-test/css-extract/cases/insert-string/expected/main.js @@ -108,8 +108,9 @@ __webpack_require__.l = function (url, done, key, chunkId) { } if (!script) { needAttach = true; - script = document.createElement('script'); + script = document.createElement('script'); + script.charset = 'utf-8'; script.timeout = 120; if (__webpack_require__.nc) { @@ -118,8 +119,8 @@ __webpack_require__.l = function (url, done, key, chunkId) { script.src = url; - + } inProgress[url] = [done]; var onScriptComplete = function (prev, event) { diff --git a/tests/plugin-test/css-extract/cases/insert-undefined/expected/main.js b/tests/plugin-test/css-extract/cases/insert-undefined/expected/main.js index 471233a1fda4..368cf43f95c6 100644 --- a/tests/plugin-test/css-extract/cases/insert-undefined/expected/main.js +++ b/tests/plugin-test/css-extract/cases/insert-undefined/expected/main.js @@ -108,8 +108,9 @@ __webpack_require__.l = function (url, done, key, chunkId) { } if (!script) { needAttach = true; - script = document.createElement('script'); + script = document.createElement('script'); + script.charset = 'utf-8'; script.timeout = 120; if (__webpack_require__.nc) { @@ -118,8 +119,8 @@ __webpack_require__.l = function (url, done, key, chunkId) { script.src = url; - + } inProgress[url] = [done]; var onScriptComplete = function (prev, event) { diff --git a/tests/plugin-test/css-extract/cases/issue-6649/expected/main.js b/tests/plugin-test/css-extract/cases/issue-6649/expected/main.js index 42c1642fe3dc..cdcffc29cdcd 100644 --- a/tests/plugin-test/css-extract/cases/issue-6649/expected/main.js +++ b/tests/plugin-test/css-extract/cases/issue-6649/expected/main.js @@ -107,7 +107,7 @@ __webpack_require__.e = function (chunkId) { // webpack/runtime/get_full_hash (() => { __webpack_require__.h = function () { - return "950959268269901ed8e8"; + return "da63e7bb2bfca29ff73b"; }; })(); @@ -154,8 +154,9 @@ __webpack_require__.l = function (url, done, key, chunkId) { } if (!script) { needAttach = true; - script = document.createElement('script'); + script = document.createElement('script'); + script.charset = 'utf-8'; script.timeout = 120; if (__webpack_require__.nc) { @@ -164,8 +165,8 @@ __webpack_require__.l = function (url, done, key, chunkId) { script.src = url; - + } inProgress[url] = [done]; var onScriptComplete = function (prev, event) { diff --git a/tests/plugin-test/css-extract/cases/no-runtime/expected/main.js b/tests/plugin-test/css-extract/cases/no-runtime/expected/main.js index e5719db7a739..5dec33303d7d 100644 --- a/tests/plugin-test/css-extract/cases/no-runtime/expected/main.js +++ b/tests/plugin-test/css-extract/cases/no-runtime/expected/main.js @@ -106,8 +106,9 @@ __webpack_require__.l = function (url, done, key, chunkId) { } if (!script) { needAttach = true; - script = document.createElement('script'); + script = document.createElement('script'); + script.charset = 'utf-8'; script.timeout = 120; if (__webpack_require__.nc) { @@ -116,8 +117,8 @@ __webpack_require__.l = function (url, done, key, chunkId) { script.src = url; - + } inProgress[url] = [done]; var onScriptComplete = function (prev, event) { diff --git a/tests/plugin-test/css-extract/cases/runtime/expected/runtime~main.js b/tests/plugin-test/css-extract/cases/runtime/expected/runtime~main.js index 6a90b5965a47..3f4afe80dab8 100644 --- a/tests/plugin-test/css-extract/cases/runtime/expected/runtime~main.js +++ b/tests/plugin-test/css-extract/cases/runtime/expected/runtime~main.js @@ -148,8 +148,9 @@ __webpack_require__.l = function (url, done, key, chunkId) { } if (!script) { needAttach = true; - script = document.createElement('script'); + script = document.createElement('script'); + script.charset = 'utf-8'; script.timeout = 120; if (__webpack_require__.nc) { @@ -158,8 +159,8 @@ __webpack_require__.l = function (url, done, key, chunkId) { script.src = url; - + } inProgress[url] = [done]; var onScriptComplete = function (prev, event) { diff --git a/tests/webpack-test/__snapshots__/StatsTestCases.basictest.js.snap b/tests/webpack-test/__snapshots__/StatsTestCases.basictest.js.snap index 817ef8799add..d455489e5f9f 100644 --- a/tests/webpack-test/__snapshots__/StatsTestCases.basictest.js.snap +++ b/tests/webpack-test/__snapshots__/StatsTestCases.basictest.js.snap @@ -49,7 +49,7 @@ exports[`StatsTestCases should print correct stats for async-commons-chunk-auto > ./b ./index.js 2:0-47 dependent modules 80 bytes [dependent] 4 modules ./b.js 116 bytes [built] [code generated] - chunk (runtime: a) disabled/a.js (a) 165 bytes (javascript) 7.28 KiB (runtime) [entry] [rendered] + chunk (runtime: a) disabled/a.js (a) 165 bytes (javascript) 7.29 KiB (runtime) [entry] [rendered] > ./a a ./a.js 165 bytes [built] [code generated] chunk (runtime: b) disabled/b.js (b) 116 bytes [entry] [rendered] @@ -58,7 +58,7 @@ exports[`StatsTestCases should print correct stats for async-commons-chunk-auto chunk (runtime: c) disabled/c.js (c) 116 bytes [entry] [rendered] > ./c c ./c.js 116 bytes [built] [code generated] - chunk (runtime: main) disabled/main.js (main) 147 bytes (javascript) 7.35 KiB (runtime) [entry] [rendered] + chunk (runtime: main) disabled/main.js (main) 147 bytes (javascript) 7.36 KiB (runtime) [entry] [rendered] > ./ main ./index.js 147 bytes [built] [code generated] chunk (runtime: a, main) disabled/async-g.js (async-g) 65 bytes [rendered] @@ -95,7 +95,7 @@ default: > ./c ./index.js 3:0-47 > ./g ./a.js 6:0-47 ./f.js 20 bytes [built] [code generated] - chunk (runtime: a) default/a.js (a) 165 bytes (javascript) 7.31 KiB (runtime) [entry] [rendered] + chunk (runtime: a) default/a.js (a) 165 bytes (javascript) 7.32 KiB (runtime) [entry] [rendered] > ./a a ./a.js 165 bytes [built] [code generated] chunk (runtime: b) default/b.js (b) 116 bytes [entry] [rendered] @@ -109,7 +109,7 @@ default: chunk (runtime: c) default/c.js (c) 116 bytes [entry] [rendered] > ./c c ./c.js 116 bytes [built] [code generated] - chunk (runtime: main) default/main.js (main) 147 bytes (javascript) 7.36 KiB (runtime) [entry] [rendered] + chunk (runtime: main) default/main.js (main) 147 bytes (javascript) 7.38 KiB (runtime) [entry] [rendered] > ./ main ./index.js 147 bytes [built] [code generated] chunk (runtime: a, main) default/async-g.js (async-g) 45 bytes [rendered] @@ -130,7 +130,7 @@ vendors: > ./b ./index.js 2:0-47 dependent modules 80 bytes [dependent] 4 modules ./b.js 116 bytes [built] [code generated] - chunk (runtime: a) vendors/a.js (a) 165 bytes (javascript) 7.28 KiB (runtime) [entry] [rendered] + chunk (runtime: a) vendors/a.js (a) 165 bytes (javascript) 7.29 KiB (runtime) [entry] [rendered] > ./a a ./a.js 165 bytes [built] [code generated] chunk (runtime: b) vendors/b.js (b) 116 bytes [entry] [rendered] @@ -139,7 +139,7 @@ vendors: chunk (runtime: c) vendors/c.js (c) 116 bytes [entry] [rendered] > ./c c ./c.js 116 bytes [built] [code generated] - chunk (runtime: main) vendors/main.js (main) 147 bytes (javascript) 7.35 KiB (runtime) [entry] [rendered] + chunk (runtime: main) vendors/main.js (main) 147 bytes (javascript) 7.36 KiB (runtime) [entry] [rendered] > ./ main ./index.js 147 bytes [built] [code generated] chunk (runtime: a, main) vendors/async-g.js (async-g) 65 bytes [rendered] @@ -213,7 +213,7 @@ all: chunk (runtime: b) all/726.js (id hint: vendors) 116 bytes [initial] [rendered] split chunk (cache group: vendors) > ./b b ./b.js 116 bytes [built] [code generated] - chunk (runtime: a) all/a.js (a) 8.36 KiB [entry] [rendered] + chunk (runtime: a) all/a.js (a) 8.37 KiB [entry] [rendered] > ./a a chunk (runtime: b) all/b.js (b) 2.58 KiB [entry] [rendered] > ./b b @@ -222,7 +222,7 @@ all: chunk (runtime: a, main) all/889.js (id hint: vendors) 45 bytes [rendered] split chunk (cache group: vendors) > ./g ./a.js 6:0-47 ./g.js 45 bytes [built] [code generated] - chunk (runtime: main) all/main.js (main) 8.36 KiB [entry] [rendered] + chunk (runtime: main) all/main.js (main) 8.37 KiB [entry] [rendered] > ./ main chunk (runtime: main) all/910.js (id hint: vendors) 185 bytes [rendered] split chunk (cache group: vendors) > ./a ./index.js 1:0-47 @@ -251,7 +251,7 @@ chunk (runtime: main) 751.bundle.js (b) 49 bytes <{76}> <{909}> >{76}< [rendered ./module-b.js 49 bytes [built] [code generated] chunk (runtime: main) 76.bundle.js (c) 98 bytes <{74}> <{751}> >{74}< >{751}< [rendered] ./module-c.js 98 bytes [built] [code generated] -chunk (runtime: main) bundle.js (main) 98 bytes (javascript) 8.45 KiB (runtime) >{74}< >{751}< [entry] [rendered] +chunk (runtime: main) bundle.js (main) 98 bytes (javascript) 8.46 KiB (runtime) >{74}< >{751}< [entry] [rendered] ./index.js 98 bytes [built] [code generated] Rspack x.x.x compiled successfully" `; @@ -356,7 +356,7 @@ Rspack x.x.x compiled successfully in X.23" `; exports[`StatsTestCases should print correct stats for graph-correctness-entries 1`] = ` -"chunk (runtime: e1) e1.js (e1) 49 bytes (javascript) 8.48 KiB (runtime) >{74}< [entry] [rendered] +"chunk (runtime: e1) e1.js (e1) 49 bytes (javascript) 8.49 KiB (runtime) >{74}< [entry] [rendered] ./e1.js 49 bytes [built] [code generated] entry ./e1 chunk (runtime: e1, e2) a.js (a) 49 bytes <{605}> <{76}> >{751}< [rendered] @@ -370,14 +370,14 @@ chunk (runtime: e1, e2) c.js (c) 49 bytes <{751}> <{844}> >{74}< [rendered] ./module-c.js 49 bytes [built] [code generated] import() ./module-c ./e2.js import() ./module-c ./module-b.js -chunk (runtime: e2) e2.js (e2) 49 bytes (javascript) 8.48 KiB (runtime) >{76}< [entry] [rendered] +chunk (runtime: e2) e2.js (e2) 49 bytes (javascript) 8.49 KiB (runtime) >{76}< [entry] [rendered] ./e2.js 49 bytes [built] [code generated] entry ./e2 Rspack x.x.x compiled successfully" `; exports[`StatsTestCases should print correct stats for graph-correctness-modules 1`] = ` -"chunk (runtime: e1) e1.js (e1) 119 bytes (javascript) 8.79 KiB (runtime) >{74}< >{984}< [entry] [rendered] +"chunk (runtime: e1) e1.js (e1) 119 bytes (javascript) 8.8 KiB (runtime) >{74}< >{984}< [entry] [rendered] ./e1.js 70 bytes [built] [code generated] entry ./e1 ./module-x.js 49 bytes [dependent] [built] [code generated] @@ -395,7 +395,7 @@ chunk (runtime: e1, e2) c.js (c) 49 bytes <{751}> <{844}> >{74}< [rendered] ./module-c.js 49 bytes [built] [code generated] import() ./module-c ./e2.js import() ./module-c ./module-b.js -chunk (runtime: e2) e2.js (e2) 119 bytes (javascript) 8.79 KiB (runtime) >{76}< >{984}< [entry] [rendered] +chunk (runtime: e2) e2.js (e2) 119 bytes (javascript) 8.8 KiB (runtime) >{76}< >{984}< [entry] [rendered] ./e2.js 70 bytes [built] [code generated] entry ./e2 ./module-x.js 49 bytes [dependent] [built] [code generated] @@ -434,7 +434,7 @@ chunk (runtime: main) id-equals-name_js0.js 21 bytes [rendered] ./id-equals-name.js 21 bytes [built] [code generated] chunk (runtime: main) id-equals-name_js_3.js 21 bytes [rendered] ./id-equals-name.js?3 21 bytes [built] [code generated] -chunk (runtime: main) main.js (main) 639 bytes (javascript) 7.27 KiB (runtime) [entry] [rendered] +chunk (runtime: main) main.js (main) 639 bytes (javascript) 7.28 KiB (runtime) [entry] [rendered] ./index.js 639 bytes [built] [code generated] chunk (runtime: main) tree.js (tree) 137 bytes [rendered] dependent modules 98 bytes [dependent] 3 modules @@ -454,7 +454,7 @@ Rspack x.x.x compiled successfully in X.23" `; exports[`StatsTestCases should print correct stats for immutable 1`] = ` -"asset a309a604082e563a.js 10.4 KiB [emitted] [immutable] (name: main) +"asset 7d308f468b6a0d1b.js 10.4 KiB [emitted] [immutable] (name: main) asset 7342054f673663df.js 167 bytes [emitted] [immutable]" `; @@ -463,7 +463,7 @@ exports[`StatsTestCases should print correct stats for import-context-filter 1`] asset 228.js 407 bytes [emitted] asset 271.js 407 bytes [emitted] asset 536.js 407 bytes [emitted] -runtime modules 7.27 KiB 9 modules +runtime modules 7.28 KiB 9 modules cacheable modules 724 bytes modules by path ./templates/*.js 114 bytes ./templates/bar.js 38 bytes [built] [code generated] @@ -478,7 +478,7 @@ exports[`StatsTestCases should print correct stats for import-weak 1`] = ` "asset entry.js 10.2 KiB [emitted] (name: entry) asset 332.js 285 bytes [emitted] asset 313.js 130 bytes [emitted] -runtime modules 8.44 KiB 10 modules +runtime modules 8.46 KiB 10 modules cacheable modules 179 bytes ./entry.js 120 bytes [built] [code generated] ./modules/a.js 37 bytes [built] [code generated] @@ -490,7 +490,7 @@ exports[`StatsTestCases should print correct stats for import-weak-parser-option "asset entry.js 10.2 KiB [emitted] (name: entry) asset 332.js 285 bytes [emitted] asset 313.js 130 bytes [emitted] -runtime modules 8.44 KiB 10 modules +runtime modules 8.46 KiB 10 modules cacheable modules 153 bytes ./entry.js 94 bytes [built] [code generated] ./modules/a.js 37 bytes [built] [code generated] @@ -499,7 +499,7 @@ Rspack x.x.x compiled successfully in X.23" `; exports[`StatsTestCases should print correct stats for import-with-invalid-options-comments 1`] = ` -"runtime modules 9.49 KiB 12 modules +"runtime modules 9.51 KiB 12 modules cacheable modules 559 bytes ./index.js 50 bytes [built] [code generated] ./chunk.js 401 bytes [built] [code generated] [2 warnings] @@ -560,11 +560,11 @@ Rspack x.x.x compiled successfully in X.23 assets by chunk 862 bytes (id hint: all) asset c-all-b_js-b683c5304b71900e.js 480 bytes [emitted] [immutable] (id hint: all) asset c-all-c_js-2c876c6ecab93d9b.js 382 bytes [emitted] [immutable] (id hint: all) -asset c-runtime~main-d7f987785eb841d4.js 11.1 KiB [emitted] [immutable] (name: runtime~main) +asset c-runtime~main-cf6fa4193cfaab7e.js 11.1 KiB [emitted] [immutable] (name: runtime~main) asset c-main-1b0ba12f79ed8053.js 643 bytes [emitted] [immutable] (name: main) asset c-vendors-node_modules_vendor_js-8e4df31a4698ceb4.js 173 bytes [emitted] [immutable] (id hint: vendors) -Entrypoint main 12.1 KiB = c-runtime~main-d7f987785eb841d4.js 11.1 KiB c-all-c_js-2c876c6ecab93d9b.js 382 bytes c-main-1b0ba12f79ed8053.js 643 bytes -runtime modules 9.7 KiB 13 modules +Entrypoint main 12.1 KiB = c-runtime~main-cf6fa4193cfaab7e.js 11.1 KiB c-all-c_js-2c876c6ecab93d9b.js 382 bytes c-main-1b0ba12f79ed8053.js 643 bytes +runtime modules 9.73 KiB 13 modules cacheable modules 101 bytes ./c.js 61 bytes [built] [code generated] ./b.js 17 bytes [built] [code generated] @@ -594,7 +594,7 @@ exports[`StatsTestCases should print correct stats for limit-chunk-count-plugin ./a.js 22 bytes [built] [code generated] ./b.js 22 bytes [built] [code generated] ./c.js 30 bytes [built] [code generated] - chunk (runtime: main) bundle2.js (main) 101 bytes (javascript) 8.45 KiB (runtime) >{76}< [entry] [rendered] + chunk (runtime: main) bundle2.js (main) 101 bytes (javascript) 8.46 KiB (runtime) >{76}< [entry] [rendered] ./index.js 101 bytes [built] [code generated] 2 chunks (Rspack x.x.x) compiled successfully in X.23 @@ -609,7 +609,7 @@ exports[`StatsTestCases should print correct stats for limit-chunk-count-plugin ./e.js 22 bytes [built] [code generated] chunk (runtime: main) 76.bundle3.js (c) 30 bytes <{909}> >{656}< [rendered] ./c.js 30 bytes [built] [code generated] - chunk (runtime: main) bundle3.js (main) 101 bytes (javascript) 8.45 KiB (runtime) >{656}< >{76}< [entry] [rendered] + chunk (runtime: main) bundle3.js (main) 101 bytes (javascript) 8.46 KiB (runtime) >{656}< >{76}< [entry] [rendered] ./index.js 101 bytes [built] [code generated] 3 chunks (Rspack x.x.x) compiled successfully in X.23 @@ -626,7 +626,7 @@ exports[`StatsTestCases should print correct stats for limit-chunk-count-plugin ./e.js 22 bytes [built] [code generated] chunk (runtime: main) 76.bundle4.js (c) 30 bytes <{909}> >{537}< >{697}< [rendered] ./c.js 30 bytes [built] [code generated] - chunk (runtime: main) bundle4.js (main) 101 bytes (javascript) 8.45 KiB (runtime) >{537}< >{76}< [entry] [rendered] + chunk (runtime: main) bundle4.js (main) 101 bytes (javascript) 8.46 KiB (runtime) >{537}< >{76}< [entry] [rendered] ./index.js 101 bytes [built] [code generated] 4 chunks (Rspack x.x.x) compiled successfully in X.23" `; @@ -684,23 +684,23 @@ Rspack x.x.x compiled successfully in X.23" `; exports[`StatsTestCases should print correct stats for module-assets 1`] = ` -"assets by path *.js 9.02 KiB - asset main.js 8.58 KiB [emitted] (name: main) +"assets by path *.js 9.03 KiB + asset main.js 8.59 KiB [emitted] (name: main) asset b.js 226 bytes [emitted] (name: b) asset a.js 225 bytes [emitted] (name: a) assets by path *.png 42 KiB asset 1.png 21 KiB [emitted] [from: node_modules/a/1.png] asset 2.png 21 KiB [emitted] [from: node_modules/a/2.png] -Entrypoint main 8.58 KiB = main.js +Entrypoint main 8.59 KiB = main.js Chunk Group a 225 bytes = a.js Chunk Group b 226 bytes = b.js chunk (runtime: main) a.js (a) 36 bytes [rendered] ./node_modules/a/index.js 36 bytes [built] [code generated] chunk (runtime: main) b.js (b) 18 bytes [rendered] ./node_modules/b/index.js 18 bytes [built] [code generated] -chunk (runtime: main) main.js (main) 82 bytes (javascript) 7.01 KiB (runtime) [entry] [rendered] +chunk (runtime: main) main.js (main) 82 bytes (javascript) 7.02 KiB (runtime) [entry] [rendered] ./index.js 82 bytes [built] [code generated] -runtime modules 7.01 KiB 8 modules +runtime modules 7.02 KiB 8 modules orphan modules 98 bytes [orphan] 2 modules modules with assets 136 bytes ./index.js 82 bytes [built] [code generated] @@ -710,9 +710,9 @@ Rspack x.x.x compiled successfully in X.23" `; exports[`StatsTestCases should print correct stats for module-deduplication 1`] = ` -"asset e1.js 9.98 KiB [emitted] (name: e1) -asset e2.js 9.98 KiB [emitted] (name: e2) -asset e3.js 9.98 KiB [emitted] (name: e3) +"asset e1.js 9.99 KiB [emitted] (name: e1) +asset e2.js 9.99 KiB [emitted] (name: e2) +asset e3.js 9.99 KiB [emitted] (name: e3) asset 106.js 753 bytes [emitted] asset 511.js 753 bytes [emitted] asset 637.js 753 bytes [emitted] @@ -729,20 +729,20 @@ chunk (runtime: e3) 400.js 61 bytes [rendered] chunk (runtime: e1, e3) 511.js 81 bytes [rendered] ./async2.js 61 bytes [built] [code generated] ./f.js 20 bytes [dependent] [built] [code generated] -chunk (runtime: e1) e1.js (e1) 249 bytes (javascript) 7.27 KiB (runtime) [entry] [rendered] +chunk (runtime: e1) e1.js (e1) 249 bytes (javascript) 7.28 KiB (runtime) [entry] [rendered] ./b.js 20 bytes [dependent] [built] [code generated] ./d.js 20 bytes [dependent] [built] [code generated] ./e1.js + 2 modules 209 bytes [code generated] chunk (runtime: e2, e3) 637.js 81 bytes [rendered] ./async1.js 61 bytes [built] [code generated] ./d.js 20 bytes [dependent] [built] [code generated] -chunk (runtime: e3) e3.js (e3) 249 bytes (javascript) 7.27 KiB (runtime) [entry] [rendered] +chunk (runtime: e3) e3.js (e3) 249 bytes (javascript) 7.28 KiB (runtime) [entry] [rendered] ./b.js 20 bytes [dependent] [built] [code generated] ./e3.js + 2 modules 209 bytes [code generated] ./h.js 20 bytes [dependent] [built] [code generated] chunk (runtime: e2) 806.js 61 bytes [rendered] ./async2.js 61 bytes [built] [code generated] -chunk (runtime: e2) e2.js (e2) 249 bytes (javascript) 7.27 KiB (runtime) [entry] [rendered] +chunk (runtime: e2) e2.js (e2) 249 bytes (javascript) 7.28 KiB (runtime) [entry] [rendered] ./b.js 20 bytes [dependent] [built] [code generated] ./e2.js + 2 modules 209 bytes [code generated] ./f.js 20 bytes [dependent] [built] [code generated] @@ -750,16 +750,16 @@ Rspack x.x.x compiled successfully" `; exports[`StatsTestCases should print correct stats for module-deduplication-named 1`] = ` -"asset e1.js 9.84 KiB [emitted] (name: e1) -asset e2.js 9.84 KiB [emitted] (name: e2) -asset e3.js 9.84 KiB [emitted] (name: e3) +"asset e1.js 9.85 KiB [emitted] (name: e1) +asset e2.js 9.85 KiB [emitted] (name: e2) +asset e3.js 9.85 KiB [emitted] (name: e3) asset async1.js 865 bytes [emitted] (name: async1) asset async2.js 864 bytes [emitted] (name: async2) asset async3.js 864 bytes [emitted] (name: async3) chunk (runtime: e1, e2, e3) async3.js (async3) 135 bytes [rendered] ./async3.js 115 bytes [built] [code generated] ./h.js 20 bytes [dependent] [built] [code generated] -chunk (runtime: e1) e1.js (e1) 242 bytes (javascript) 7.32 KiB (runtime) [entry] [rendered] +chunk (runtime: e1) e1.js (e1) 242 bytes (javascript) 7.33 KiB (runtime) [entry] [rendered] ./b.js 20 bytes [dependent] [built] [code generated] ./d.js 20 bytes [dependent] [built] [code generated] ./e1.js + 2 modules 202 bytes [code generated] @@ -769,11 +769,11 @@ chunk (runtime: e1, e2, e3) async2.js (async2) 135 bytes [rendered] chunk (runtime: e1, e2, e3) async1.js (async1) 135 bytes [rendered] ./async1.js 115 bytes [built] [code generated] ./d.js 20 bytes [dependent] [built] [code generated] -chunk (runtime: e3) e3.js (e3) 242 bytes (javascript) 7.32 KiB (runtime) [entry] [rendered] +chunk (runtime: e3) e3.js (e3) 242 bytes (javascript) 7.33 KiB (runtime) [entry] [rendered] ./b.js 20 bytes [dependent] [built] [code generated] ./e3.js + 2 modules 202 bytes [code generated] ./h.js 20 bytes [dependent] [built] [code generated] -chunk (runtime: e2) e2.js (e2) 242 bytes (javascript) 7.32 KiB (runtime) [entry] [rendered] +chunk (runtime: e2) e2.js (e2) 242 bytes (javascript) 7.33 KiB (runtime) [entry] [rendered] ./b.js 20 bytes [dependent] [built] [code generated] ./e2.js + 2 modules 202 bytes [code generated] ./f.js 20 bytes [dependent] [built] [code generated] @@ -886,7 +886,7 @@ exports[`StatsTestCases should print correct stats for named-chunk-groups 1`] = "Chunk Group async-a 1000 bytes = a-727.js 250 bytes a-async-a.js 751 bytes Chunk Group async-b 1000 bytes = a-727.js 250 bytes a-async-b.js 751 bytes Chunk Group async-c 1.21 KiB = a-vendors.js 586 bytes a-async-c.js 654 bytes -Chunk Group main 9.59 KiB = a-main.js +Chunk Group main 9.6 KiB = a-main.js chunk (runtime: main) a-async-c.js (async-c) 67 bytes [rendered] > ./c ./index.js 3:0-47 ./c.js 67 bytes [built] [code generated] @@ -904,12 +904,12 @@ chunk (runtime: main) a-727.js (id hint: ) 149 bytes [rendered] split chunk (cac > ./a ./index.js 1:0-47 > ./b ./index.js 2:0-47 ./shared.js 149 bytes [built] [code generated] -chunk (runtime: main) a-main.js (main) 146 bytes (javascript) 7.65 KiB (runtime) [entry] [rendered] +chunk (runtime: main) a-main.js (main) 146 bytes (javascript) 7.66 KiB (runtime) [entry] [rendered] > ./ main ./index.js 146 bytes [built] [code generated] Rspack x.x.x compiled successfully -Entrypoint main 9.59 KiB = b-main.js +Entrypoint main 9.6 KiB = b-main.js Chunk Group async-a 1000 bytes = b-727.js 250 bytes b-async-a.js 751 bytes Chunk Group async-b 1000 bytes = b-727.js 250 bytes b-async-b.js 751 bytes Chunk Group async-c 1.21 KiB = b-vendors.js 586 bytes b-async-c.js 654 bytes @@ -930,7 +930,7 @@ chunk (runtime: main) b-727.js (id hint: ) 149 bytes [rendered] split chunk (cac > ./a ./index.js 1:0-47 > ./b ./index.js 2:0-47 ./shared.js 149 bytes [built] [code generated] -chunk (runtime: main) b-main.js (main) 146 bytes (javascript) 7.65 KiB (runtime) [entry] [rendered] +chunk (runtime: main) b-main.js (main) 146 bytes (javascript) 7.66 KiB (runtime) [entry] [rendered] > ./ main ./index.js 146 bytes [built] [code generated] Rspack x.x.x compiled successfully" @@ -950,7 +950,7 @@ Rspack x.x.x compiled successfully in X.23" `; exports[`StatsTestCases should print correct stats for optimize-chunks 1`] = ` -"asset main.js 9.29 KiB {909} [emitted] (name: main) +"asset main.js 9.3 KiB {909} [emitted] (name: main) asset cir2 from cir1.js 355 bytes {334} [emitted] (name: cir2 from cir1) asset cir1.js 327 bytes {228} [emitted] (name: cir1) asset cir2.js 327 bytes {787} [emitted] (name: cir2) @@ -982,7 +982,7 @@ chunk {405} (runtime: main) ac in ab.js (ac in ab) 2 bytes <{909}> [rendered] chunk {787} (runtime: main) cir2.js (cir2) 81 bytes <{909}> >{228}< [rendered] > [10] ./index.js 14:0-54 ./circular2.js [193] 81 bytes {334} {787} [built] [code generated] -chunk {909} (runtime: main) main.js (main) 524 bytes (javascript) 6.82 KiB (runtime) >{228}< >{295}< >{37}< >{405}< >{787}< >{919}< [entry] [rendered] +chunk {909} (runtime: main) main.js (main) 524 bytes (javascript) 6.83 KiB (runtime) >{228}< >{295}< >{37}< >{405}< >{787}< >{919}< [entry] [rendered] > ./index main ./index.js [10] 523 bytes {909} [built] [code generated] ./modules/f.js [544] 1 bytes {909} [dependent] [built] [code generated] @@ -997,9 +997,9 @@ Rspack x.x.x compiled successfully in X.23" `; exports[`StatsTestCases should print correct stats for output-module 1`] = ` -"asset main.mjs 7.91 KiB [emitted] [javascript module] (name: main) +"asset main.mjs 7.92 KiB [emitted] [javascript module] (name: main) asset 8.mjs 270 bytes [emitted] [javascript module] -runtime modules 6.2 KiB 8 modules +runtime modules 6.21 KiB 8 modules orphan modules 225 bytes [orphan] 2 modules cacheable modules 263 bytes ./index.js + 1 modules 225 bytes [code generated] @@ -1160,14 +1160,14 @@ Rspack x.x.x compiled with 3 errors in X s" `; exports[`StatsTestCases should print correct stats for prefetch 1`] = ` -"asset main.js 13.9 KiB {909} [emitted] (name: main) +"asset main.js 14 KiB {909} [emitted] (name: main) asset prefetched.js 554 bytes {674} [emitted] (name: prefetched) asset inner2.js 130 bytes {857} [emitted] (name: inner2) asset inner.js 102 bytes {481} [emitted] (name: inner) asset normal.js 102 bytes {615} [emitted] (name: normal) asset prefetched2.js 102 bytes {424} [emitted] (name: prefetched2) asset prefetched3.js 102 bytes {182} [emitted] (name: prefetched3) -Entrypoint main 13.9 KiB = main.js +Entrypoint main 14 KiB = main.js prefetch: prefetched.js {674} (name: prefetched), prefetched3.js {182} (name: prefetched3), prefetched2.js {424} (name: prefetched2) chunk {182} (runtime: main) prefetched3.js (prefetched3) 1 bytes <{909}> [rendered] chunk {424} (runtime: main) prefetched2.js (prefetched2) 1 bytes <{909}> [rendered] @@ -1208,7 +1208,7 @@ chunk (runtime: main) preloaded3.js (preloaded3) 1 bytes [rendered] chunk (runtime: main) preloaded2.js (preloaded2) 1 bytes [rendered] chunk (runtime: main) normal.js (normal) 1 bytes [rendered] chunk (runtime: main) inner2.js (inner2) 2 bytes [rendered] -chunk (runtime: main) main.js (main) 424 bytes (javascript) 9.78 KiB (runtime) (preload: {154} {551} {577}) [entry] [rendered]" +chunk (runtime: main) main.js (main) 424 bytes (javascript) 9.81 KiB (runtime) (preload: {154} {551} {577}) [entry] [rendered]" `; exports[`StatsTestCases should print correct stats for preset-errors-only 1`] = `""`; @@ -1280,11 +1280,11 @@ exports[`StatsTestCases should print correct stats for related-assets 1`] = ` "default: assets by path *.br 14 KiB asset default-main.js.br 12 KiB [emitted] - asset default-main.js.map.br 675 bytes [emitted] + asset default-main.js.map.br 676 bytes [emitted] + 6 assets assets by path *.gz 14 KiB asset default-main.js.gz 12 KiB [emitted] - asset default-main.js.map.gz 675 bytes [emitted] + asset default-main.js.map.gz 676 bytes [emitted] asset default-chunk_js.js.gz 611 bytes [emitted] + 5 assets assets by path *.js 12.6 KiB @@ -1295,13 +1295,13 @@ exports[`StatsTestCases should print correct stats for related-assets 1`] = ` asset default-main.css 69 bytes [emitted] (name: main) relatedAssets: - assets by path *.br 14 KiB + assets by path *.br 14.1 KiB asset relatedAssets-main.js.br 12 KiB [emitted] - asset relatedAssets-main.js.map.br 681 bytes [emitted] + asset relatedAssets-main.js.map.br 682 bytes [emitted] + 6 assets - assets by path *.gz 14 KiB + assets by path *.gz 14.1 KiB asset relatedAssets-main.js.gz 12 KiB [emitted] - asset relatedAssets-main.js.map.gz 681 bytes [emitted] + asset relatedAssets-main.js.map.gz 682 bytes [emitted] asset relatedAssets-chunk_js.js.gz 617 bytes [emitted] + 5 assets assets by path *.js 12.6 KiB @@ -1324,11 +1324,11 @@ exclude1: exclude2: assets by path *.br 14 KiB asset exclude2-main.js.br 12 KiB [emitted] - asset exclude2-main.js.map.br 676 bytes [emitted] + asset exclude2-main.js.map.br 677 bytes [emitted] + 6 assets assets by path *.gz 14 KiB asset exclude2-main.js.gz 12 KiB [emitted] - asset exclude2-main.js.map.gz 676 bytes [emitted] + asset exclude2-main.js.map.gz 677 bytes [emitted] asset exclude2-chunk_js.js.gz 612 bytes [emitted] + 5 assets assets by path *.js 12.6 KiB @@ -1340,15 +1340,15 @@ exclude2: exclude3: hidden assets 2.89 KiB 10 assets - assets by status 37.8 KiB [emitted] + assets by status 37.9 KiB [emitted] assets by path *.br 12.9 KiB asset exclude3-main.js.br 12 KiB [emitted] - asset exclude3-main.js.map.br 676 bytes [emitted] + asset exclude3-main.js.map.br 677 bytes [emitted] asset exclude3-main.css.map.br 171 bytes [emitted] asset exclude3-main.css.br 70 bytes [emitted] assets by path *.gz 12.9 KiB asset exclude3-main.js.gz 12 KiB [emitted] - asset exclude3-main.js.map.gz 676 bytes [emitted] + asset exclude3-main.js.map.gz 677 bytes [emitted] asset exclude3-main.css.map.gz 171 bytes [emitted] asset exclude3-main.css.gz 70 bytes [emitted] assets by chunk 12.1 KiB (name: main) @@ -1412,15 +1412,15 @@ Rspack x.x.x compiled successfully" exports[`StatsTestCases should print correct stats for runtime-specific-used-exports 1`] = ` "production: - asset production-a.js 10.6 KiB [emitted] (name: a) - asset production-b.js 10.6 KiB [emitted] (name: b) + asset production-a.js 10.7 KiB [emitted] (name: a) + asset production-b.js 10.7 KiB [emitted] (name: b) asset production-dx_js.js 847 bytes [emitted] asset production-dw_js-_b3b00.js 838 bytes [emitted] asset production-dw_js-_b3b01.js 838 bytes [emitted] asset production-dy_js.js 831 bytes [emitted] asset production-dz_js.js 831 bytes [emitted] asset production-c.js 45 bytes [emitted] (name: c) - chunk (runtime: a) production-a.js (a) 605 bytes (javascript) 7.27 KiB (runtime) [entry] [rendered] + chunk (runtime: a) production-a.js (a) 605 bytes (javascript) 7.29 KiB (runtime) [entry] [rendered] ./a.js 261 bytes [built] [code generated] [no exports used] ./dx-importer.js 63 bytes [dependent] [built] [code generated] @@ -1431,7 +1431,7 @@ exports[`StatsTestCases should print correct stats for runtime-specific-used-exp [only some exports used: x, y] ./reexport.js 37 bytes [dependent] [built] [code generated] [only some exports used: x, y] - chunk (runtime: b) production-b.js (b) 605 bytes (javascript) 7.27 KiB (runtime) [entry] [rendered] + chunk (runtime: b) production-b.js (b) 605 bytes (javascript) 7.29 KiB (runtime) [entry] [rendered] ./b.js 261 bytes [built] [code generated] [no exports used] ./dx-importer.js 63 bytes [dependent] [built] [code generated] @@ -1465,7 +1465,7 @@ exports[`StatsTestCases should print correct stats for runtime-specific-used-exp ./dz.js 46 bytes [built] [code generated] ./module.js?chunk 122 bytes [dependent] [built] [code generated] [only some exports used: identity, w, x, y, z] - runtime modules 14.5 KiB 18 modules + runtime modules 14.6 KiB 18 modules cacheable modules 1.15 KiB ./a.js 261 bytes [built] [code generated] [no exports used] @@ -1497,7 +1497,7 @@ development: asset development-dy_js.js 1.07 KiB [emitted] asset development-dz_js.js 1.07 KiB [emitted] asset development-c.js 419 bytes [emitted] (name: c) - chunk (runtime: a) development-a.js (a) 605 bytes (javascript) 7.28 KiB (runtime) [entry] [rendered] + chunk (runtime: a) development-a.js (a) 605 bytes (javascript) 7.29 KiB (runtime) [entry] [rendered] ./a.js 261 bytes [built] [code generated] [used exports unknown] ./dx-importer.js 63 bytes [dependent] [built] [code generated] @@ -1508,7 +1508,7 @@ development: [used exports unknown] ./reexport.js 37 bytes [dependent] [built] [code generated] [used exports unknown] - chunk (runtime: b) development-b.js (b) 605 bytes (javascript) 7.28 KiB (runtime) [entry] [rendered] + chunk (runtime: b) development-b.js (b) 605 bytes (javascript) 7.29 KiB (runtime) [entry] [rendered] ./b.js 261 bytes [built] [code generated] [used exports unknown] ./dx-importer.js 63 bytes [dependent] [built] [code generated] @@ -1571,14 +1571,14 @@ development: development (Rspack x.x.x) compiled successfully in X.23 global: - asset global-a.js 10.7 KiB [emitted] (name: a) - asset global-b.js 10.7 KiB [emitted] (name: b) + asset global-a.js 10.8 KiB [emitted] (name: a) + asset global-b.js 10.8 KiB [emitted] (name: b) asset global-dw_js.js 847 bytes [emitted] asset global-dx_js.js 847 bytes [emitted] asset global-dy_js.js 847 bytes [emitted] asset global-dz_js.js 847 bytes [emitted] asset global-c.js 45 bytes [emitted] (name: c) - chunk (runtime: a) global-a.js (a) 605 bytes (javascript) 7.27 KiB (runtime) [entry] [rendered] + chunk (runtime: a) global-a.js (a) 605 bytes (javascript) 7.28 KiB (runtime) [entry] [rendered] ./a.js 261 bytes [built] [code generated] [no exports used] ./dx-importer.js 63 bytes [dependent] [built] [code generated] @@ -1589,7 +1589,7 @@ global: [only some exports used: x, y] ./reexport.js 37 bytes [dependent] [built] [code generated] [only some exports used: x, y] - chunk (runtime: b) global-b.js (b) 605 bytes (javascript) 7.27 KiB (runtime) [entry] [rendered] + chunk (runtime: b) global-b.js (b) 605 bytes (javascript) 7.28 KiB (runtime) [entry] [rendered] ./b.js 261 bytes [built] [code generated] [no exports used] ./dx-importer.js 63 bytes [dependent] [built] [code generated] @@ -1619,7 +1619,7 @@ global: ./dz.js 46 bytes [built] [code generated] ./module.js?chunk 122 bytes [dependent] [built] [code generated] [only some exports used: identity, w, x, y, z] - runtime modules 14.5 KiB 18 modules + runtime modules 14.6 KiB 18 modules cacheable modules 1.15 KiB ./a.js 261 bytes [built] [code generated] [no exports used] @@ -1684,7 +1684,7 @@ Rspack x.x.x compiled successfully in X.23" exports[`StatsTestCases should print correct stats for side-effects-issue-7428 1`] = ` "asset main.js 10.1 KiB [emitted] (name: main) asset 0.js 563 bytes [emitted] -runtime modules 7.26 KiB 9 modules +runtime modules 7.27 KiB 9 modules cacheable modules 967 bytes modules by path ./components/src/ 501 bytes orphan modules 315 bytes [orphan] @@ -1771,8 +1771,8 @@ Rspack x.x.x compiled successfully in X.23" exports[`StatsTestCases should print correct stats for split-chunks 1`] = ` "default: - Entrypoint main 9.49 KiB = default/main.js - Entrypoint a 9.05 KiB = default/a.js + Entrypoint main 9.5 KiB = default/main.js + Entrypoint a 9.06 KiB = default/a.js Entrypoint b 192 bytes = default/b.js Entrypoint c 192 bytes = default/c.js chunk (runtime: main) default/async-c.js (async-c) 116 bytes <{909}> ={416}= ={418}= ={581}= ={753}= [rendered] @@ -1802,7 +1802,7 @@ exports[`StatsTestCases should print correct stats for split-chunks 1`] = ` > ./c ./index.js 3:0-47 > ./g ./a.js 6:0-47 ./f.js 20 bytes [built] [code generated] - chunk (runtime: a) default/a.js (a) 165 bytes (javascript) 7.31 KiB (runtime) >{581}< >{912}< [entry] [rendered] + chunk (runtime: a) default/a.js (a) 165 bytes (javascript) 7.32 KiB (runtime) >{581}< >{912}< [entry] [rendered] > ./a a ./a.js 165 bytes [built] [code generated] chunk (runtime: b) default/b.js (b) 116 bytes [entry] [rendered] @@ -1816,7 +1816,7 @@ exports[`StatsTestCases should print correct stats for split-chunks 1`] = ` chunk (runtime: c) default/c.js (c) 116 bytes [entry] [rendered] > ./c c ./c.js 116 bytes [built] [code generated] - chunk (runtime: main) default/main.js (main) 147 bytes (javascript) 7.36 KiB (runtime) >{172}< >{250}< >{262}< >{310}< >{416}< >{418}< >{581}< >{753}< [entry] [rendered] + chunk (runtime: main) default/main.js (main) 147 bytes (javascript) 7.38 KiB (runtime) >{172}< >{250}< >{262}< >{310}< >{416}< >{418}< >{581}< >{753}< [entry] [rendered] > ./ main ./index.js 147 bytes [built] [code generated] chunk (runtime: a, main) default/async-g.js (async-g) 45 bytes <{250}> <{310}> <{418}> <{74}> <{753}> ={581}= [rendered] @@ -1825,8 +1825,8 @@ exports[`StatsTestCases should print correct stats for split-chunks 1`] = ` default (Rspack x.x.x) compiled successfully all-chunks: - Entrypoint main 9.49 KiB = all-chunks/main.js - Entrypoint a 9.05 KiB = all-chunks/a.js + Entrypoint main 9.5 KiB = all-chunks/main.js + Entrypoint a 9.06 KiB = all-chunks/a.js Entrypoint b 192 bytes = all-chunks/b.js Entrypoint c 192 bytes = all-chunks/c.js chunk (runtime: main) all-chunks/async-c.js (async-c) 116 bytes <{909}> ={416}= ={418}= ={581}= ={753}= [rendered] @@ -1856,7 +1856,7 @@ all-chunks: > ./c ./index.js 3:0-47 > ./g ./a.js 6:0-47 ./f.js 20 bytes [built] [code generated] - chunk (runtime: a) all-chunks/a.js (a) 165 bytes (javascript) 7.32 KiB (runtime) >{581}< >{912}< [entry] [rendered] + chunk (runtime: a) all-chunks/a.js (a) 165 bytes (javascript) 7.33 KiB (runtime) >{581}< >{912}< [entry] [rendered] > ./a a ./a.js 165 bytes [built] [code generated] chunk (runtime: b) all-chunks/b.js (b) 116 bytes [entry] [rendered] @@ -1870,7 +1870,7 @@ all-chunks: chunk (runtime: c) all-chunks/c.js (c) 116 bytes [entry] [rendered] > ./c c ./c.js 116 bytes [built] [code generated] - chunk (runtime: main) all-chunks/main.js (main) 147 bytes (javascript) 7.37 KiB (runtime) >{172}< >{250}< >{262}< >{310}< >{416}< >{418}< >{581}< >{753}< [entry] [rendered] + chunk (runtime: main) all-chunks/main.js (main) 147 bytes (javascript) 7.38 KiB (runtime) >{172}< >{250}< >{262}< >{310}< >{416}< >{418}< >{581}< >{753}< [entry] [rendered] > ./ main ./index.js 147 bytes [built] [code generated] chunk (runtime: a, main) all-chunks/async-g.js (async-g) 45 bytes <{250}> <{310}> <{418}> <{74}> <{753}> ={581}= [rendered] @@ -1879,7 +1879,7 @@ all-chunks: all-chunks (Rspack x.x.x) compiled successfully manual: - Entrypoint main 9.25 KiB = manual/main.js + Entrypoint main 9.26 KiB = manual/main.js Entrypoint a 11.6 KiB = manual/vendors.js 835 bytes manual/a.js 10.8 KiB Entrypoint b 5.59 KiB = manual/vendors.js 835 bytes manual/b.js 4.77 KiB Entrypoint c 5.59 KiB = manual/vendors.js 835 bytes manual/c.js 4.77 KiB @@ -1914,7 +1914,7 @@ manual: > ./b ./index.js 2:0-47 dependent modules 40 bytes [dependent] 2 modules ./b.js 116 bytes [built] [code generated] - chunk (runtime: a) manual/a.js (a) 165 bytes (javascript) 8.36 KiB (runtime) ={192}= >{912}< [entry] [rendered] + chunk (runtime: a) manual/a.js (a) 165 bytes (javascript) 8.38 KiB (runtime) ={192}= >{912}< [entry] [rendered] > ./a a > x a > y a @@ -1932,7 +1932,7 @@ manual: > y c > z c ./c.js 116 bytes [built] [code generated] - chunk (runtime: main) manual/main.js (main) 147 bytes (javascript) 7.37 KiB (runtime) >{172}< >{192}< >{250}< >{262}< [entry] [rendered] + chunk (runtime: main) manual/main.js (main) 147 bytes (javascript) 7.38 KiB (runtime) >{172}< >{192}< >{250}< >{262}< [entry] [rendered] > ./ main ./index.js 147 bytes [built] [code generated] chunk (runtime: a, main) manual/async-g.js (async-g) 65 bytes <{192}> <{250}> <{74}> [rendered] @@ -1942,8 +1942,8 @@ manual: manual (Rspack x.x.x) compiled successfully name-too-long: - Entrypoint main 9.49 KiB = name-too-long/main.js - Entrypoint aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa 9.05 KiB = name-too-long/aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa.js + Entrypoint main 9.5 KiB = name-too-long/main.js + Entrypoint aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa 9.06 KiB = name-too-long/aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa.js Entrypoint bbbbbbbbbbbbbbbbbbbbbbbbbbbbbb 192 bytes = name-too-long/bbbbbbbbbbbbbbbbbbbbbbbbbbbbbb.js Entrypoint cccccccccccccccccccccccccccccc 192 bytes = name-too-long/cccccccccccccccccccccccccccccc.js chunk (runtime: main) name-too-long/async-c.js (async-c) 116 bytes <{909}> ={416}= ={418}= ={581}= ={753}= [rendered] @@ -1984,20 +1984,20 @@ name-too-long: > ./b ./index.js 2:0-47 > ./c ./index.js 3:0-47 ./d.js 20 bytes [built] [code generated] - chunk (runtime: main) name-too-long/main.js (main) 147 bytes (javascript) 7.37 KiB (runtime) >{172}< >{250}< >{262}< >{310}< >{416}< >{418}< >{581}< >{753}< [entry] [rendered] + chunk (runtime: main) name-too-long/main.js (main) 147 bytes (javascript) 7.38 KiB (runtime) >{172}< >{250}< >{262}< >{310}< >{416}< >{418}< >{581}< >{753}< [entry] [rendered] > ./ main ./index.js 147 bytes [built] [code generated] chunk (runtime: aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa, main) name-too-long/async-g.js (async-g) 45 bytes <{250}> <{310}> <{418}> <{753}> <{959}> ={581}= [rendered] > ./g ./a.js 6:0-47 ./g.js 45 bytes [built] [code generated] - chunk (runtime: aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa) name-too-long/aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa.js (aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa) 165 bytes (javascript) 7.32 KiB (runtime) >{581}< >{912}< [entry] [rendered] + chunk (runtime: aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa) name-too-long/aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa.js (aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa) 165 bytes (javascript) 7.33 KiB (runtime) >{581}< >{912}< [entry] [rendered] > ./a aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa ./a.js 165 bytes [built] [code generated] name-too-long (Rspack x.x.x) compiled successfully custom-chunks-filter: - Entrypoint main 9.5 KiB = custom-chunks-filter/main.js - Entrypoint a 9.06 KiB = custom-chunks-filter/a.js + Entrypoint main 9.51 KiB = custom-chunks-filter/main.js + Entrypoint a 9.07 KiB = custom-chunks-filter/a.js Entrypoint b 192 bytes = custom-chunks-filter/b.js Entrypoint c 192 bytes = custom-chunks-filter/c.js chunk (runtime: main) custom-chunks-filter/async-c.js (async-c) 116 bytes <{909}> ={416}= ={418}= ={581}= ={753}= [rendered] @@ -2027,7 +2027,7 @@ custom-chunks-filter: > ./c ./index.js 3:0-47 > ./g ./a.js 6:0-47 ./f.js 20 bytes [built] [code generated] - chunk (runtime: a) custom-chunks-filter/a.js (a) 165 bytes (javascript) 7.33 KiB (runtime) >{581}< >{912}< [entry] [rendered] + chunk (runtime: a) custom-chunks-filter/a.js (a) 165 bytes (javascript) 7.34 KiB (runtime) >{581}< >{912}< [entry] [rendered] > ./a a ./a.js 165 bytes [built] [code generated] chunk (runtime: b) custom-chunks-filter/b.js (b) 116 bytes [entry] [rendered] @@ -2041,7 +2041,7 @@ custom-chunks-filter: chunk (runtime: c) custom-chunks-filter/c.js (c) 116 bytes [entry] [rendered] > ./c c ./c.js 116 bytes [built] [code generated] - chunk (runtime: main) custom-chunks-filter/main.js (main) 147 bytes (javascript) 7.38 KiB (runtime) >{172}< >{250}< >{262}< >{310}< >{416}< >{418}< >{581}< >{753}< [entry] [rendered] + chunk (runtime: main) custom-chunks-filter/main.js (main) 147 bytes (javascript) 7.39 KiB (runtime) >{172}< >{250}< >{262}< >{310}< >{416}< >{418}< >{581}< >{753}< [entry] [rendered] > ./ main ./index.js 147 bytes [built] [code generated] chunk (runtime: a, main) custom-chunks-filter/async-g.js (async-g) 45 bytes <{250}> <{310}> <{418}> <{74}> <{753}> ={581}= [rendered] @@ -2050,7 +2050,7 @@ custom-chunks-filter: custom-chunks-filter (Rspack x.x.x) compiled successfully custom-chunks-filter-in-cache-groups: - Entrypoint main 9.28 KiB = custom-chunks-filter-in-cache-groups/main.js + Entrypoint main 9.29 KiB = custom-chunks-filter-in-cache-groups/main.js Entrypoint a 11.2 KiB = custom-chunks-filter-in-cache-groups/598.js 388 bytes custom-chunks-filter-in-cache-groups/a.js 10.8 KiB Entrypoint b 5.59 KiB = custom-chunks-filter-in-cache-groups/vendors.js 835 bytes custom-chunks-filter-in-cache-groups/b.js 4.77 KiB Entrypoint c 5.59 KiB = custom-chunks-filter-in-cache-groups/vendors.js 835 bytes custom-chunks-filter-in-cache-groups/c.js 4.77 KiB @@ -2089,7 +2089,7 @@ custom-chunks-filter-in-cache-groups: ./node_modules/x.js 20 bytes [built] [code generated] ./node_modules/y.js 20 bytes [built] [code generated] ./node_modules/z.js 20 bytes [built] [code generated] - chunk (runtime: a) custom-chunks-filter-in-cache-groups/a.js (a) 165 bytes (javascript) 8.39 KiB (runtime) ={598}= >{912}< [entry] [rendered] + chunk (runtime: a) custom-chunks-filter-in-cache-groups/a.js (a) 165 bytes (javascript) 8.4 KiB (runtime) ={598}= >{912}< [entry] [rendered] > ./a a > x a > y a @@ -2107,7 +2107,7 @@ custom-chunks-filter-in-cache-groups: > y c > z c ./c.js 116 bytes [built] [code generated] - chunk (runtime: main) custom-chunks-filter-in-cache-groups/main.js (main) 147 bytes (javascript) 7.4 KiB (runtime) >{172}< >{192}< >{250}< >{262}< [entry] [rendered] + chunk (runtime: main) custom-chunks-filter-in-cache-groups/main.js (main) 147 bytes (javascript) 7.41 KiB (runtime) >{172}< >{192}< >{250}< >{262}< [entry] [rendered] > ./ main ./index.js 147 bytes [built] [code generated] chunk (runtime: a, main) custom-chunks-filter-in-cache-groups/async-g.js (async-g) 65 bytes <{192}> <{250}> <{598}> <{74}> [rendered] @@ -2118,7 +2118,7 @@ custom-chunks-filter-in-cache-groups: `; exports[`StatsTestCases should print correct stats for split-chunks-automatic-name 1`] = ` -"Entrypoint main 9.56 KiB = main.js +"Entrypoint main 9.57 KiB = main.js chunk (runtime: main) async-a.js (async-a) (id hint: common) 136 bytes <{main}> ={common-d_js}= ={common-node_modules_x_js}= ={common-node_modules_y_js}= [rendered] > ./a ./index.js 1:0-47 ./a.js + 1 modules 136 bytes [code generated] @@ -2149,14 +2149,14 @@ chunk (runtime: main) common-node_modules_y_js.js (id hint: common) 20 bytes <{m chunk (runtime: main) common-node_modules_z_js.js (id hint: common) 20 bytes <{main}> ={async-c}= ={common-d_js}= ={common-f_js}= ={common-node_modules_x_js}= [rendered] split chunk (cache group: b) > ./c ./index.js 3:0-47 ./node_modules/z.js 20 bytes [built] [code generated] -chunk (runtime: main) main.js (main) (id hint: common) 147 bytes (javascript) 7.27 KiB (runtime) >{async-a}< >{async-b}< >{async-c}< >{common-d_js}< >{common-f_js}< >{common-node_modules_x_js}< >{common-node_modules_y_js}< >{common-node_modules_z_js}< [entry] [rendered] +chunk (runtime: main) main.js (main) (id hint: common) 147 bytes (javascript) 7.28 KiB (runtime) >{async-a}< >{async-b}< >{async-c}< >{common-d_js}< >{common-f_js}< >{common-node_modules_x_js}< >{common-node_modules_y_js}< >{common-node_modules_z_js}< [entry] [rendered] > ./ main ./index.js 147 bytes [built] [code generated] production (Rspack x.x.x) compiled successfully" `; exports[`StatsTestCases should print correct stats for split-chunks-chunk-name 1`] = ` -"Entrypoint main 9.21 KiB = default/main.js +"Entrypoint main 9.22 KiB = default/main.js chunk (runtime: main) default/async-a.js (async-a) 20 bytes <{909}> [rendered] > a ./index.js 1:0-45 ./node_modules/a.js 20 bytes [built] [code generated] @@ -2167,14 +2167,14 @@ chunk (runtime: main) default/async-c-1.js (async-c-1) (id hint: vendors) 122 by > c ./index.js 3:0-47 > c ./index.js 4:0-47 ./node_modules/c.js 122 bytes [built] [code generated] -chunk (runtime: main) default/main.js (main) 192 bytes (javascript) 7.34 KiB (runtime) >{250}< >{262}< >{589}< [entry] [rendered] +chunk (runtime: main) default/main.js (main) 192 bytes (javascript) 7.35 KiB (runtime) >{250}< >{262}< >{589}< [entry] [rendered] > ./ main ./index.js 192 bytes [built] [code generated] Rspack x.x.x compiled successfully" `; exports[`StatsTestCases should print correct stats for split-chunks-combinations 1`] = ` -"Entrypoint main 9.68 KiB = main.js +"Entrypoint main 9.69 KiB = main.js chunk (runtime: main) async-c.js (async-c) 132 bytes <{909}> [rendered] > ./c ./index.js 3:0-47 dependent modules 87 bytes [dependent] 1 module @@ -2202,7 +2202,7 @@ chunk (runtime: main) async-d.js (async-d) 132 bytes <{909}> [rendered] > ./d ./index.js 4:0-47 dependent modules 87 bytes [dependent] 1 module ./d.js 45 bytes [built] [code generated] -chunk (runtime: main) main.js (main) 343 bytes (javascript) 7.4 KiB (runtime) >{172}< >{198}< >{250}< >{262}< >{36}< >{407}< >{602}< >{912}< [entry] [rendered] +chunk (runtime: main) main.js (main) 343 bytes (javascript) 7.41 KiB (runtime) >{172}< >{198}< >{250}< >{262}< >{36}< >{407}< >{602}< >{912}< [entry] [rendered] > ./ main ./index.js 343 bytes [built] [code generated] chunk (runtime: main) async-g.js (async-g) 132 bytes <{909}> [rendered] @@ -2213,7 +2213,7 @@ Rspack x.x.x compiled successfully" `; exports[`StatsTestCases should print correct stats for split-chunks-issue-6413 1`] = ` -"Entrypoint main 9.31 KiB = main.js +"Entrypoint main 9.32 KiB = main.js chunk (runtime: main) async-c.js (async-c) 36 bytes <{909}> ={306}= ={418}= [rendered] > ./c ./index.js 3:0-47 ./c.js 36 bytes [built] [code generated] @@ -2233,7 +2233,7 @@ chunk (runtime: main) 418.js (id hint: vendors) 20 bytes <{909}> ={172}= ={250}= > ./b ./index.js 2:0-47 > ./c ./index.js 3:0-47 ./node_modules/x.js 20 bytes [built] [code generated] -chunk (runtime: main) main.js (main) 147 bytes (javascript) 7.33 KiB (runtime) >{172}< >{250}< >{262}< >{306}< >{418}< [entry] [rendered] +chunk (runtime: main) main.js (main) 147 bytes (javascript) 7.34 KiB (runtime) >{172}< >{250}< >{262}< >{306}< >{418}< [entry] [rendered] > ./ main ./index.js 147 bytes [built] [code generated] default (Rspack x.x.x) compiled successfully" @@ -2252,7 +2252,7 @@ chunk (runtime: main) async-b.js (async-b) 49 bytes <{192}> <{909}> [rendered] > ./b ./index.js 3:0-47 dependent modules 20 bytes [dependent] 1 module ./b.js 29 bytes [built] [code generated] -chunk (runtime: main) main.js (main) 134 bytes (javascript) 8.39 KiB (runtime) ={192}= >{250}< >{262}< [entry] [rendered] +chunk (runtime: main) main.js (main) 134 bytes (javascript) 8.4 KiB (runtime) ={192}= >{250}< >{262}< [entry] [rendered] > ./ main ./index.js 134 bytes [built] [code generated] default (Rspack x.x.x) compiled successfully" @@ -2260,7 +2260,7 @@ default (Rspack x.x.x) compiled successfully" exports[`StatsTestCases should print correct stats for split-chunks-issue-7401 1`] = ` "Entrypoint a 4.91 KiB = 418.js 337 bytes a.js 4.58 KiB -Entrypoint b 8.87 KiB = b.js +Entrypoint b 8.88 KiB = b.js Chunk Group c 705 bytes = 418.js 337 bytes c.js 368 bytes chunk (runtime: a, b) 418.js (id hint: vendors) 20 bytes <{751}> ={74}= ={76}= [initial] [rendered] split chunk (cache group: defaultVendors) > ./c ./b.js 1:0-41 @@ -2269,7 +2269,7 @@ chunk (runtime: a, b) 418.js (id hint: vendors) 20 bytes <{751}> ={74}= ={76}= [ chunk (runtime: a) a.js (a) 35 bytes (javascript) 2.86 KiB (runtime) ={418}= [entry] [rendered] > ./a a ./a.js 35 bytes [built] [code generated] -chunk (runtime: b) b.js (b) 43 bytes (javascript) 7.29 KiB (runtime) >{418}< >{76}< [entry] [rendered] +chunk (runtime: b) b.js (b) 43 bytes (javascript) 7.3 KiB (runtime) >{418}< >{76}< [entry] [rendered] > ./b b ./b.js 43 bytes [built] [code generated] chunk (runtime: b) c.js (c) 35 bytes <{751}> ={418}= [rendered] @@ -2279,7 +2279,7 @@ default (Rspack x.x.x) compiled successfully" `; exports[`StatsTestCases should print correct stats for split-chunks-keep-remaining-size 1`] = ` -"Entrypoint main 9.4 KiB = default/main.js +"Entrypoint main 9.41 KiB = default/main.js chunk (runtime: main) default/async-c.js (async-c) 50 bytes <{909}> ={44}= [rendered] > ./c ./index.js 3:0-47 ./c.js 50 bytes [built] [code generated] @@ -2303,14 +2303,14 @@ chunk (runtime: main) default/async-d.js (async-d) 84 bytes <{909}> ={403}= [ren chunk (runtime: main) default/728.js (id hint: vendors) 126 bytes <{909}> ={250}= [rendered] split chunk (cache group: defaultVendors) > ./a ./index.js 1:0-47 ./node_modules/shared.js?1 126 bytes [built] [code generated] -chunk (runtime: main) default/main.js (main) 196 bytes (javascript) 7.36 KiB (runtime) >{172}< >{250}< >{262}< >{403}< >{44}< >{602}< >{728}< [entry] [rendered] +chunk (runtime: main) default/main.js (main) 196 bytes (javascript) 7.38 KiB (runtime) >{172}< >{250}< >{262}< >{403}< >{44}< >{602}< >{728}< [entry] [rendered] > ./ main ./index.js 196 bytes [built] [code generated] Rspack x.x.x compiled successfully" `; exports[`StatsTestCases should print correct stats for split-chunks-min-size-reduction 1`] = ` -"Entrypoint main 9.57 KiB = default/main.js +"Entrypoint main 9.58 KiB = default/main.js chunk (runtime: main) default/async-c.js (async-c) 50 bytes <{909}> ={44}= [rendered] > ./c ./index.js 3:0-47 ./c.js 50 bytes [built] [code generated] @@ -2335,14 +2335,14 @@ chunk (runtime: main) default/728.js (id hint: vendors) 126 bytes <{909}> ={250} > ./a ./index.js 1:0-47 > ./b ./index.js 2:0-47 ./node_modules/shared.js?1 126 bytes [built] [code generated] -chunk (runtime: main) default/main.js (main) 245 bytes (javascript) 7.38 KiB (runtime) >{172}< >{250}< >{262}< >{407}< >{44}< >{602}< >{728}< [entry] [rendered] +chunk (runtime: main) default/main.js (main) 245 bytes (javascript) 7.39 KiB (runtime) >{172}< >{250}< >{262}< >{407}< >{44}< >{602}< >{728}< [entry] [rendered] > ./ main ./index.js 245 bytes [built] [code generated] Rspack x.x.x compiled successfully" `; exports[`StatsTestCases should print correct stats for split-chunks-prefer-bigger-splits 1`] = ` -"Entrypoint main 9.19 KiB = default/main.js +"Entrypoint main 9.2 KiB = default/main.js chunk (runtime: main) default/async-c.js (async-c) 70 bytes <{909}> ={457}= [rendered] > ./c ./index.js 3:0-47 ./c.js 70 bytes [built] [code generated] @@ -2359,7 +2359,7 @@ chunk (runtime: main) default/457.js (id hint: ) 150 bytes <{909}> ={172}= ={262 > ./c ./index.js 3:0-47 ./d.js 63 bytes [built] [code generated] ./f.js 87 bytes [built] [code generated] -chunk (runtime: main) default/main.js (main) 147 bytes (javascript) 7.35 KiB (runtime) >{172}< >{250}< >{262}< >{457}< [entry] [rendered] +chunk (runtime: main) default/main.js (main) 147 bytes (javascript) 7.36 KiB (runtime) >{172}< >{250}< >{262}< >{457}< [entry] [rendered] > ./ main ./index.js 147 bytes [built] [code generated] Rspack x.x.x compiled successfully" From 060370009b9b18350ea94ee14926308d09a7820e Mon Sep 17 00:00:00 2001 From: LingyuCoder Date: Wed, 22 Jan 2025 21:00:38 +0800 Subject: [PATCH 2/4] feat: add runtime plugin hooks --- website/docs/en/api/plugin-api/_meta.json | 3 +- .../api/plugin-api/runtime-plugin-hooks.mdx | 106 ++++++++++++++++++ website/docs/zh/api/plugin-api/_meta.json | 3 +- .../api/plugin-api/runtime-plugin-hooks.mdx | 106 ++++++++++++++++++ 4 files changed, 216 insertions(+), 2 deletions(-) create mode 100644 website/docs/en/api/plugin-api/runtime-plugin-hooks.mdx create mode 100644 website/docs/zh/api/plugin-api/runtime-plugin-hooks.mdx diff --git a/website/docs/en/api/plugin-api/_meta.json b/website/docs/en/api/plugin-api/_meta.json index 9715c9b03444..3f4c08c9be94 100644 --- a/website/docs/en/api/plugin-api/_meta.json +++ b/website/docs/en/api/plugin-api/_meta.json @@ -5,5 +5,6 @@ "normal-module-factory-hooks", "context-module-factory-hooks", "javascript-modules-plugin-hooks", - "stats-hooks" + "stats-hooks", + "runtime-plugin-hooks" ] diff --git a/website/docs/en/api/plugin-api/runtime-plugin-hooks.mdx b/website/docs/en/api/plugin-api/runtime-plugin-hooks.mdx new file mode 100644 index 000000000000..d4cd7617ce43 --- /dev/null +++ b/website/docs/en/api/plugin-api/runtime-plugin-hooks.mdx @@ -0,0 +1,106 @@ +import { Collapse, CollapsePanel } from '@components/Collapse'; +import ChunkType from '../../types/chunk.mdx'; + +# RuntimePlugin Hooks + +`RuntimePlugin` is used to generate the code for the Rspack startup. It provides the following hooks that can be used to modify these runtime codes. + +You can obtain these hooks like below: + +```js +module.exports = { + //... + plugins: [ + { + apply: compiler => { + const { RuntimePlugin } = compiler.webpack; + compiler.hooks.compilation.tap('MyPlugin', compilation => { + const hooks = RuntimePlugin.getCompilationHooks(compilation); + //... + }); + }, + }, + ], +}; +``` + +## `createScript` + +`SyncWaterallHook<[string, chunk]>` + +Can modify the code executed when creating the `