rspack_plugin_library/
lib.rs1mod amd_library_plugin;
2mod assign_library_plugin;
3mod export_property_library_plugin;
4mod modern_module;
5mod modern_module_library_plugin;
6mod module_library_plugin;
7mod system_library_plugin;
8mod umd_library_plugin;
9mod utils;
10
11pub use amd_library_plugin::AmdLibraryPlugin;
12pub use assign_library_plugin::*;
13pub use export_property_library_plugin::ExportPropertyLibraryPlugin;
14use rspack_core::{BoxPlugin, PluginExt};
15pub use system_library_plugin::SystemLibraryPlugin;
16pub use umd_library_plugin::UmdLibraryPlugin;
17
18use crate::{
19 modern_module_library_plugin::ModernModuleLibraryPlugin,
20 module_library_plugin::ModuleLibraryPlugin,
21};
22
23pub fn enable_library_plugin(library_type: String, plugins: &mut Vec<BoxPlugin>) {
24 let ns_object_used = library_type != "module";
25 match library_type.as_str() {
26 "var" => plugins.push(
27 AssignLibraryPlugin::new(AssignLibraryPluginOptions {
28 library_type,
29 prefix: Prefix::Array(vec![]),
30 declare: true,
31 unnamed: Unnamed::Error,
32 named: None,
33 })
34 .boxed(),
35 ),
36 "assign-properties" => plugins.push(
37 AssignLibraryPlugin::new(AssignLibraryPluginOptions {
38 library_type,
39 prefix: Prefix::Array(vec![]),
40 declare: false,
41 unnamed: Unnamed::Error,
42 named: Some(Named::Copy),
43 })
44 .boxed(),
45 ),
46 "assign" => plugins.push(
47 AssignLibraryPlugin::new(AssignLibraryPluginOptions {
48 library_type,
49 prefix: Prefix::Array(vec![]),
50 declare: false,
51 unnamed: Unnamed::Error,
52 named: None,
53 })
54 .boxed(),
55 ),
56 "this" | "window" | "self" => plugins.push(
57 AssignLibraryPlugin::new(AssignLibraryPluginOptions {
58 library_type: library_type.clone(),
59 prefix: Prefix::Array(vec![library_type]),
60 declare: false,
61 unnamed: Unnamed::Copy,
62 named: None,
63 })
64 .boxed(),
65 ),
66 "global" => plugins.push(
67 AssignLibraryPlugin::new(AssignLibraryPluginOptions {
68 library_type,
69 prefix: Prefix::Global,
70 declare: false,
71 unnamed: Unnamed::Copy,
72 named: None,
73 })
74 .boxed(),
75 ),
76 "commonjs" => plugins.push(
77 AssignLibraryPlugin::new(AssignLibraryPluginOptions {
78 library_type,
79 prefix: Prefix::Array(vec!["exports".to_string()]),
80 declare: false,
81 unnamed: Unnamed::Copy,
82 named: None,
83 })
84 .boxed(),
85 ),
86 "commonjs-static" => plugins.push(
87 AssignLibraryPlugin::new(AssignLibraryPluginOptions {
88 library_type,
89 prefix: Prefix::Array(vec!["exports".to_string()]),
90 declare: false,
91 unnamed: Unnamed::Static,
92 named: None,
93 })
94 .boxed(),
95 ),
96 "commonjs2" | "commonjs-module" => plugins.push(
97 AssignLibraryPlugin::new(AssignLibraryPluginOptions {
98 library_type,
99 prefix: Prefix::Array(vec!["module".to_string(), "exports".to_string()]),
100 declare: false,
101 unnamed: Unnamed::Assign,
102 named: None,
103 })
104 .boxed(),
105 ),
106 "umd" | "umd2" => {
107 plugins
108 .push(ExportPropertyLibraryPlugin::new(library_type.clone(), ns_object_used, true).boxed());
109 plugins.push(UmdLibraryPlugin::new("umd2" == library_type, library_type).boxed());
110 }
111 "amd" | "amd-require" => {
112 plugins
113 .push(ExportPropertyLibraryPlugin::new(library_type.clone(), ns_object_used, true).boxed());
114 plugins.push(AmdLibraryPlugin::new("amd-require" == library_type, library_type).boxed());
115 }
116 "module" => {
117 plugins
118 .push(ExportPropertyLibraryPlugin::new(library_type.clone(), ns_object_used, true).boxed());
119 plugins.push(ModuleLibraryPlugin::default().boxed());
120 }
121 "modern-module" => {
122 plugins.push(
123 ExportPropertyLibraryPlugin::new(library_type.clone(), ns_object_used, false).boxed(),
124 );
125 plugins.push(ModernModuleLibraryPlugin::default().boxed());
126 }
127 "system" => {
128 plugins.push(
129 ExportPropertyLibraryPlugin::new(library_type.clone(), library_type != "module", true)
130 .boxed(),
131 );
132 plugins.push(SystemLibraryPlugin::default().boxed());
133 }
134 _ => {}
135 }
136}