babel / babel/minify

Support mangled names cache preserved between runs

Open
#969 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
JavaScript
Stars
4.4k
Forks
217
PR merge metrics
No merged PRs in 30d

Description

**Is your feature request related to a problem? Please describe.**
Sometimes you may have to build multiple output files with multiples runs. For example, it may be the case for browser extensions where you may have to build a content-script, a background-script, and a popup separately. Those scripts may reuse common objects and services but in case you have communication between them (what is very likely in case of complex browser extensions) there is one big issue in terms of a minification - object, compiled and minified separately may have different properties after the minification for different compilations. When a content-script sends a message (an event) to a background script it may send an object A with property `x` (minified, let's say it's `eventType` property before the minification) while the background script is expecting the same object A but it's `eventType` property is minified to `y`. In this case when the background-script retrieves such event with object A then the property `y` is undefined for it.

**Describe the solution you'd like**
The [terser|npm](https://www.npmjs.com/package/terser) package has `--name-cache` property which can be set to an object or a file. It's allowed (for example in a gulp file) to specify an object or a file that will be used as a name-cache. This name-cache object may be reused between multiple compilation/minification steps solving the issue described above. Is it possible to add something similar to babel/minify?

**Describe alternatives you've considered**
To solve this issue, one may use string constants for setting/accessing properties in the communication between let's say a content-script and a background-script **OR** exclude some properties from the minification using **exclude** configuration option. But both methods do not allow us to use minification fully for its advancement.

**Additional context**
none

Contributor guide

Open the contributing guide

Research direction

Start by locating the babel/minify entry points that perform name mangling and the configuration path for minification options. Compare the requested reusable object-or-file cache with the existing configuration, then identify how separate compilation runs could share it. Done means repeated runs preserve compatible mangled property names without requiring string constants or exclusions.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript
Domain
tooling
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.