Skip to content

Commit

Permalink
refactor!: use swc_plugin_prefresh instead of builtin swc plugin (#7069)
Browse files Browse the repository at this point in the history
  • Loading branch information
LingyuCoder authored Jul 8, 2024
1 parent 7e79786 commit 36673f2
Show file tree
Hide file tree
Showing 54 changed files with 310 additions and 896 deletions.
397 changes: 132 additions & 265 deletions Cargo.lock

Large diffs are not rendered by default.

8 changes: 4 additions & 4 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -61,11 +61,11 @@ tikv-jemallocator = { version = "=0.5.4", features = ["disable_initial_exec_tls"
# Must be pinned with the same swc versions
#rkyv = { version = "=0.7.44" } # synced with swc wasm plugin
swc_config = { version = "=0.1.14" }
swc_core = { version = "0.95.7", default-features = false }
swc_ecma_minifier = { version = "=0.197.0", default-features = false }
swc_error_reporters = { version = "=0.18.0" }
swc_core = { version = "0.96.9", default-features = false }
swc_ecma_minifier = { version = "=0.197.3", default-features = false }
swc_error_reporters = { version = "=0.18.1" }
swc_html = { version = "=0.142.0" }
swc_html_minifier = { version = "=0.139.0" }
swc_html_minifier = { version = "=0.139.1" }
swc_node_comments = { version = "=0.21.0" }

[profile.dev]
Expand Down
1 change: 0 additions & 1 deletion crates/rspack_loader_swc/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,3 @@ swc_config = { workspace = true }
swc_core = { workspace = true, features = ["base", "ecma_ast", "common"] }
tokio = { workspace = true }
url = "2.5.0"
xxhash-rust = { workspace = true, features = ["xxh32"] }
5 changes: 1 addition & 4 deletions crates/rspack_loader_swc/src/options.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use rspack_swc_visitors::{ImportOptions, PreactOptions, RawImportOptions, RawPreactOptions};
use rspack_swc_visitors::{ImportOptions, RawImportOptions};
use serde::Deserialize;
use swc_config::config_types::BoolConfig;
use swc_core::base::config::{
Expand All @@ -10,13 +10,11 @@ use swc_core::base::config::{
#[serde(rename_all = "camelCase", default)]
pub struct RawRspackExperiments {
pub import: Option<Vec<RawImportOptions>>,
pub preact: Option<RawPreactOptions>,
}

#[derive(Default, Debug)]
pub(crate) struct RspackExperiments {
pub(crate) import: Option<Vec<ImportOptions>>,
pub(crate) preact: Option<PreactOptions>,
}

impl From<RawRspackExperiments> for RspackExperiments {
Expand All @@ -25,7 +23,6 @@ impl From<RawRspackExperiments> for RspackExperiments {
import: value
.import
.map(|i| i.into_iter().map(|v| v.into()).collect()),
preact: value.preact,
}
}
}
Expand Down
17 changes: 5 additions & 12 deletions crates/rspack_loader_swc/src/transformer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,13 @@ use std::sync::Arc;

use either::Either;
use rspack_core::CompilerOptions;
use rspack_swc_visitors::PreactOptions;
use swc_core::atoms::Atom;
use swc_core::common::collections::AHashMap;
use swc_core::common::BytePos;
use swc_core::common::{chain, comments::Comments, Mark, SourceMap};
use swc_core::common::{comments::Comments, Mark, SourceMap};
use swc_core::ecma::ast::Ident;
use swc_core::ecma::visit::{noop_visit_type, Visit};
use swc_core::ecma::{transforms::base::pass::noop, visit::Fold};
use xxhash_rust::xxh32::xxh32;

use crate::options::RspackExperiments;

Expand Down Expand Up @@ -41,17 +39,12 @@ pub(crate) fn transform<'a>(
_top_level_mark: Mark,
_unresolved_mark: Mark,
_cm: Arc<SourceMap>,
content: &'a String,
_content: &'a str,
rspack_experiments: &'a RspackExperiments,
) -> impl Fold + 'a {
chain!(
either!(rspack_experiments.import, |options| {
rspack_swc_visitors::import(options)
}),
either!(rspack_experiments.preact, |options: &PreactOptions| {
rspack_swc_visitors::preact(options.clone(), xxh32(content.as_bytes(), 0).to_string())
}),
)
either!(rspack_experiments.import, |options| {
rspack_swc_visitors::import(options)
})
}

pub struct IdentCollector {
Expand Down
1 change: 0 additions & 1 deletion crates/rspack_swc_visitors/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,3 @@ swc_core = { workspace = true, features = [
"ecma_transforms_optimization",
] }
swc_plugin_import = { path = "../swc_plugin_import" }
swc_plugin_preact = { path = "../swc_plugin_preact" }
3 changes: 0 additions & 3 deletions crates/rspack_swc_visitors/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
mod react;
pub use react::ReactOptions;

mod preact;
pub use preact::{preact, PreactOptions, RawPreactOptions};

mod define;
pub use define::{define, Define, RawDefine};

Expand Down
3 changes: 0 additions & 3 deletions crates/rspack_swc_visitors/src/preact.rs

This file was deleted.

25 changes: 0 additions & 25 deletions crates/swc_plugin_preact/Cargo.toml

This file was deleted.

Loading

2 comments on commit 36673f2

@rspack-bot
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

📝 Ran ecosystem CI: Open

suite result
modernjs ❌ failure
_selftest ✅ success
nx ✅ success
rspress ✅ success
rsbuild ✅ success
examples ✅ success

@rspack-bot
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

📝 Benchmark detail: Open

Name Base (2024-07-08 d14720d) Current Change
10000_development-mode + exec 2.16 s ± 25 ms 2.16 s ± 21 ms +0.06 %
10000_development-mode_hmr + exec 692 ms ± 2.9 ms 699 ms ± 12 ms +0.90 %
10000_production-mode + exec 2.73 s ± 23 ms 2.79 s ± 32 ms +2.05 %
arco-pro_development-mode + exec 1.91 s ± 87 ms 1.88 s ± 63 ms -1.47 %
arco-pro_development-mode_hmr + exec 435 ms ± 3.2 ms 435 ms ± 1.2 ms +0.03 %
arco-pro_production-mode + exec 3.42 s ± 95 ms 3.41 s ± 75 ms -0.25 %
threejs_development-mode_10x + exec 1.58 s ± 19 ms 1.6 s ± 22 ms +1.37 %
threejs_development-mode_10x_hmr + exec 798 ms ± 6.9 ms 824 ms ± 11 ms +3.31 %
threejs_production-mode_10x + exec 5.58 s ± 29 ms 5.63 s ± 37 ms +1.06 %

Please sign in to comment.