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

Provide an ability to perform tree-shaking but retain symbol names #22354

Closed
1 task done
AndrewKushnir opened this issue Dec 11, 2021 · 4 comments · Fixed by #22379
Closed
1 task done

Provide an ability to perform tree-shaking but retain symbol names #22354

AndrewKushnir opened this issue Dec 11, 2021 · 4 comments · Fixed by #22379
Assignees
Labels
Milestone

Comments

@AndrewKushnir
Copy link

🚀 Feature request

Command (mark with an x)

  • build

Description

Currently it's not possible to use ng build to perform dead code elimination via Terser, but retain symbol names in generated JS bundle. It'd be useful to have this capability to simplify bundle size-related investigations (which often times involves looking for retained symbols).

// cc @alan-agius4

@alan-agius4
Copy link
Collaborator

What myself and @AndrewKushnir observed was that using NG_BUILD_MANGLE=0 caused a lot of dead code such as DebugNode to be retained.

ng config cli.cache.enabled false
NG_BUILD_MANGLE=0 ng build

@johncrim
Copy link

johncrim commented Dec 14, 2021

I use this to test non-mangled production output:

cross-env NG_BUILD_DEBUG_OPTIMIZE=minify,beautify ng build --configuration production --output-hashing none

As I recall I arrived at that by reviewing the code that handles the different flags.

Does that suffer from the same problem?

@alan-agius4
Copy link
Collaborator

@johncrim, yeah since in that case mangled is disabled. At least in v13, you can verify this by looking for DebugNode, if it’s found DCE didn’t fully work.

@alan-agius4 alan-agius4 self-assigned this Dec 15, 2021
alan-agius4 added a commit that referenced this issue Dec 17, 2021
…etain symbol names

Previously, we enabled the `keepNames` esbuild when mangling was disabled, this caused dead code to be retained because of the transformations that esbuild did to the input.

Input
```js
class foo {}
```

Output
```js
var l = Object.defineProperty,
  a = (s, c) => l(s, "name", { value: c, configurable: !0 });
class foo {}
a(foo, "foo");
```

Previously we enabled the `keepNames` esbuild option when mangling was disabled, which is actually not needed to retain the name of symbols but is needed for SSR because Domino relies on the `name` property on functions and classes.

Closes #22354
alan-agius4 added a commit that referenced this issue Dec 17, 2021
…etain symbol names

Previously, we enabled the `keepNames` esbuild when mangling was disabled, this caused dead code to be retained because of the transformations that esbuild did to the input.

Input
```js
class foo {}
```

Output
```js
var l = Object.defineProperty,
  a = (s, c) => l(s, "name", { value: c, configurable: !0 });
class foo {}
a(foo, "foo");
```

Previously we enabled the `keepNames` esbuild option when mangling was disabled, which is actually not needed to retain the name of symbols but is needed for SSR because Domino relies on the `name` property on functions and classes.

Closes #22354

(cherry picked from commit 2c9a33d)
@angular-automatic-lock-bot
Copy link

This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

This action has been performed automatically by a bot.

@angular-automatic-lock-bot angular-automatic-lock-bot bot locked and limited conversation to collaborators Jan 17, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants