Skip to content

Commit

Permalink
fix: write stats.json in dev when stats is configured
Browse files Browse the repository at this point in the history
  • Loading branch information
sorrycc committed Apr 29, 2024
1 parent e88750e commit 0b7126a
Showing 1 changed file with 19 additions and 9 deletions.
28 changes: 19 additions & 9 deletions crates/mako/src/generate/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ impl Compiler {

// generate stats
let stats = create_stats_info(0, self);
if self.context.config.stats && !self.context.args.watch {
if self.context.config.stats {
write_stats(&stats, self);
}

Expand Down Expand Up @@ -266,18 +266,28 @@ impl Compiler {
// write assets
let t_write_assets = Instant::now();
debug!("write assets");
let assets_info = &(*self.context.assets_info.lock().unwrap());
for (k, v) in assets_info {
let asset_path = &self.context.root.join(k);
let asset_output_path = &config.output.path.join(v);
if asset_path.exists() {
fs::copy(asset_path, asset_output_path)?;
} else {
panic!("asset not found: {}", asset_path.display());
{
let assets_info = &(*self.context.assets_info.lock().unwrap());
for (k, v) in assets_info {
let asset_path = &self.context.root.join(k);
let asset_output_path = &config.output.path.join(v);
if asset_path.exists() {
fs::copy(asset_path, asset_output_path)?;
} else {
panic!("asset not found: {}", asset_path.display());
}
}
}
let t_write_assets = t_write_assets.elapsed();

// TODO: do not write to fs, using jsapi hooks to pass stats
// why generate stats?
// ref: https://github.com/umijs/mako/issues/1107
if self.context.config.stats {
let stats = create_stats_info(0, self);
write_stats(&stats, self);
}

let t_generate = t_generate.elapsed();

debug!(
Expand Down

0 comments on commit 0b7126a

Please sign in to comment.