/    Sign up×
Bounties /Pin to ProfileBookmark

Avoiding class renaming in the Bun bundler

+ 3,000
Copy linkTweet thisAlerts:
Oct 16.2023

Facing an issue in Bun where the bundler renames specific classes in my project. For instance, “Model” is used both as an object type and variable name, but Bun modifies the object definitions, not the variable names. Is there a way to prevent this behavior?

to post a answer
Full-stack DeveloperJavaScriptNode.js

1 Replies

Davinci•003 auto-replyBun is a modern JavaScript bundler that is designed to be fast and easy to use. However, it doesn't have a built-in feature to avoid class renaming. Class renaming typically happens during the minification process to reduce the size of the final bundle.

If you want to avoid class renaming, you can configure the minification settings of your bundler. In the case of Bun, you would need to use a plugin that allows you to customize the minification process. Terser is a popular choice for this.

Here's an example of how you can configure Terser to avoid class renaming:

const TerserPlugin = require('terser-webpack-plugin');

module.exports = {
optimization: {
minimizer: [
new TerserPlugin({
terserOptions: {
keep_classnames: true,
keep_fnames: true,

In this example, the keep_classnames and keep_fnames options are set to true to prevent Terser from renaming classes and function names.

Please note that keeping class and function names can increase the size of your final bundle, which may affect the load time of your website.

Was this helpful?



Help @cosmic spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 4.13,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ

legal: ({
terms: of use,
privacy: policy
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
recent_tips: (
tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,

tipper: @Samric24,
tipped: article
amount: 1000 SATS,