Skip to content

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

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

Closed
dbettini opened this issue Feb 27, 2017 · 9 comments · Fixed by #20466
Closed

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

dbettini opened this issue Feb 27, 2017 · 9 comments · Fixed by #20466
Labels
area: @ngtools/webpack feature Issue that requests a new feature
Milestone

Comments

@dbettini
Copy link

dbettini commented Feb 27, 2017

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)?

@filipesilva filipesilva added package4: @angular-sdk/webpack P5 The team acknowledges the request but does not plan to address it, it remains open for discussion labels Mar 14, 2017
@ytkj
Copy link

ytkj commented Apr 13, 2017

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 ?

@tavelli
Copy link

tavelli commented May 31, 2017

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

@ytkj
Copy link

ytkj commented Jun 5, 2017

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

@nathanmarks
Copy link

@tavelli have you found a hack or workaround?

@tavelli
Copy link

tavelli commented Jul 6, 2017 via email

@snewell92
Copy link

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?

@ytkj
Copy link

ytkj commented Dec 8, 2017

related to #7954

@hansl hansl added feature Issue that requests a new feature and removed package4: @angular-sdk/webpack labels Jan 24, 2018
@hansl hansl removed their assignment Feb 6, 2018
@artonge
Copy link

artonge commented May 15, 2018

While this get fixed, I published a npm package with some modifications to handle multiple entry modules: @artonge/webpack feel free to use it.
You only have to replace @ngtools/webpack by @artonge/webpack in your webpack config and change entryModule: "your module" by entryModules: ["your module A", "your module B"]

@filipesilva filipesilva added area: @ngtools/webpack and removed P5 The team acknowledges the request but does not plan to address it, it remains open for discussion labels Oct 1, 2019
@ngbot ngbot bot modified the milestone: Backlog Oct 1, 2019
clydin added a commit to clydin/angular-cli that referenced this issue Apr 6, 2021
…tion

This change allows multiple instances of the `AngularWebpackPlugin` to be present in a Webpack configuration.
Each plugin instance should reference a different TypeScript configuration file (`tsconfig.json`) and the TypeScript configuration files should be setup to not include source files present in the other TypeScript configuration files. If files are included in more than one TypeScript configuration, the first plugin present in the Webpack configuration that can emit the file will be used.

Closes: angular#5072
clydin added a commit to clydin/angular-cli that referenced this issue Apr 6, 2021
…tion

This change allows multiple instances of the `AngularWebpackPlugin` to be present in a Webpack configuration.
Each plugin instance should reference a different TypeScript configuration file (`tsconfig.json`) and the TypeScript configuration files should be setup to not include source files present in the other TypeScript configuration files. If files are included in more than one TypeScript configuration, the first plugin present in the Webpack configuration that can emit the file will be used.

Closes: angular#5072
clydin added a commit to clydin/angular-cli that referenced this issue Apr 7, 2021
…tion

This change allows multiple instances of the `AngularWebpackPlugin` to be present in a Webpack configuration.
Each plugin instance should reference a different TypeScript configuration file (`tsconfig.json`) and the TypeScript configuration files should be setup to not include source files present in the other TypeScript configuration files. If files are included in more than one TypeScript configuration, the first plugin present in the Webpack configuration that can emit the file will be used.

Closes: angular#5072
clydin added a commit to clydin/angular-cli that referenced this issue Apr 7, 2021
…tion

This change allows multiple instances of the `AngularWebpackPlugin` to be present in a Webpack configuration.
Each plugin instance should reference a different TypeScript configuration file (`tsconfig.json`) and the TypeScript configuration files should be setup to not include source files present in the other TypeScript configuration files. If files are included in more than one TypeScript configuration, the first plugin present in the Webpack configuration that can emit the file will be used.

Closes: angular#5072
clydin added a commit to clydin/angular-cli that referenced this issue Apr 7, 2021
…tion

This change allows multiple instances of the `AngularWebpackPlugin` to be present in a Webpack configuration.
Each plugin instance should reference a different TypeScript configuration file (`tsconfig.json`) and the TypeScript configuration files should be setup to not include source files present in the other TypeScript configuration files. If files are included in more than one TypeScript configuration, the first plugin present in the Webpack configuration that can emit the file will be used.

Closes: angular#5072
clydin added a commit to clydin/angular-cli that referenced this issue Apr 7, 2021
…tion

This change allows multiple instances of the `AngularWebpackPlugin` to be present in a Webpack configuration.
Each plugin instance should reference a different TypeScript configuration file (`tsconfig.json`) and the TypeScript configuration files should be setup to not include source files present in the other TypeScript configuration files. If files are included in more than one TypeScript configuration, the first plugin present in the Webpack configuration that can emit the file will be used.

Closes: angular#5072
clydin added a commit to clydin/angular-cli that referenced this issue Apr 8, 2021
…tion

This change allows multiple instances of the `AngularWebpackPlugin` to be present in a Webpack configuration.
Each plugin instance should reference a different TypeScript configuration file (`tsconfig.json`) and the TypeScript configuration files should be setup to not include source files present in the other TypeScript configuration files. If files are included in more than one TypeScript configuration, the first plugin present in the Webpack configuration that can emit the file will be used.

Closes: angular#5072
@alan-agius4 alan-agius4 linked a pull request Apr 8, 2021 that will close this issue
clydin added a commit to clydin/angular-cli that referenced this issue Apr 8, 2021
…tion

This change allows multiple instances of the `AngularWebpackPlugin` to be present in a Webpack configuration.
Each plugin instance should reference a different TypeScript configuration file (`tsconfig.json`) and the TypeScript configuration files should be setup to not include source files present in the other TypeScript configuration files. If files are included in more than one TypeScript configuration, the first plugin present in the Webpack configuration that can emit the file will be used.

Closes: angular#5072
clydin added a commit to clydin/angular-cli that referenced this issue Apr 8, 2021
…tion

This change allows multiple instances of the `AngularWebpackPlugin` to be present in a Webpack configuration.
Each plugin instance should reference a different TypeScript configuration file (`tsconfig.json`) and the TypeScript configuration files should be setup to not include source files present in the other TypeScript configuration files. If files are included in more than one TypeScript configuration, the first plugin present in the Webpack configuration that can emit the file will be used.

Closes: angular#5072
clydin added a commit that referenced this issue Apr 8, 2021
…tion

This change allows multiple instances of the `AngularWebpackPlugin` to be present in a Webpack configuration.
Each plugin instance should reference a different TypeScript configuration file (`tsconfig.json`) and the TypeScript configuration files should be setup to not include source files present in the other TypeScript configuration files. If files are included in more than one TypeScript configuration, the first plugin present in the Webpack configuration that can emit the file will be used.

Closes: #5072
@angular-automatic-lock-bot
Copy link

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.

@angular-automatic-lock-bot angular-automatic-lock-bot bot locked and limited conversation to collaborators May 9, 2021
ikjelle pushed a commit to ikjelle/angular-cli that referenced this issue Mar 26, 2024
…tion

This change allows multiple instances of the `AngularWebpackPlugin` to be present in a Webpack configuration.
Each plugin instance should reference a different TypeScript configuration file (`tsconfig.json`) and the TypeScript configuration files should be setup to not include source files present in the other TypeScript configuration files. If files are included in more than one TypeScript configuration, the first plugin present in the Webpack configuration that can emit the file will be used.

Closes: angular#5072
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area: @ngtools/webpack feature Issue that requests a new feature
Projects
None yet
Development

Successfully merging a pull request may close this issue.

9 participants