Skip to content

Commit 857097f

Browse files
committed
减少 wasm 包大小: 2.1mb => 1.5mb, br 压缩后 (0.54mb)
1 parent b853b17 commit 857097f

File tree

7 files changed

+26
-44
lines changed

7 files changed

+26
-44
lines changed

Cargo.toml

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ edition = "2024"
88
rust-version = "1.85"
99

1010
[profile.wasm-release]
11-
# Use release profile as default values
1211
inherits = "release"
12+
debug = 0
1313
# Optimize with size in mind, also try "s", sometimes it is better.
1414
# This doesn't increase compilation times compared to -O3, great improvements
1515
opt-level = "z"
@@ -18,5 +18,4 @@ opt-level = "z"
1818
lto = "fat"
1919
# When building crates, optimize larger chunks at a time
2020
# Slows compile times, marginal improvements
21-
codegen-units = 1
22-
panic = "abort"
21+
codegen-units = 1

assets/fonts/NotoEmoji-Regular.ttf

-409 KB
Binary file not shown.

assets/fonts/emoji-icon-font-mit-license.txt

Lines changed: 0 additions & 9 deletions
This file was deleted.

assets/fonts/emoji-icon-font.ttf

-310 KB
Binary file not shown.

assets/fonts/iconfont.ttf

41.4 KB
Binary file not shown.

build-wasm.sh

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,18 @@ cargo build --profile wasm-release --target wasm32-unknown-unknown --bin simuver
44
for i in target/wasm32-unknown-unknown/wasm-release/*.wasm;
55
do
66
wasm-bindgen --no-typescript --out-dir wasm --web "$i";
7-
# 优化 wasm 包大小
7+
# 优化 wasm 包大小 (未压缩)
88
# 2024/5/5, 4.6MB -> 3.2MB
99
# 2024/6/22, 3.2MB -> 2.2MB
1010
# 2025/3/1, 2.2MB -> 2.1MB
11+
# 2025/6/22, 2.1MB -> 1.5MB
1112
filename=$(basename "$i");
1213
name_no_extension="${filename%.wasm}";
1314
wasm-opt -Oz --output wasm/"$name_no_extension"_optimized_bg.wasm wasm/"$name_no_extension"_bg.wasm
15+
cd wasm
16+
# 删除旧的压缩文件
17+
rm -f "$name_no_extension"_bg.wasm.br
18+
# 压缩并保留原文件
19+
brotli -Zk "$name_no_extension"_optimized_bg.wasm -o "$name_no_extension"_bg.wasm.br
20+
cd ../
1421
done

simuverse/src/setting/control_panel.rs

Lines changed: 16 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ impl ControlPanel {
139139

140140
self.top_bar_ui(ctx);
141141

142-
let window = egui::Window::new("Settings")
142+
let window = egui::Window::new("Settings")
143143
.id(egui::Id::new("particles_window_options")) // required since we change the title
144144
.resizable(false)
145145
.collapsible(true)
@@ -181,21 +181,25 @@ impl ControlPanel {
181181
});
182182
}
183183

184+
/// 顶部菜单栏
185+
///
186+
/// # NOTE:
187+
/// 下边的  字符不是乱码,它是 iconfont 中的一个图标,编辑器中无法正确显示
184188
fn top_bar_ui(&mut self, ctx: &Context) {
185189
let mut menu_items = vec![
186-
("🌾 Vector Field", SimuType::Field),
187-
("💦 LBM Fluid", SimuType::Fluid),
188-
("💥 Perlin Noise", SimuType::Noise),
189-
("👗 Position-based Dynamics", SimuType::PBDynamic),
190+
("Vector Field", SimuType::Field),
191+
("LBM Fluid", SimuType::Fluid),
192+
("Perlin Noise", SimuType::Noise),
193+
("Position-based Dynamics", SimuType::PBDynamic),
190194
];
191195
if cfg!(not(target_arch = "wasm32")) {
192-
menu_items.push(("🚚 CAD Kenel", SimuType::CAD));
196+
menu_items.push((" CAD Kenel", SimuType::CAD));
193197
}
194198
egui::TopBottomPanel::top("simuverse_top_bar").show(ctx, |ui| {
195199
ui.horizontal_wrapped(|ui| {
196200
ui.visuals_mut().button_frame = false;
197201
if ui
198-
.hyperlink_to("🌌 Wgpu Simuverse", "https://github.com/jinleili/simuverse")
202+
.hyperlink_to(" Wgpu Simuverse", "https://github.com/jinleili/simuverse")
199203
.clicked()
200204
{
201205
webbrowser::open("https://github.com/jinleili/simuverse").unwrap();
@@ -362,39 +366,20 @@ pub fn setup_custom_fonts(ctx: &egui::Context) {
362366
})
363367
.into(),
364368
);
365-
// Some good looking emojis.
366369
fonts.font_data.insert(
367-
"NotoEmoji-Regular".to_owned(),
368-
egui::FontData::from_static(include_bytes!(
369-
"../../../assets/fonts/NotoEmoji-Regular.ttf"
370-
))
371-
.tweak(egui::FontTweak {
372-
scale: 0.91, // make it smaller
373-
y_offset_factor: -0.15, // move it up
374-
y_offset: 0.0,
375-
..Default::default()
376-
})
377-
.into(),
378-
);
379-
// Bigger emojis, and more. <http://jslegers.github.io/emoji-icon-font/>:
380-
fonts.font_data.insert(
381-
"emoji-icon-font".to_owned(),
382-
egui::FontData::from_static(include_bytes!("../../../assets/fonts/emoji-icon-font.ttf"))
370+
"iconfont".to_owned(),
371+
egui::FontData::from_static(include_bytes!("../../../assets/fonts/iconfont.ttf"))
383372
.tweak(egui::FontTweak {
384-
scale: 0.88, // make it smaller
385-
y_offset_factor: 0.07, // move it down slightly
373+
scale: 0.91, // make it smaller
374+
y_offset_factor: 0., // move it up
386375
y_offset: 0.0,
387376
..Default::default()
388377
})
389378
.into(),
390379
);
391380
fonts.families.insert(
392381
egui::FontFamily::Proportional,
393-
vec![
394-
ZH_TINY.to_owned(),
395-
"NotoEmoji-Regular".to_owned(),
396-
"emoji-icon-font".to_owned(),
397-
],
382+
vec![ZH_TINY.to_owned(), "iconfont".to_owned()],
398383
);
399384

400385
// 如果没有这项设置,`syntax_highlighting::code_view_ui` 无法渲染任何字符

0 commit comments

Comments
 (0)