Skip to content

Use "pure-module" flag from package.json to opt modules into the more aggressive build optimization process #12103

Closed

Description

@alexeagle

From @IgorMinar on August 9, 2017 23:29

build optimizer currently contains a whitelist for all packages that should be processed: https://github.com/angular/devkit/blob/a6cc86360ce9e8f32739995ee7961487345a3d45/packages/angular_devkit/build_optimizer/src/build-optimizer/build-optimizer.ts#L21-L33

This whitelist is for prefixing function calls with pure annotation for uglify.

Webpack is working on introducing pure module feature that npm packages opt-in to via "pure-module": true in package.json.

Since the meaning of this flag is the same as what we need for purification of top level function calls, we could get rid of the whitelist and use the same package.json metadata as webpack.

Since all of the modules in the whitelist will also want to benefit from the pure-modules feature in webpack, sharing the flag would allow us to get rid of the whitelist.

Copied from original issue: angular/devkit#89

Activity

  1. alexeagle commented on Sep 4, 2018

    @alexeagle
    ContributorAuthor

    From @filipesilva on August 10, 2017 8:59

    For reference: https://github.com/webpack/webpack/tree/feature/pure-module/examples/pure-module

    Doing this on the build-optimizer itself raises some problems. Build optimizer doesn't know about modules, and it actually doesn't know about file systems either. It only knows about file contents and (if given) file paths.

    And this is relevant in a webpack context because the file contents for a given file path may or may not be related to that path on disk. For instance, the file may have been through some loaders already and it's current content changed, or the given file path may not even exist at all (this happens for AOT code).

    The one that truly is aware of the pure-module flag is the system that is resolving the module - webpack in this case, maybe others in the future. So my suggestion is that we pass that information along in the build-optimizer call in the consumer:

    const boOutput = buildOptimizer({ content: input, pure: true });
    

    This way the module loader can tell build optimizer that it thinks this given module is pure, and build optimizer itself drops the whitelist and doesn't even bother checking the file path, which was a problematic way to detect these anyway.

  2. alexeagle commented on Sep 4, 2018

    @alexeagle
    ContributorAuthor

    From @IgorMinar on August 22, 2017 1:29

    If I remember correctly from looking at the pure-module branch diff,
    webpack does keep track of which modules are pure and should be able to
    pass that information along to all the plugins and loaders.

    On Thu, Aug 10, 2017 at 1:59 AM Filipe Silva notifications@github.com
    wrote:

    For reference:
    https://github.com/webpack/webpack/tree/feature/pure-module/examples/pure-module

    Doing this on the build-optimizer itself raises some problems. Build
    optimizer doesn't know about modules, and it actually doesn't know about
    file systems either. It only knows about file contents and (if given) file
    paths.

    And this is relevant in a webpack context because the file contents for a
    given file path may or may not be related to that path on disk. For
    instance, the file may have been through some loaders already and it's
    current content changed, or the given file path may not even exist at all
    (this happens for AOT code).

    The one that truly is aware of the pure-module flag is the system that is
    resolving the module - webpack in this case, maybe others in the future. So
    my suggestion is that we pass that information along in the
    build-optimizer call in the consumer:

    const boOutput = buildOptimizer({ content: input, pure: true });

    This way the module loader can tell build optimizer that it thinks this
    given module is pure, and build optimizer itself drops the whitelist and
    doesn't even bother checking the file path, which was a problematic way to
    detect these anyway.

    —
    You are receiving this because you authored the thread.
    Reply to this email directly, view it on GitHub
    angular/devkit#89 (comment), or mute
    the thread
    https://github.com/notifications/unsubscribe-auth/AANM6GFX1-l7YnWy9knSfXi1GlB4Xl_Nks5sWsZVgaJpZM4Oyw9d
    .

  3. added this to the Backlog milestone on Sep 4, 2018
  4. clydin commented on Mar 1, 2019

    @clydin
    Member

    This has been available in build optimizer since at least 6.1.0 of the CLI

  5. angular-automatic-lock-bot commented on Sep 9, 2019

    @angular-automatic-lock-bot

    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.

  6. locked and limited conversation to collaborators on Sep 9, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

featureLabel used to distinguish feature request from other issues

Type

No type

Projects

No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions