rspack_plugin_runtime/
drive.rs

1use std::ptr::NonNull;
2
3use rspack_core::{ChunkUkey, Compilation, CompilationId};
4use rspack_hook::define_hook;
5
6#[derive(Debug, Clone)]
7pub struct CreateScriptData {
8  pub code: String,
9  pub chunk: RuntimeModuleChunkWrapper,
10}
11
12#[derive(Debug, Clone)]
13pub struct LinkPreloadData {
14  pub code: String,
15  pub chunk: RuntimeModuleChunkWrapper,
16}
17
18#[derive(Debug, Clone)]
19pub struct LinkPrefetchData {
20  pub code: String,
21  pub chunk: RuntimeModuleChunkWrapper,
22}
23
24#[derive(Debug, Clone)]
25pub struct RuntimeModuleChunkWrapper {
26  pub chunk_ukey: ChunkUkey,
27  pub compilation_id: CompilationId,
28  pub compilation: NonNull<Compilation>,
29}
30
31unsafe impl Send for RuntimeModuleChunkWrapper {}
32
33define_hook!(RuntimePluginCreateScript: SeriesWaterfall(data: CreateScriptData) -> CreateScriptData);
34define_hook!(RuntimePluginLinkPreload: SeriesWaterfall(data: LinkPreloadData) -> LinkPreloadData);
35define_hook!(RuntimePluginLinkPrefetch: SeriesWaterfall(data: LinkPrefetchData) -> LinkPrefetchData);
36
37#[derive(Debug, Default)]
38pub struct RuntimePluginHooks {
39  pub create_script: RuntimePluginCreateScriptHook,
40  pub link_preload: RuntimePluginLinkPreloadHook,
41  pub link_prefetch: RuntimePluginLinkPrefetchHook,
42}