Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: support rspack.DllPlugin & rspack.DllReferencePlugin #8296

Merged
merged 26 commits into from
Nov 11, 2024
Merged
Show file tree
Hide file tree
Changes from 18 commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
ddc113c
feat: rewrite dll-plugin by rust
GiveMe-A-Name Oct 28, 2024
61a8386
feat: support rspack.DllReferencePlugin
GiveMe-A-Name Oct 31, 2024
7cd40f2
test: add dll plugin tests
GiveMe-A-Name Oct 31, 2024
31cf010
Merge branch 'main' into feat/dll-plugin
GiveMe-A-Name Oct 31, 2024
1ac86e9
refactor: improve delegated_module code
GiveMe-A-Name Oct 31, 2024
e35cac8
docs: add dll-plugin & dll-refernce-plugin docs
GiveMe-A-Name Nov 1, 2024
68beb1a
fix: flagAllModuleAsUsedPlugin add_extra_reason
GiveMe-A-Name Nov 5, 2024
772f5c1
chore: rename some vars
GiveMe-A-Name Nov 5, 2024
8f25d29
fix: typo
GiveMe-A-Name Nov 5, 2024
23bc688
Merge branch 'main' into feat/dll-plugin
GiveMe-A-Name Nov 5, 2024
e4246b0
fix: remove the unnecessary generics
GiveMe-A-Name Nov 5, 2024
43555e6
fix: typo
GiveMe-A-Name Nov 5, 2024
1f225e8
fix: cargo clippy test
GiveMe-A-Name Nov 5, 2024
0ba5e31
fix: remove unused dependency rspack_macros
GiveMe-A-Name Nov 5, 2024
45c78df
Merge branch 'main' into feat/dll-plugin
GiveMe-A-Name Nov 6, 2024
2c044ec
docs: add dll & dll-reference plugin zh docs
GiveMe-A-Name Nov 6, 2024
0c05841
fix: resolved merge conflict
GiveMe-A-Name Nov 6, 2024
71811aa
fix: resolved some issues
GiveMe-A-Name Nov 8, 2024
3ac6301
chore: add some annotations
GiveMe-A-Name Nov 8, 2024
2c996a4
chore: add some annotations
GiveMe-A-Name Nov 8, 2024
3f4d02d
fix: update manifest content item exports type
GiveMe-A-Name Nov 8, 2024
a34740c
fix: update dll manifest types
GiveMe-A-Name Nov 8, 2024
7015b94
chore:update docs
GiveMe-A-Name Nov 8, 2024
7a03d0c
chore: clippy fix
GiveMe-A-Name Nov 8, 2024
d075bcc
fix: bailout use build_info.module_concatenation_bailout
GiveMe-A-Name Nov 11, 2024
c294041
Merge branch 'main' into feat/dll-plugin
GiveMe-A-Name Nov 11, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

