Skip to content

Commit

Permalink
feat(tasks/minsize): define process.env.NODE_ENV for react
Browse files Browse the repository at this point in the history
  • Loading branch information
Boshen committed Dec 25, 2024
1 parent 11c4bd8 commit b94f6ba
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 1 deletion.
2 changes: 2 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions tasks/minsize/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ oxc_codegen = { workspace = true }
oxc_minifier = { workspace = true }
oxc_parser = { workspace = true }
oxc_span = { workspace = true }
oxc_transformer = { workspace = true }
oxc_semantic = { workspace = true }

flate2 = { workspace = true }
oxc_tasks_common = { workspace = true }
Expand Down
2 changes: 1 addition & 1 deletion tasks/minsize/minsize.snap
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
| Oxc | ESBuild | Oxc | ESBuild |
Original | minified | minified | gzip | gzip | Fixture
-------------------------------------------------------------------------------------
72.14 kB | 24.04 kB | 23.70 kB | 8.61 kB | 8.54 kB | react.development.js
72.14 kB | 24.00 kB | 23.70 kB | 8.58 kB | 8.54 kB | react.development.js

173.90 kB | 61.55 kB | 59.82 kB | 19.54 kB | 19.33 kB | moment.js

Expand Down
9 changes: 9 additions & 0 deletions tasks/minsize/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,10 @@ use oxc_allocator::Allocator;
use oxc_codegen::{CodeGenerator, CodegenOptions};
use oxc_minifier::{CompressOptions, MangleOptions, Minifier, MinifierOptions};
use oxc_parser::Parser;
use oxc_semantic::SemanticBuilder;
use oxc_span::SourceType;
use oxc_tasks_common::{project_root, TestFile, TestFiles};
use oxc_transformer::{ReplaceGlobalDefines, ReplaceGlobalDefinesConfig};
use rustc_hash::FxHashMap;

// #[test]
Expand Down Expand Up @@ -137,6 +139,13 @@ fn minify(source_text: &str, source_type: SourceType, options: MinifierOptions)
let allocator = Allocator::default();
let ret = Parser::new(&allocator, source_text, source_type).parse();
let mut program = ret.program;
let (symbols, scopes) =
SemanticBuilder::new().build(&program).semantic.into_symbol_table_and_scope_tree();
let _ = ReplaceGlobalDefines::new(
&allocator,
ReplaceGlobalDefinesConfig::new(&[("process.env.NODE_ENV", "'development'")]).unwrap(),
)
.build(symbols, scopes, &mut program);
let ret = Minifier::new(options).build(&allocator, &mut program);
CodeGenerator::new()
.with_options(CodegenOptions { minify: true, ..CodegenOptions::default() })
Expand Down

0 comments on commit b94f6ba

Please sign in to comment.