aboutsummaryrefslogtreecommitdiff
path: root/src/bundler.zig
diff options
context:
space:
mode:
authorGravatar Dylan Conway <35280289+dylan-conway@users.noreply.github.com> 2023-04-20 05:23:12 -0700
committerGravatar GitHub <noreply@github.com> 2023-04-20 05:23:12 -0700
commitd78ecc76c854310fd47da32071d22301b0782ec3 (patch)
treedcee5bde1b3598203de25f07a632cfb55aaa01e5 /src/bundler.zig
parent9e7bfdec8cd4fc1827a5d793844afe36638ded37 (diff)
downloadbun-d78ecc76c854310fd47da32071d22301b0782ec3.tar.gz
bun-d78ecc76c854310fd47da32071d22301b0782ec3.tar.zst
bun-d78ecc76c854310fd47da32071d22301b0782ec3.zip
Symbol minification (#2695)
* minify * Update renamer.zig * --minify-whitespace * Speed up minification a little * handle private names * 5% faster minification * use helper function * fix nested scope slots * `bun build --minify` gets another +8% faster * print semicolons afterwards * print semicolon after checking error * after all error checking * Delete code for generating legacy bundes * remove extra whitespace around if statements * print space before import identifier * Use `@constCast` * Make `S.Local#decls` use `BabyList(Decl)` * Add `fromSlice` helper to `BabyList` * Remove unnecessary optional chains * minify `undefined, true, false` * Another @constCast * Implement merge adjacent local var * Support --minify in `bun build --transform` * skip comments when counting character frequencies * Don't wrap commonjs with --transform on (unless targeting bun) * Support --minify in the runtime * Fix edgecase with import * as * don't infinite loop * --trnasform shouldn't mess with require * Only track comments when minifying --------- Co-authored-by: Jarred Sumner <709451+Jarred-Sumner@users.noreply.github.com>
Diffstat (limited to 'src/bundler.zig')
-rw-r--r--src/bundler.zig22
1 files changed, 18 insertions, 4 deletions
diff --git a/src/bundler.zig b/src/bundler.zig
index 34544afb0..f2da1a960 100644
--- a/src/bundler.zig
+++ b/src/bundler.zig
@@ -738,8 +738,6 @@ pub const Bundler = struct {
Output.flush();
}
- pub const GenerateNodeModulesBundle = @import("./bundler/generate_node_modules_bundle.zig");
-
pub const BuildResolveResultPair = struct {
written: usize,
input_fd: ?StoredFileDescriptorType,
@@ -1155,6 +1153,9 @@ pub const Bundler = struct {
.source_map_handler = source_map_context,
.rewrite_require_resolve = bundler.options.platform != .node,
.minify_whitespace = bundler.options.minify_whitespace,
+ .minify_syntax = bundler.options.minify_syntax,
+ .minify_identifiers = bundler.options.minify_identifiers,
+ .transform_only = bundler.options.transform_only,
},
enable_source_map,
),
@@ -1174,6 +1175,9 @@ pub const Bundler = struct {
.css_import_behavior = bundler.options.cssImportBehavior(),
.rewrite_require_resolve = bundler.options.platform != .node,
.minify_whitespace = bundler.options.minify_whitespace,
+ .minify_syntax = bundler.options.minify_syntax,
+ .minify_identifiers = bundler.options.minify_identifiers,
+ .transform_only = bundler.options.transform_only,
},
enable_source_map,
),
@@ -1191,6 +1195,10 @@ pub const Bundler = struct {
.require_ref = ast.require_ref,
.css_import_behavior = bundler.options.cssImportBehavior(),
.source_map_handler = source_map_context,
+ .minify_whitespace = bundler.options.minify_whitespace,
+ .minify_syntax = bundler.options.minify_syntax,
+ .minify_identifiers = bundler.options.minify_identifiers,
+ .transform_only = bundler.options.transform_only,
},
enable_source_map,
),
@@ -1208,6 +1216,10 @@ pub const Bundler = struct {
.require_ref = ast.require_ref,
.css_import_behavior = bundler.options.cssImportBehavior(),
.source_map_handler = source_map_context,
+ .minify_whitespace = bundler.options.minify_whitespace,
+ .minify_syntax = bundler.options.minify_syntax,
+ .minify_identifiers = bundler.options.minify_identifiers,
+ .transform_only = bundler.options.transform_only,
},
enable_source_map,
),
@@ -1377,6 +1389,7 @@ pub const Bundler = struct {
opts.features.trim_unused_imports = bundler.options.trim_unused_imports orelse loader.isTypeScript();
opts.features.should_fold_typescript_constant_expressions = loader.isTypeScript() or platform.isBun() or bundler.options.inlining;
opts.features.dynamic_require = platform.isBun();
+ opts.transform_only = bundler.options.transform_only;
// @bun annotation
opts.features.dont_bundle_twice = this_parse.dont_bundle_twice;
@@ -1400,7 +1413,7 @@ pub const Bundler = struct {
opts.filepath_hash_for_hmr = file_hash orelse 0;
opts.features.auto_import_jsx = bundler.options.auto_import_jsx;
opts.warn_about_unbundled_modules = platform.isNotBun();
- opts.features.jsx_optimization_inline = (bundler.options.jsx_optimization_inline orelse (platform.isBun() and jsx.parse and
+ opts.features.jsx_optimization_inline = opts.features.allow_runtime and (bundler.options.jsx_optimization_inline orelse (platform.isBun() and jsx.parse and
!jsx.development)) and
(jsx.runtime == .automatic or jsx.runtime == .classic);
@@ -1408,6 +1421,7 @@ pub const Bundler = struct {
opts.features.hoist_bun_plugin = this_parse.hoist_bun_plugin;
opts.features.inject_jest_globals = this_parse.inject_jest_globals;
opts.features.minify_syntax = bundler.options.minify_syntax;
+ opts.features.minify_identifiers = bundler.options.minify_identifiers;
if (bundler.macro_context == null) {
bundler.macro_context = js_ast.Macro.MacroContext.init(bundler);
@@ -1727,7 +1741,7 @@ pub const Bundler = struct {
if (log.level == .verbose) {
bundler.resolver.debug_logs = try DebugLogs.init(allocator);
}
-
+ bundler.options.transform_only = true;
var did_start = false;
if (bundler.options.output_dir_handle == null) {