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

fix(bazel): disable treeshaking when generating FESM and UMD bundles #32069

Closed
wants to merge 2 commits into from
Closed

fix(bazel): disable treeshaking when generating FESM and UMD bundles #32069

wants to merge 2 commits into from

Commits on Aug 9, 2019

  1. fix(bazel): disable treeshaking when generating FESM and UMD bundles

    There has been a regression where enabling rollup treeshaking causes errors during runtime because it will drop const access which will always evaluate to true or false. However, such `const` in `@angular/core` cannot be dropped because their value is changed when NGCC is run on `@angular/core`
    
    VE
    ```
    const SWITCH_IVY_ENABLED__POST_R3__ = true;
    const SWITCH_IVY_ENABLED__PRE_R3__ = false;
    const ivyEnabled = SWITCH_IVY_ENABLED__PRE_R3__;
    ```
    
    Ivy (After NGCC)
    ```
    const SWITCH_IVY_ENABLED__POST_R3__ = true;
    const SWITCH_IVY_ENABLED__PRE_R3__ = false;
    const ivyEnabled = SWITCH_IVY_ENABLED__POST_R3__;
    ```
    
    FESM2015
    ```
    load(path) {
    	/** @type {?} */
    	const legacyOfflineMode = this._compiler instanceof Compiler;
    	return legacyOfflineMode ? this.loadFactory(path) : this.loadAndCompile(path);
    }
    ```
    
    ESM2015
    ```
     load(path) {
    	/** @type {?} */
    	const legacyOfflineMode = !ivyEnabled && this._compiler instanceof Compiler;
    	return legacyOfflineMode ? this.loadFactory(path) : this.loadAndCompile(path);
    }
    ```
    
    From the above we can see that `ivyEnabled ` is being treeshaken away when generating the FESM bundle which is causing runtime errors such as `Cannot find module './lazy/lazy.module.ngfactory'` since in Ivy we will always load the factories.
    alan-agius4 committed Aug 9, 2019
    Copy the full SHA
    78205a6 View commit details
    Browse the repository at this point in the history
  2. Copy the full SHA
    12ace10 View commit details
    Browse the repository at this point in the history