angular-cli icon indicating copy to clipboard operation
angular-cli copied to clipboard

No way to access compilation output files

Open wszydlak opened this issue 10 months ago • 6 comments

Command

build, serve

Description

I have an esbuild plugin that is resposible to collect outputFiles after compilation (using onEnd hook with result.outputFiles).

When using application builder (esbuild) with custom plugins there is no way to access full list of outputFiles, only those emitted by main entrypoint compilation. There is no way to access additional files emited by angular builder, such as polyfills, assets, styles etc.

Previously, with using webpack plugin, i was able to get full list of outputFiles by using processAssets compilation hook.

I need to list emited files, as this is only way to get full names with filenames hash.

MY point is to build something like manifest of compilation result output files.

Describe the solution you'd like

I would like to be able to access all compilation files by esbuild plugin.

Describe alternatives you've considered

An alternative could be to access output files as an result of builder output, currently build command only returns {success: true} without information about output files.

wszydlak avatar Mar 29 '24 07:03 wszydlak

This behavior is expected. Unlike with the webpack builder, the application builder uses multiple instances of esbuild to compile various parts of your application.

To obtain the complete list of files, utilize the outputFiles option of the application builder outside of the esbuild context.

for await (const { outputFiles } of buildApplication(...)) {
}

alan-agius4 avatar Apr 01 '24 20:04 alan-agius4

This behavior is expected. Unlike with the webpack builder, the application builder uses multiple instances of esbuild to compile various parts of your application.

To obtain the complete list of files, utilize the outputFiles option of the application builder outside of the esbuild context.

for await (const { outputFiles } of buildApplication(...)) {
}

@alan-agius4 Please reopen this issue, cause as described in issue:

currently build command only returns {success: true} without information about output files.

When using buildApplication without watch mode im not able to obtain list of output files.

wszydlak avatar Apr 02 '24 06:04 wszydlak

{success: true} is returned when buildApplication is executed in write mode. I am curious, what is your use case of adding additional files?

alan-agius4 avatar Apr 02 '24 16:04 alan-agius4

How can i execute it without write mode? As i see this is only possible using buildApplicationInternal function, is it guaranteed that it always will be public?

My use case:

  1. My angular application defines list of custom elements - by using angular elements, that can be used in external application
  2. External application need to know what files it should load to make it all work (eg. load polyfills file to have zone.js, load some styles that define fonts (which has to be done outside shadow dom, etc).
  3. External application is in old technology (not using any bundler), just plain javascript files, which have mechanism to fetch main JSON file (that contains information about files generated by angular with hashes).

So to achieve this during compilation time I emmit additional file (we can call it entry.json) that is deployed together with all files generated by angular. External application fetches only entry.json and get information what additional files should it load.

Ideally would be to do this only by using esbuild plugin, so i could be able to use community builders such as @nx/angular:application that allow to pass list of esbuild plugins, but if this is not possible i need any (but secure) way to do this.

wszydlak avatar Apr 03 '24 07:04 wszydlak

@alan-agius4 any update on this?

wszydlak avatar Apr 05 '24 06:04 wszydlak

@alan-agius4 can you please reopen this issue? Problem still exists and there is no final info how to get list of compiled files properly.

wszydlak avatar Apr 10 '24 06:04 wszydlak