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

Ability to configure/add Rollups plugins #1765

Closed
thomasoreilly opened this issue Oct 13, 2020 · 9 comments
Closed

Ability to configure/add Rollups plugins #1765

thomasoreilly opened this issue Oct 13, 2020 · 9 comments

Comments

@thomasoreilly
Copy link

Type of Issue

[ ] Bug Report
[x] Feature Request

Description

Is there anyway to add plugins to Rollup?
Looking for a way to configure/add the rollup plugin replace specifically.

Expected Behaviour

Ability to add rollup plugins or configure rollup plugins already in use.

Version Information

$ node_modules/.bin/ng-packagr --version
ng-packagr:  9.1.5
@angular/*: 9.1.0
typescript: 3.7.5
rxjs: 6.5.3
node: 12.16.1
npm/yarn: 6.13.4

Please include all version numbers that might be relevant, e.g. third-party libraries

@alan-agius4
Copy link
Member

alan-agius4 commented Oct 13, 2020

Hi @thomasoreilly,

The fact that rollup is used is an implementation detail which can be changed in the future. Also, rollup is used only to generate FESM and UMD bundles, where ESM bundles are generated using NGC directly. Therefore adding any plugins to the pipeline would result in different code in different bundles.

I am not sure why you need to replace a value in a library, but typically this indicates that the pattern used is not the recommend one. Any configurations that the library need to work should be provided via dependency injection from the application.

@thomasoreilly
Copy link
Author

Thanks for the quick response @alan-agius4.
I wasn't aware NGC generates the ESM bundles. This will but a stop to the solution I had in mind.

The reason I'm asking for this is because I wanted to be able to conditionally tree shake features from our library via an environment depending set of global toggle-able feature variables. This is something that should happen at build time for the library. We have a solution successfully implemented in our React version of the library that allows us to use Rollup replace plugin to provide the feature toggle variables at build time thus eliminating these features from the final build. I can't think of any other way to achieve this with Angular.

@alan-agius4
Copy link
Member

@thomasoreilly, I don't know the exact setup and architecture of your application and library, but if a library feature is unused in the application, it should be removed from the final bundle out-of-box when the application is built with optimization enabled.

@thomasoreilly
Copy link
Author

@alan-agius4, we don't have an application per se, however we do have application developers that use our library. The idea of being able to "turn off" features at build time for the library is so we don't ship said features.

@SchnWalter
Copy link
Contributor

What features do you want to "turn off"? Do you want some way of removing whole sub-packages or just components, directives and services?

@thomasoreilly
Copy link
Author

@SchnWalter, would be nice to "turn off" components but I believe that isn't possible. We provide a UI component library which each UI component declared within its own Angular module. Mostly these modules are independent but can depend on each other. All these modules are export form the public_api file.

We are looking to conditionally include parts of components. For example we have a table component and will want to "turn off" some functionality until we are happy it is in a shippable state.

@SchnWalter
Copy link
Contributor

Just provide one sub-package per module, this way, you only import what you need. And with the performance optimizations from #1764, you don't have any noticeable performance penalties. The sub-package overhead was "discovered" in #1758

@thomasoreilly
Copy link
Author

@SchnWalter we do follow the same approach in the linked repo from #1758 on branch sub-entries. This provides our library in a tree-shakable format. The build time hasn't been an issue for us.

I have implemented a way to have two different public_api files, one for dev and the other for prod. This solves exporting modules (UI components) that are ready for shipping.

With our React lib we can do something along the lines of.
export const x = __foo__ ? Foo : noop;
where foo is a global replaced by a boolean value using Rollup Replace plugin and Foo being our UI component.
Form my understanding there is no way to noop a class.

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

This action has been performed automatically by a bot.

@github-actions github-actions bot locked and limited conversation to collaborators Nov 13, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Development

No branches or pull requests

3 participants