66 changes: 66 additions & 0 deletions crates/node_binding/binding.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -303,6 +303,10 @@ export enum BuiltinPluginName {
SizeLimitsPlugin = 'SizeLimitsPlugin',
NoEmitOnErrorsPlugin = 'NoEmitOnErrorsPlugin',
ContextReplacementPlugin = 'ContextReplacementPlugin',
DllEntryPlugin = 'DllEntryPlugin',
DllReferenceAgencyPlugin = 'DllReferenceAgencyPlugin',
LibManifestPlugin = 'LibManifestPlugin',
FlagAllModulesAsUsedPlugin = 'FlagAllModulesAsUsedPlugin',
HttpExternalsRspackPlugin = 'HttpExternalsRspackPlugin',
CopyRspackPlugin = 'CopyRspackPlugin',
HtmlRspackPlugin = 'HtmlRspackPlugin',
Expand Down Expand Up @@ -446,6 +450,22 @@ export interface JsBeforeResolveArgs {
issuer: string
}

export interface JsBuildMeta {
strictEsmModule: boolean
hasTopLevelAwait: boolean
esm: boolean
exportsType: 'unset' | 'default' | 'namespace' | 'flagged' | 'dynamic'
defaultObject: 'false' | 'redirect' | JsBuildMetaDefaultObjectRedirectWarn
moduleArgument: 'module' | 'webpackModule'
exportsArgument: 'exports' | 'webpackExports'
sideEffectFree?: boolean
exportsFinalName?: Array<[string, string]> | undefined
}

export interface JsBuildMetaDefaultObjectRedirectWarn {
redirectWarn: JsDefaultObjectRedirectWarnObject
}

export interface JsBuildTimeExecutionOption {
publicPath?: string
baseUri?: string
Expand Down Expand Up @@ -519,6 +539,10 @@ export interface JsCreateData {
resource: string
}

export interface JsDefaultObjectRedirectWarnObject {
ignore: boolean
}

export interface JsDiagnostic {
message: string
help?: string
Expand Down Expand Up @@ -1269,6 +1293,35 @@ export interface RawCssParserOptions {
namedExports?: boolean
}

export interface RawDllEntryPluginOptions {
context: string
entries: Array<string>
name: string
}

export interface RawDllManifest {
content: RawDllManifestContent
name?: string
type?: string
}

export interface RawDllManifestContentItem {
buildMeta?: JsBuildMeta
exports?: Array<string>
id?: string
}

export interface RawDllReferenceAgencyPluginOptions {
context?: string
name?: string
extensions: Array<string>
scope?: string
sourceType?: string
type: string
content?: RawDllManifestContent
manifest?: RawDllManifest
}

export interface RawDraft {
customMedia: boolean
}
Expand Down Expand Up @@ -1347,6 +1400,10 @@ export interface RawFallbackCacheGroupOptions {
automaticNameDelimiter?: string
}

export interface RawFlagAllModulesAsUsedPluginOptions {
explanation: string
}

export interface RawFuncUseCtx {
resource?: string
realResource?: string
Expand Down Expand Up @@ -1475,6 +1532,15 @@ export interface RawLazyCompilationOption {
cacheable: boolean
}

export interface RawLibManifestPluginOptions {
context?: string
entryOnly?: boolean
name?: JsFilename
path: JsFilename
format?: boolean
type?: string
}

export interface RawLightningCssBrowsers {
android?: number
chrome?: number
Expand Down
1 change: 1 addition & 0 deletions crates/rspack_binding_options/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ rspack_plugin_context_replacement = { version = "0.1.0", path = "../rspack_
rspack_plugin_copy = { version = "0.1.0", path = "../rspack_plugin_copy" }
rspack_plugin_css = { version = "0.1.0", path = "../rspack_plugin_css" }
rspack_plugin_devtool = { version = "0.1.0", path = "../rspack_plugin_devtool" }
rspack_plugin_dll = { version = "0.1.0", path = "../rspack_plugin_dll" }
rspack_plugin_dynamic_entry = { version = "0.1.0", path = "../rspack_plugin_dynamic_entry" }
rspack_plugin_ensure_chunk_conditions = { version = "0.1.0", path = "../rspack_plugin_ensure_chunk_conditions" }
rspack_plugin_entry = { version = "0.1.0", path = "../rspack_plugin_entry" }
Expand Down
38 changes: 35 additions & 3 deletions crates/rspack_binding_options/src/options/raw_builtins/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ mod raw_banner;
mod raw_bundle_info;
mod raw_copy;
mod raw_css_extract;
mod raw_dll;
mod raw_html;
mod raw_ignore;
mod raw_lazy_compilation;
Expand All @@ -15,6 +16,7 @@ mod raw_swc_js_minimizer;

use napi::{bindgen_prelude::FromNapiValue, Env, JsUnknown};
use napi_derive::napi;
use raw_dll::{RawDllReferenceAgencyPluginOptions, RawFlagAllModulesAsUsedPluginOptions};
use raw_lightning_css_minimizer::RawLightningCssMinimizerRspackPluginOptions;
use rspack_binding_values::entry::JsEntryPluginOptions;
use rspack_core::{BoxPlugin, Plugin, PluginExt};
Expand All @@ -34,6 +36,9 @@ use rspack_plugin_devtool::{
SourceMapDevToolModuleOptionsPluginOptions, SourceMapDevToolPlugin,
SourceMapDevToolPluginOptions,
};
use rspack_plugin_dll::{
DllEntryPlugin, DllReferenceAgencyPlugin, FlagAllModulesAsUsedPlugin, LibManifestPlugin,
};
use rspack_plugin_dynamic_entry::DynamicEntryPlugin;
use rspack_plugin_ensure_chunk_conditions::EnsureChunkConditionsPlugin;
use rspack_plugin_entry::EntryPlugin;
Expand Down Expand Up @@ -78,9 +83,13 @@ use rspack_plugin_web_worker_template::web_worker_template_plugin;
use rspack_plugin_worker::WorkerPlugin;

pub use self::{
raw_banner::RawBannerPluginOptions, raw_copy::RawCopyRspackPluginOptions,
raw_html::RawHtmlRspackPluginOptions, raw_ignore::RawIgnorePluginOptions,
raw_limit_chunk_count::RawLimitChunkCountPluginOptions, raw_mf::RawContainerPluginOptions,
raw_banner::RawBannerPluginOptions,
raw_copy::RawCopyRspackPluginOptions,
raw_dll::{RawDllEntryPluginOptions, RawLibManifestPluginOptions},
raw_html::RawHtmlRspackPluginOptions,
raw_ignore::RawIgnorePluginOptions,
raw_limit_chunk_count::RawLimitChunkCountPluginOptions,
raw_mf::RawContainerPluginOptions,
raw_progress::RawProgressPluginOptions,
raw_swc_js_minimizer::RawSwcJsMinimizerRspackPluginOptions,
};
Expand Down Expand Up @@ -166,6 +175,10 @@ pub enum BuiltinPluginName {
SizeLimitsPlugin,
NoEmitOnErrorsPlugin,
ContextReplacementPlugin,
DllEntryPlugin,
DllReferenceAgencyPlugin,
LibManifestPlugin,
FlagAllModulesAsUsedPlugin,

// rspack specific plugins
// naming format follow XxxRspackPlugin
Expand Down Expand Up @@ -517,6 +530,25 @@ impl BuiltinPlugin {
let options = raw_options.try_into()?;
plugins.push(ContextReplacementPlugin::new(options).boxed());
}
BuiltinPluginName::DllEntryPlugin => {
let raw_options = downcast_into::<RawDllEntryPluginOptions>(self.options)?;
let options = raw_options.into();
plugins.push(DllEntryPlugin::new(options).boxed());
}
BuiltinPluginName::LibManifestPlugin => {
let raw_options = downcast_into::<RawLibManifestPluginOptions>(self.options)?;
let options = raw_options.into();
plugins.push(LibManifestPlugin::new(options).boxed());
}
BuiltinPluginName::FlagAllModulesAsUsedPlugin => {
let raw_options = downcast_into::<RawFlagAllModulesAsUsedPluginOptions>(self.options)?;
plugins.push(FlagAllModulesAsUsedPlugin::new(raw_options.explanation).boxed())
}
BuiltinPluginName::DllReferenceAgencyPlugin => {
let raw_options = downcast_into::<RawDllReferenceAgencyPluginOptions>(self.options)?;
let options = raw_options.into();
plugins.push(DllReferenceAgencyPlugin::new(options).boxed());
}
}
Ok(())
}
Expand Down
158 changes: 158 additions & 0 deletions crates/rspack_binding_options/src/options/raw_builtins/raw_dll.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,158 @@
use napi_derive::napi;
use rspack_binding_values::{JsBuildMeta, JsFilename};
use rspack_plugin_dll::{
DllEntryPluginOptions, DllManifest, DllManifestContent, DllManifestContentItem,
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<RawDllManifestContent>,
pub manifest: Option<RawDllManifest>,
}

type RawDllManifestContent = HashMap<String, RawDllManifestContentItem>;

#[napi(object, object_to_js = false)]
pub struct RawDllManifestContentItem {
pub build_meta: Option<JsBuildMeta>,
pub exports: Option<Vec<String>>,
pub id: Option<String>,
}

impl From<RawDllManifestContentItem> for DllManifestContentItem {
fn from(value: RawDllManifestContentItem) -> Self {
Self {
build_meta: value.build_meta.map(|meta| meta.into()),
exports: value.exports.map(|exports| {
exports
.into_iter()
.map(|export| Atom::from(export))
.collect::<Vec<_>>()
}),
id: value.id.into(),
}
}
}

#[napi(object, object_to_js = false)]
pub struct RawDllManifest {
pub content: RawDllManifestContent,
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.map(|n| n.into()),
r#type: value.r#type.into(),
}
}
}

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,
}
Loading
Loading