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

[Suggestion] Allow to set terser mangle options #136

Closed
jantimon opened this issue Jun 9, 2019 · 2 comments
Closed

[Suggestion] Allow to set terser mangle options #136

jantimon opened this issue Jun 9, 2019 · 2 comments
Labels
kind: feature New feature or request kind: optimization Performance, space, size, etc improvement

Comments

@jantimon
Copy link

jantimon commented Jun 9, 2019

Current Behaviour

Right now TSDX provides good defaults for terser / uglify-es.
Unfortunately fine tuning prop mangling is not supported right now.

Desired Behaviour

As a library author file size is important for me.
Using prop mangling on a project saved ~10% in size (after gzip).

For example given the following code:

const state = { count: 0 };
state.count ++;

Minifying it with terser/uglify-es reduces the following outputs

  1. without mangling
  2. with mangling
var s={count:0};s.count++;
var s={c:0}s.c++;

This would allows me adding more features for the same file size.

As you can probably guess this will only work for internal library code as mangling public option names would not be a good idea:
E.g. Mangling if(options.verbose){..} to if(o.verbose){..} will still work however if(o.x){..} won't.

Therefore terser/uglify-es allows to limit propMangling using a regular expression.
So as a library author I can tell terser to mangle only props starting with a _:

const state = { _count: 0 };
if (options.verbose) { console.log(state._count) }

with a regular expression /^_/ would produce the following:

var s={c:0};if(o.verbose){console.log(s.c)}

Try it out yourself: runkit live demo

Suggested Solution

Allow to set a regex for props mangling - if none is given don't mangle props at all.

Who does this impact? Who is this for?

This helps library authors to provide smaller libraries.

Describe alternatives you've considered

For example codekit uses a prop whitelist instead of a regular expression: https://codekitapp.com/help/terser/

Additional context

runkit live demo
terser docs

@swyxio
Copy link
Collaborator

swyxio commented Jun 9, 2019

great writeup. we'll probably enable this through a general "extend your own rollup config" option #110

@agilgur5
Copy link
Collaborator

agilgur5 commented Mar 9, 2020

This should be possible now by extending the Rollup config in tsdx.config.js that was added in #183 .

If that is too difficult or if this is a more common request we can think about more easily configuring it. I believe microbundle has a flag for this, but we want to avoid flag sprawl if possible through other means (and IMO config is better than flags generally)

@agilgur5 agilgur5 closed this as completed Mar 9, 2020
@agilgur5 agilgur5 added kind: feature New feature or request kind: optimization Performance, space, size, etc improvement labels Mar 9, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind: feature New feature or request kind: optimization Performance, space, size, etc improvement
Projects
None yet
Development

No branches or pull requests

3 participants