nx icon indicating copy to clipboard operation
nx copied to clipboard

Generate index.html while using custom webpack config

Open huv1k opened this issue 3 years ago โ€ข 2 comments

Description

Currently, when using @nrwl/web:webpack with a custom config, there is no way how to generate a custom index.html, because there are two webpack configs. One is for es5 and second is for esm when using HtmlWebpackPlugin we are emitting these index.html for each config and it's really difficult to put their es5 and esm outputs from both processes ton single index.html Right now these two outputs are merged and then generate index.html if there is generateIndexHtml: true https://github.com/nrwl/nx/blob/0c614b2d6bf230b862423b0514edee636e3ea07a/packages/web/src/executors/webpack/webpack.impl.ts#L236-L249

There should be an option to provide a custom function that is going to work similarly to a custom webpack config. This would enable us to modify index.html depending on our use case.

Motivation

Currently, it's really difficult to get working CSP with both es5 and esm emitted assets inside index.html. This should simplify the process around it and provide the possibility to modify index.html for example minify output etc. There is a lot of use cases that could be useful with this solution.

Suggested Implementation

Provide a new option customHtml for @nrwl/web:webpack, that is going to work similar as webpackConfig. This function would be called instead of writeIndexHtml with same options. This would bring full control to users, who could implement their own function for generating HTML with all emited files etc.

Alternate Implementations

Another possible solution could create a postprocessor for already generated HTML, we could parse this and for example, inject CSP depending on already emitted HTML.

huv1k avatar May 17 '22 13:05 huv1k

Any update on this feature?

tealang7012 avatar Aug 23 '22 05:08 tealang7012

I'd also be willing to collaborate with this feature. If anyone is working on it already, please reach out. My thoughts are that we could alter the index option of this executor so that it takes < IndexLoader | string> with the interface of IndexLoader looking something like this:

interface IndexLoader {
  template: (path to template | template string)
  loader: (any webpack loader)
}

LongLiveCHIEF avatar Sep 21 '22 12:09 LongLiveCHIEF

This issue has been automatically marked as stale because it hasn't had any recent activity. It will be closed in 14 days if no further activity occurs. If we missed this issue please reply to keep it active. Thanks for being a part of the Nx community! ๐Ÿ™

github-actions[bot] avatar May 30 '23 00:05 github-actions[bot]

Can we reopen this issue? ๐Ÿ™ Still a problem ๐Ÿ™ˆ

huv1k avatar Jun 13 '23 04:06 huv1k

I think you'd have to create a new issue at this point.

LongLiveCHIEF avatar Jun 13 '23 12:06 LongLiveCHIEF

This issue has been closed for more than 30 days. If this issue is still occuring, please open a new issue with more recent context.

github-actions[bot] avatar Jul 14 '23 00:07 github-actions[bot]