Skip to content
This repository has been archived by the owner on Apr 9, 2022. It is now read-only.

Build optimizer breaks third party libraries #612

Closed
yGuy opened this issue Apr 3, 2018 · 2 comments
Closed

Build optimizer breaks third party libraries #612

yGuy opened this issue Apr 3, 2018 · 2 comments

Comments

@yGuy
Copy link

yGuy commented Apr 3, 2018

Bug Report or Feature Request (mark with an x)

- [x] bug report -> please search issues before submitting
- [ ] feature request

Area

- [x] devkit
- [ ] schematics

Versions

all

Repro steps

  • Scaffold a project that uses code (e.g. a third party library) that contains code that cannot be properly "optimized" using uglifyjs. E.g. code that uses "non-pure getters" like this:
let object = {};
Object.defineProperty(object,"nonSideEffectFreeGetterBasedMember", 
    {get: function(){ console.log("side effect")}});

(function () {
  object.nonSideEffectFreeGetterBasedMember;
}());
  • Enable the angular build optimizer
  • Run the program with the build optimizer enabled and observe that the code does not work as expected anymore, because the non-pure getter has been removed and the side-effect does not happen anymore.

The log given by the failure

n/a

Desired functionality

It should be possible to either configure the build optimizer and disable possibly logic-breaking optimizations altogether or at least on a per dependency basis. Especially if the third party library is already optimized/minified/preprocessed the danger of breaking things is higher than the benefits of possibly saving a few more bytes.

Mention any other details that might be useful

Right now it is an either/or - either the code runs and you can rely on it, or it may be "optimized" but broken in some cases.

The tool-chain makes it easy to include all kind of packages from third parties via npm, etc. The "build-optimizer" cannot dictate how the code of all of these packages needs to be written in order to work with the "optimization" step. It's OK to forbid non-pure getters in the angular code base, but not in any third party code. Either add an option to only apply safe code transformations for third party code or make this an opt-in. The binary API right now is not sufficient.

@seanbright
Copy link

I'm experiencing this as well with https://github.com/onsip/SIP.js as a dependency. Building with Angular CLI without the --prod flag my application works, with the --prod flag it doesn't. No errors are emitted, so it seems that something is just getting silently optimized away.

@alexeagle
Copy link
Contributor

This issue was moved to angular/angular-cli#12128

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants