-
-
Notifications
You must be signed in to change notification settings - Fork 595
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: binding ContextReplacementPlugin
- Loading branch information
Showing
9 changed files
with
91 additions
and
36 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
37 changes: 37 additions & 0 deletions
37
crates/rspack_binding_options/src/plugins/context_replacement.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,37 @@ | ||
use napi_derive::napi; | ||
use rspack_binding_values::RawRegex; | ||
use rspack_error::Error; | ||
use rspack_plugin_context_replacement::ContextReplacementPluginOptions; | ||
use rspack_regex::RspackRegex; | ||
|
||
#[napi(object, object_to_js = false)] | ||
pub struct RawContextReplacementPluginOptions { | ||
pub resource_reg_exp: RawRegex, | ||
pub new_content_resource: Option<String>, | ||
pub new_content_recursive: Option<bool>, | ||
pub new_content_reg_exp: Option<RawRegex>, | ||
// new_content_callback | ||
} | ||
|
||
impl TryFrom<RawContextReplacementPluginOptions> for ContextReplacementPluginOptions { | ||
type Error = Error; | ||
|
||
fn try_from(val: RawContextReplacementPluginOptions) -> Result<Self, Self::Error> { | ||
let new_content_reg_exp = match val.new_content_reg_exp { | ||
Some(js_regex) => { | ||
let regex = RspackRegex::with_flags(&js_regex.source, &js_regex.flags)?; | ||
Some(regex) | ||
} | ||
None => None, | ||
}; | ||
Ok(Self { | ||
resource_reg_exp: RspackRegex::with_flags( | ||
&val.resource_reg_exp.source, | ||
&val.resource_reg_exp.flags, | ||
)?, | ||
new_content_resource: val.new_content_resource, | ||
new_content_recursive: val.new_content_recursive, | ||
new_content_reg_exp, | ||
}) | ||
} | ||
} |
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 |
---|---|---|
@@ -1,4 +1,7 @@ | ||
mod context_replacement; | ||
mod css_extract_additional_data; | ||
mod js_loader; | ||
|
||
pub use context_replacement::*; | ||
pub(super) use css_extract_additional_data::CssExtractRspackAdditionalDataPlugin; | ||
pub(super) use js_loader::{JsLoaderRspackPlugin, JsLoaderRunner}; |
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