Skip to main content

rspack_plugin_runtime/
drive.rs

1use std::ptr::NonNull;
2
3use rspack_core::{ChunkUkey, Compilation, CompilationId};
4use rspack_hook::define_hook;
5#[cfg(allocative)]
6use rspack_util::allocative;
7
8#[derive(Debug, Clone)]
9pub struct CreateScriptData {
10  pub code: String,
11  pub chunk: RuntimeModuleChunkWrapper,
12}
13
14#[derive(Debug, Clone)]
15pub struct CreateLinkData {
16  pub code: String,
17  pub chunk: RuntimeModuleChunkWrapper,
18}
19
20#[derive(Debug, Clone)]
21pub struct LinkPreloadData {
22  pub code: String,
23  pub chunk: RuntimeModuleChunkWrapper,
24}
25
26#[derive(Debug, Clone)]
27pub struct LinkPrefetchData {
28  pub code: String,
29  pub chunk: RuntimeModuleChunkWrapper,
30}
31
32#[derive(Debug, Clone)]
33pub struct RuntimeModuleChunkWrapper {
34  pub chunk_ukey: ChunkUkey,
35  pub compilation_id: CompilationId,
36  pub compilation: NonNull<Compilation>,
37}
38
39unsafe impl Send for RuntimeModuleChunkWrapper {}
40
41define_hook!(RuntimePluginCreateScript: SeriesWaterfall(data: CreateScriptData) -> CreateScriptData);
42define_hook!(RuntimePluginCreateLink: SeriesWaterfall(data: CreateLinkData) -> CreateLinkData);
43define_hook!(RuntimePluginLinkPreload: SeriesWaterfall(data: LinkPreloadData) -> LinkPreloadData);
44define_hook!(RuntimePluginLinkPrefetch: SeriesWaterfall(data: LinkPrefetchData) -> LinkPrefetchData);
45
46#[derive(Debug, Default)]
47#[cfg_attr(allocative, derive(allocative::Allocative))]
48pub struct RuntimePluginHooks {
49  #[cfg_attr(allocative, allocative(skip))]
50  pub create_script: RuntimePluginCreateScriptHook,
51  #[cfg_attr(allocative, allocative(skip))]
52  pub create_link: RuntimePluginCreateLinkHook,
53  #[cfg_attr(allocative, allocative(skip))]
54  pub link_preload: RuntimePluginLinkPreloadHook,
55  #[cfg_attr(allocative, allocative(skip))]
56  pub link_prefetch: RuntimePluginLinkPrefetchHook,
57}