Skip to content

@ngtools/webpack - Limited number of AotPlugin instances #5072

Description

@dbettini

Hello there. I might be wrong, but it seems that, at the moment, @ngtools/webpack doesn' support multiple entry points. The way it was possible to have multiple Angular client apps built by the same webpack instance was, e.g. using awesome-webpack-loader, something like this:

const tsClientNames = ["studio", "learn"];
tsClientNames.forEach(name => webpackConfig.module.rules.push({
    test: /\.tsx?$/,
    include: path.join(require.resolve(`${name}-client`), ".."),
    use: [
        {
            loader: "awesome-typescript-loader",
            options: {
                configFileName: path.join(require.resolve(`${name}-client`), "../tsconfig.json")
            }
        },
        "angular-router-loader",
        "angular2-template-loader"
    ]
}));

As you can see, this config enables it to build two different angular apps (that are package dependencies of the main one that runs webpack), each containing its own tsconfig, typings etc., by scoping each loader instance using 'include' to its own directory.
However, @ngtools/webpack provides the AOT functionality through the AotPlugin, which throws the An @ngtools/webpack plugin already exist for this compilation. exception if you try creating more than one instance.

So my question is, why is the number of AotPlugin instances restricted? Is there another way to support multiple entry points? If not, are there to plans to support it, or an issue where it can be tracked (since all issues concerning the webpack loader are in the angular-cli repository, which makes it really hard to track)?

Activity

  1. ytkj commented on Apr 13, 2017

    @ytkj

    In my opinion, webpack's multi-entries is essential feature; In typical large-scale enterprise system, Application must be devided into multiple SPA to supress memory usage in web-browser.

    ( Another solution, using single-SPA with lazy loading, is effective only in first-time loading, but in total memory usage.)

    But this issue is labeled 'nice to have', not 'required'.
    Is there alternative way to AOT-compile multiple SPA with webpack ?

    ( Using ngc cli directly before webpacking ? But we no longer use @ngtools/webpack in that case...)

    Any idea ?

  2. tavelli commented on May 31, 2017

    @tavelli

    @ytkj @filipesilva yea i agree. we went ahead with an adoption of ng2+ at our company with assumption this bug would be resolved by the time we got close to moving to production, now i'm getting a bit nervous! Are there any hacks or workarounds we can use until official support lands?

  3. ytkj commented on Jun 5, 2017

    @ytkj

    @tavelli workaround I can come up with is quite primitive:

    1. run ngc command as many times as the number of spa.
    2. Then webpacking to the generated *.ngFactory intermediate codes.

    To automate build process, step 1 should be done by a task-runner such as npm-script or Gulp.

  4. nathanmarks commented on Jul 5, 2017

    @nathanmarks

    @tavelli have you found a hack or workaround?

  5. tavelli commented on Jul 6, 2017

    @tavelli
  6. snewell92 commented on Sep 1, 2017

    @snewell92

    For a while I did this:

    package.json snippet

        ...
        "prebuild:client-aot": "ngc -p public/src/prep-tsconfig.aot.json",
        "build:client-aot": "ngc -p public/src/tsconfig.aot.json && rollup -c rollup-config.js",
        ...
    

    My prep-tsconfig.aot.json points to a prepare-ngc.main.ts, which imports all my main modules, just so the compiler can generate the right files, while my tsconfig.aot.json matches all my main page files with a regex in the include option of the tsconfig (pattern is "*-aot.ts").

    In this way Webpack can be used in development with JIT, while pure ngc+rollup can be used for AOT building. Not the most ideal imo, since I'd rather just use one tool (webpack) and not have to jump into ngc directly - but it is a valid approach.

    I'm investigating migrating to webpack, but perhaps I'll still need to do this if I have multiple entry point :
    Are y'all getting this by using the angular cli? Or using webpack directly akin to what this guy is doing?

  7. ytkj commented on Dec 8, 2017

    @ytkj

    related to #7954

  8. removed their assignment
    on Feb 6, 2018
  9. 5 remaining items

  10. added 7 commits that reference this issue on Apr 6, 2021
    8596287
    f6bd692
    3cc8436
    370fe65
    c987628
    9346eb4
    389f597
  11. linked a pull request that will close this issueUpgrade tooling to use Webpack 5 #20466on Apr 8, 2021
  12. added 2 commits that reference this issue on Apr 8, 2021
    a501a62
    5826419
  13. added a commit that references this issue on Apr 8, 2021
    46e9d0e
  14. angular-automatic-lock-bot commented on May 9, 2021

    @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.

  15. locked and limited conversation to collaborators on May 9, 2021
  16. added a commit that references this issue on Mar 26, 2024
    b79a677
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

    area: @ngtools/webpackfeatureLabel 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