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

[Breaking Change] refactor: not write stats.json anymore #1485

Merged
merged 1 commit into from
Aug 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
4 changes: 2 additions & 2 deletions crates/mako/src/config/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -718,8 +718,8 @@ const DEFAULT_CONFIG: &str = r#"
"rscServer": false,
"rscClient": false,
"experimental": {
"webpackSyntaxValidate": [],
"requireContext": true,
"webpackSyntaxValidate": [],
"requireContext": true,
"detectCircularDependence": { "ignores": ["node_modules"], "graphviz": false }
},
"useDefineForClassFields": true,
Expand Down
13 changes: 1 addition & 12 deletions crates/mako/src/generate/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ use crate::dev::update::UpdateResult;
use crate::generate::generate_chunks::{ChunkFile, ChunkFileType};
use crate::module::{Dependency, ModuleId};
use crate::plugins::bundless_compiler::BundlessCompiler;
use crate::stats::{write_stats, StatsJsonMap};
use crate::stats::StatsJsonMap;
use crate::utils::base64_encode;
use crate::visitors::async_module::mark_async;

Expand Down Expand Up @@ -182,10 +182,6 @@ impl Compiler {
// generate stats
let stats = self.create_stats_info();

if self.context.config.stats.is_some() {
write_stats(&self.context.config.output.path, &stats);
}

// build_success hook
self.context
.plugin_driver
Expand Down Expand Up @@ -351,13 +347,6 @@ impl Compiler {

let stats = self.create_stats_info();

// 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.is_some() {
write_stats(&self.context.config.output.path, &stats);
}

let t_generate = t_generate.elapsed();

debug!(
Expand Down
4 changes: 3 additions & 1 deletion examples/import-resources/mako.config.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
{
"inlineLimit": 0,
"stats": true,
"stats": {
"modules": true
},
"mdx": true,
"manifest": {},
"manifestConfig": {
Expand Down
4 changes: 3 additions & 1 deletion examples/tree-shaking/mako.config.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
{
"mode": "production",
"stats": true,
"stats": {
"modules": true
},
"entry": {
"index": "./index.js"
},
Expand Down
17 changes: 10 additions & 7 deletions packages/bundler-mako/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,16 @@ exports.build = async function (opts) {
makoConfig.moduleIdStrategy = 'hashed';
}

makoConfig.plugins = makoConfig.plugins || [];

let statsJson;
makoConfig.plugins.push({
name: 'mako-stats',
generateEnd: (args) => {
statsJson = args.stats;
},
});

const { build } = require('@umijs/mako');
try {
await build({
Expand All @@ -46,13 +56,6 @@ exports.build = async function (opts) {
err.stack = null;
throw err;
}
const outputPath = path.resolve(opts.cwd, opts.config.outputPath || 'dist');

const statsJsonPath = path.join(outputPath, 'stats.json');
const statsJson = JSON.parse(fs.readFileSync(statsJsonPath, 'utf-8'));

// remove stats.json file if user did not enable it
if (originStats !== true) fs.rmSync(statsJsonPath);

const stats = {
compilation: {
Expand Down