forked from web-infra-dev/rspack
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: support rspack.DllPlugin & rspack.DllReferencePlugin (web-infra…
…-dev#8296) * feat: rewrite dll-plugin by rust * feat: support rspack.DllReferencePlugin * test: add dll plugin tests * refactor: improve delegated_module code * docs: add dll-plugin & dll-refernce-plugin docs * fix: flagAllModuleAsUsedPlugin add_extra_reason * chore: rename some vars * fix: typo * fix: remove the unnecessary generics * fix: typo * fix: cargo clippy test * fix: remove unused dependency rspack_macros * docs: add dll & dll-reference plugin zh docs * fix: resolved merge conflict * fix: resolved some issues - dll-reference-plugin should given a manifest struct, rather than json-string - we should not add a null module_graph_module_connection like webpack * chore: add some annotations * chore: add some annotations * fix: update manifest content item exports type * fix: update dll manifest types * chore:update docs * chore: clippy fix * fix: bailout use build_info.module_concatenation_bailout
- Loading branch information
1 parent
ce5694e
commit bcde793
Showing
58 changed files
with
2,856 additions
and
43 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
168 changes: 168 additions & 0 deletions
168
crates/rspack_binding_options/src/options/raw_builtins/raw_dll.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,168 @@ | ||
use napi::Either; | ||
use napi_derive::napi; | ||
use rspack_binding_values::{JsBuildMeta, JsFilename}; | ||
use rspack_plugin_dll::{ | ||
DllEntryPluginOptions, DllManifest, DllManifestContent, DllManifestContentItem, | ||
DllManifestContentItemExports, DllReferenceAgencyPluginOptions, LibManifestPluginOptions, | ||
}; | ||
use rustc_hash::FxHashMap as HashMap; | ||
use swc_core::atoms::Atom; | ||
|
||
#[derive(Debug)] | ||
#[napi(object)] | ||
pub struct RawDllEntryPluginOptions { | ||
pub context: String, | ||
pub entries: Vec<String>, | ||
pub name: String, | ||
} | ||
|
||
impl From<RawDllEntryPluginOptions> for DllEntryPluginOptions { | ||
fn from(value: RawDllEntryPluginOptions) -> Self { | ||
let RawDllEntryPluginOptions { | ||
name, | ||
context, | ||
entries, | ||
} = value; | ||
|
||
Self { | ||
name, | ||
context: context.into(), | ||
entries, | ||
} | ||
} | ||
} | ||
|
||
#[derive(Debug)] | ||
#[napi(object, object_to_js = false)] | ||
pub struct RawLibManifestPluginOptions { | ||
pub context: Option<String>, | ||
pub entry_only: Option<bool>, | ||
pub name: Option<JsFilename>, | ||
pub path: JsFilename, | ||
pub format: Option<bool>, | ||
pub r#type: Option<String>, | ||
} | ||
|
||
impl From<RawLibManifestPluginOptions> for LibManifestPluginOptions { | ||
fn from(value: RawLibManifestPluginOptions) -> Self { | ||
let RawLibManifestPluginOptions { | ||
context, | ||
entry_only, | ||
name, | ||
path, | ||
r#type, | ||
format, | ||
} = value; | ||
|
||
Self { | ||
context: context.map(|c| c.into()), | ||
format, | ||
entry_only, | ||
name: name.map(|n| n.into()), | ||
path: path.into(), | ||
r#type, | ||
} | ||
} | ||
} | ||
|
||
#[napi(object, object_to_js = false)] | ||
pub struct RawDllReferenceAgencyPluginOptions { | ||
pub context: Option<String>, | ||
pub name: Option<String>, | ||
pub extensions: Vec<String>, | ||
pub scope: Option<String>, | ||
pub source_type: Option<String>, | ||
pub r#type: String, | ||
pub content: Option<HashMap<String, RawDllManifestContentItem>>, | ||
pub manifest: Option<RawDllManifest>, | ||
} | ||
|
||
#[napi(object, object_to_js = false)] | ||
pub struct RawDllManifestContentItem { | ||
pub build_meta: Option<JsBuildMeta>, | ||
#[napi(ts_type = "string[] | true")] | ||
pub exports: Option<Either<Vec<String>, bool>>, | ||
pub id: Option<String>, | ||
} | ||
|
||
impl From<RawDllManifestContentItem> for DllManifestContentItem { | ||
fn from(value: RawDllManifestContentItem) -> Self { | ||
let raw_exports = value.exports; | ||
|
||
let exports = raw_exports.map(|exports| match exports { | ||
Either::A(seq) => { | ||
DllManifestContentItemExports::Vec(seq.into_iter().map(Atom::from).collect::<Vec<_>>()) | ||
} | ||
Either::B(bool) => { | ||
if bool { | ||
DllManifestContentItemExports::True | ||
} else { | ||
unreachable!() | ||
} | ||
} | ||
}); | ||
|
||
Self { | ||
build_meta: value.build_meta.map(|meta| meta.into()), | ||
exports, | ||
id: value.id, | ||
} | ||
} | ||
} | ||
|
||
#[napi(object, object_to_js = false)] | ||
pub struct RawDllManifest { | ||
pub content: HashMap<String, RawDllManifestContentItem>, | ||
pub name: Option<String>, | ||
pub r#type: Option<String>, | ||
} | ||
|
||
impl From<RawDllManifest> for DllManifest { | ||
fn from(value: RawDllManifest) -> Self { | ||
Self { | ||
content: value | ||
.content | ||
.into_iter() | ||
.map(|(k, v)| (k, v.into())) | ||
.collect::<DllManifestContent>(), | ||
name: value.name, | ||
r#type: value.r#type, | ||
} | ||
} | ||
} | ||
|
||
impl From<RawDllReferenceAgencyPluginOptions> for DllReferenceAgencyPluginOptions { | ||
fn from(value: RawDllReferenceAgencyPluginOptions) -> Self { | ||
let RawDllReferenceAgencyPluginOptions { | ||
context, | ||
name, | ||
extensions, | ||
scope, | ||
source_type, | ||
r#type, | ||
content, | ||
manifest, | ||
} = value; | ||
|
||
Self { | ||
context: context.map(|ctx| ctx.into()), | ||
name, | ||
extensions, | ||
scope, | ||
source_type, | ||
r#type, | ||
content: content.map(|c| { | ||
c.into_iter() | ||
.map(|(k, v)| (k, v.into())) | ||
.collect::<DllManifestContent>() | ||
}), | ||
manifest: manifest.map(|m| m.into()), | ||
} | ||
} | ||
} | ||
|
||
#[derive(Debug)] | ||
#[napi(object)] | ||
pub struct RawFlagAllModulesAsUsedPluginOptions { | ||
pub explanation: String, | ||
} |
Oops, something went wrong.