Skip to content

Commit 800f51a

Browse files
authoredMar 17, 2025··
feat(es/minifier): Default to the smallest size (#10218)
**Description:** AFAIK all bundlers used in production support extracting license comments. I think we can default to the smallest size.
1 parent 611c5b1 commit 800f51a

File tree

6 files changed

+19
-54
lines changed

6 files changed

+19
-54
lines changed
 

‎.changeset/loud-humans-arrive.md

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
swc_core: minor
3+
swc_ecma_minifier: minor
4+
---
5+
6+
feat(es/minifier): Default to smallest size
Original file line numberDiff line numberDiff line change
@@ -1,2 +1 @@
1-
y=(value// @license comment
2-
)=>foo();
1+
y=value=>foo();

‎crates/swc/tests/size.rs

+2-3
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ use flate2::{write::GzEncoder, Compression};
77
use humansize::format_size;
88
use indexmap::IndexMap;
99
use rustc_hash::FxBuildHasher;
10-
use swc::{config::JsMinifyOptions, BoolOrDataConfig, Compiler};
10+
use swc::{config::JsMinifyOptions, Compiler};
1111
use swc_common::{FileName, GLOBALS};
1212
use swc_ecma_utils::parallel::{Parallel, ParallelExt};
1313
use testing::NormalizedOutput;
@@ -115,8 +115,7 @@ fn run(src: &str) -> FileSize {
115115
let c = Compiler::new(cm.clone());
116116
let fm = cm.new_source_file(FileName::Anon.into(), src.into());
117117

118-
let mut config = JsMinifyOptions::default();
119-
config.format.comments = BoolOrDataConfig::from_bool(false);
118+
let config = JsMinifyOptions::default();
120119

121120
let output = c.minify(fm, &handler, &config, Default::default()).unwrap();
122121

‎crates/swc/tests/vercel/full/firebase/dist/1/output/index.js

+3-48
Original file line numberDiff line numberDiff line change
@@ -67,38 +67,8 @@ var e, t = require("@firebase/util"), n = require("tslib"), r = require("@fireba
6767
options: this.options
6868
};
6969
}, e;
70-
}(), s = ((e = {})["no-app"] = "No Firebase App '{$appName}' has been created - call Firebase App.initializeApp()", e["invalid-app-argument"] = "firebase.{$appName}() takes either no argument or a Firebase App instance.", e), c = new t.ErrorFactory("app-compat", "Firebase", s), u = /**
71-
* @license
72-
* Copyright 2019 Google LLC
73-
*
74-
* Licensed under the Apache License, Version 2.0 (the "License");
75-
* you may not use this file except in compliance with the License.
76-
* You may obtain a copy of the License at
77-
*
78-
* http://www.apache.org/licenses/LICENSE-2.0
79-
*
80-
* Unless required by applicable law or agreed to in writing, software
81-
* distributed under the License is distributed on an "AS IS" BASIS,
82-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
83-
* See the License for the specific language governing permissions and
84-
* limitations under the License.
85-
*/ function e() {
86-
var r = /**
87-
* @license
88-
* Copyright 2019 Google LLC
89-
*
90-
* Licensed under the Apache License, Version 2.0 (the "License");
91-
* you may not use this file except in compliance with the License.
92-
* You may obtain a copy of the License at
93-
*
94-
* http://www.apache.org/licenses/LICENSE-2.0
95-
*
96-
* Unless required by applicable law or agreed to in writing, software
97-
* distributed under the License is distributed on an "AS IS" BASIS,
98-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
99-
* See the License for the specific language governing permissions and
100-
* limitations under the License.
101-
*/ function(e) {
70+
}(), s = ((e = {})["no-app"] = "No Firebase App '{$appName}' has been created - call Firebase App.initializeApp()", e["invalid-app-argument"] = "firebase.{$appName}() takes either no argument or a Firebase App instance.", e), c = new t.ErrorFactory("app-compat", "Firebase", s), u = function e() {
71+
var r = function(e) {
10272
var n = {}, r = {
10373
__esModule: !0,
10474
initializeApp: function(i, a) {
@@ -164,22 +134,7 @@ var e, t = require("@firebase/util"), n = require("tslib"), r = require("@fireba
164134
deepExtend: t.deepExtend
165135
}), r;
166136
}(), l = new a.Logger("@firebase/app-compat");
167-
/**
168-
* @license
169-
* Copyright 2020 Google LLC
170-
*
171-
* Licensed under the Apache License, Version 2.0 (the "License");
172-
* you may not use this file except in compliance with the License.
173-
* You may obtain a copy of the License at
174-
*
175-
* http://www.apache.org/licenses/LICENSE-2.0
176-
*
177-
* Unless required by applicable law or agreed to in writing, software
178-
* distributed under the License is distributed on an "AS IS" BASIS,
179-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
180-
* See the License for the specific language governing permissions and
181-
* limitations under the License.
182-
*/ if (t.isBrowser() && void 0 !== self.firebase) {
137+
if (t.isBrowser() && void 0 !== self.firebase) {
183138
l.warn("\n Warning: Firebase is already defined in the global scope. Please make sure\n Firebase library is only loaded once.\n ");
184139
var d = self.firebase.SDK_VERSION;
185140
d && d.indexOf("LITE") >= 0 && l.warn("\n Warning: You are trying to load Firebase while using Firebase Performance standalone script.\n You should load Firebase Performance with this instance of Firebase to avoid loading duplicate code.\n ");

‎crates/swc_ecma_minifier/src/js.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,7 @@ impl Default for JsMinifyFormatOptions {
199199
}
200200

201201
fn default_comments() -> BoolOrDataConfig<JsMinifyCommentOption> {
202-
BoolOrDataConfig::from_obj(JsMinifyCommentOption::PreserveSomeComments)
202+
BoolOrDataConfig::from_bool(false)
203203
}
204204

205205
#[derive(Debug, Clone, Serialize, Deserialize, Default)]

‎packages/core/__tests__/minify_test.mjs

+6
Original file line numberDiff line numberDiff line change
@@ -216,6 +216,9 @@ describe("should remove comments", () => {
216216
mangle: {
217217
topLevel: true,
218218
},
219+
format: {
220+
comments: 'some'
221+
}
219222
}
220223
);
221224

@@ -244,6 +247,9 @@ describe("should remove comments", () => {
244247
mangle: {
245248
topLevel: true,
246249
},
250+
format: {
251+
comments: 'some'
252+
}
247253
}
248254
);
249255

0 commit comments

Comments
 (0)
Please sign in to comment.