Skip to content
This repository was archived by the owner on Apr 4, 2025. It is now read-only.
This repository was archived by the owner on Apr 4, 2025. It is now read-only.

build-optimizer hardcodes private "esm5" paths to enable optimizations #523

Closed

Description

@IgorMinar

Bug Report or Feature Request (mark with an x)

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

Area

- [x] devkit

Versions

Angular CLI: 1.6.6
Node: 8.9.4
OS: darwin x64
Angular: 6.0.0-beta.7-ac402a5a85
... animations, common, compiler, compiler-cli, core, forms
... http, language-service, platform-browser
... platform-browser-dynamic, router

@angular/cli: 1.6.6 (but the problematic code is still present in master)
@angular-devkit/build-optimizer: 0.0.42
@angular-devkit/core: 0.0.29
@angular-devkit/schematics: 0.0.52
@ngtools/json-schema: 1.1.0
@ngtools/webpack: 1.9.6
@schematics/angular: 0.1.17
typescript: 2.7.2

Repro steps

the following line hardcodes "esm5" path - which is an implementation detail and not part of the public api:

/[\\/]node_modules[\\/]@angular[\\/][^\\/]+[\\/]esm5[\\/]/,

this line then uses the path above to test if build-optimizer optimizations should be enabled:

&& es5AngularModules.some((re) => re.test(filePath))

Desired functionality

it's not clear to me why we hardcode these paths. ideally we should follow the "module" property to see where the code is in the package, or even better we should check the new "sideEffects" property introduced by webpack v4.

It seems that we are intentionally excluding the es2015 distribution from these optimizations. I'm not sure why, but regardless of the reason, relying on paths is not the right way to go about this - we should be consulting the package.json and using the same resolution algorithm (or the reversed version of it) to understand what kind of file we are dealing with.

Mention any other details that might be useful

Activity

  1. filipesilva commented on Mar 18, 2018

    @filipesilva
    Contributor

    @IgorMinar the reason those paths are hardcoded is because Build Optimizer itself does not know about entry points as described in package.json. It only knows about file paths.

    When used with Webpack, that information could be passed along. But Build Optimizer can be used outside of Webpack as well. Doing resolution for each file passed can be costly so that determination is left to the tooling.

    I think the right approach to move out of the hardcoded paths is to make use of the isSideEffectFree flag on the consuming tooling: https://github.com/angular/devkit/blob/master/packages/angular_devkit/build_optimizer/src/build-optimizer/build-optimizer.ts#L70

    This is what we used for the Bazel integration via Rollup. The webpack loader hasn't yet been revisited to use this as well.

    The es2015 are excluded intentionally because Build Optimizer doesn't support es2015 code, with some of the optimizations breaking it.

  2. IgorMinar commented on Mar 18, 2018

    @IgorMinar
    ContributorAuthor

    aha! great insights. thanks! I agree that we should just switch over to detection based on the sideEffects package.json flag.

  3. clydin commented on Mar 19, 2018

    @clydin
    Member

    PR #531 allows the build optimizer to leverage the webpack side effect detection.

  4. clydin commented on Mar 19, 2018

    @clydin
    Member

    Also of note: The CLI v6 webpack 4 configuration marks previous versions of Angular as side effect free in addition to any packages with the sideEffects flag.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions