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

Descriptive naming convention for chunks

Open kblestarge opened this issue 9 years ago • 16 comments

Bug Report or Feature Request (mark with an x)

- [ ] bug report -> please search issues before submitting
- [x] feature request

Desired functionality.

Currently, when I build out my project with ng build or ng build --prod, I see something like this:

screen shot 2017-06-15 at 12 17 57 pm

It tells me how large my chunks and bundles are which is helpful. I can then turn this information into a useful visual to get a better understanding of what exactly is in each bundle or chunk using the source-map-explorer or the webpack-bundle-analyzer. However, it's kind of difficult to tell which chunk is coming from which lazy-loaded module.

I think it would be wise to include the name of the module in the file name somehow. for example: instead of 0.9c59d5dde120b62746c2.chunk.js it would be AdminModule.0.9c59d5dde120b62746c2.chunk.js

This feature would be helpful when trying to understand the module architecture of your application.

kblestarge avatar Jun 15 '17 18:06 kblestarge

This is a MUCH needed feature in my opinion.

mjbradford89 avatar Jun 21 '17 23:06 mjbradford89

I don't know of a way off the top of my head but webpack 2.4 (https://github.com/webpack/webpack/releases/tag/v2.4.0) has some new features regarding naming modules and perhaps that can be used.

filipesilva avatar Jun 26 '17 07:06 filipesilva

At least syntax-wise for the router paths, angular-router-loader seems to have a nice approach:

https://github.com/brandonroberts/angular-router-loader/blob/master/docs/options.md#lazy-loading-options

(easily allowing for file names and paths)

PEsteves8 avatar Jun 26 '17 08:06 PEsteves8

(Unless there's a commitment to avoid mixing cli specific features with angular syntax)

PEsteves8 avatar Jun 26 '17 10:06 PEsteves8

There is now also a standalone Webpack plugin that can be used in non-Angular CLI projects with a custom Webpack config: https://github.com/Independer/angular-named-lazy-chunks-webpack-plugin

I also created an issue to either to use that package in @angular/cli or pull the plugin into one of the @angular-devkit packages.

pglazkov avatar Oct 25 '17 12:10 pglazkov

How it's done for lazy modules? Im still getting 1,2,3

trsh avatar Apr 10 '18 12:04 trsh

Use the --named-chunks flag during build. ng build --named-chunks

On Tue, Apr 10, 2018, 8:51 AM trsh [email protected] wrote:

How it's done for lazy modules? Im still getting 1,2,3

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/angular/angular-cli/issues/6700#issuecomment-380086776, or mute the thread https://github.com/notifications/unsubscribe-auth/AAdmV2tXjWVVeqKFXVkPekRr6v437-Pxks5tnKrUgaJpZM4N7lA9 .

tavelli avatar Apr 10 '18 13:04 tavelli

@tavelli tnx

trsh avatar Apr 10 '18 13:04 trsh

From the "you can't please everyone" department...now that the CLI (apparently?) does this by default (includes the module name in the chunk filename), I need the exact opposite - I want my filenames to be just generic guids, or something equally inscrutable. Without ejecting webpack, is there any way to go about this?

Thanks.

ghost avatar May 08 '18 13:05 ghost

The named chunks option is what you’re looking for to handle that situation. It is disabled by default in a new project for production builds, so no action is typically required.

clydin avatar May 12 '18 20:05 clydin

I'm using a new CLI project, but still in a dev build. Getting names like "myModule.chunk.js". I'd rather have something like "12345.chunk.js" where "12345" is a random number or guid or such.

If I enable the named chunks option, can I specify my own names or have it generate random names. If randomly generated names is out, I could settle for me just assigning fixed meaningless names. If so, how do I enable named chunks?

Thx.

PS: Just realized I replied here using my work GH account...I'm still "manndave" :-(

mann-david avatar May 14 '18 15:05 mann-david

If you are see names such as myModule.chunk.js then the option is enabled (it defaults to enabled). If you are seeing numbers (e.g., 0.chunk.js) then the option is disabled (default for production configuration in new projects).

clydin avatar May 14 '18 15:05 clydin

Perfect!

Thanks, that is exactly what I need. I guess you can please everyone... :-)

mann-david avatar May 14 '18 15:05 mann-david

Continue what @mann-david said,

If I enable the named chunks option, can I specify my own names or have it generate random names

Is it possible to add a custom name to the chunks? Currently if I use the option lazyModules in angular.json it adds all the path to the module:

chunks

It should be a little practical in this case set only the short name (e.g. Module Name).

futbolsalas15 avatar Apr 18 '19 18:04 futbolsalas15

Ok, I see. The problem with setting a custom name is in the following lines

https://github.com/angular/angular-cli/blob/32a096f3f084fd58719d9009be4ff1d6666b6565/packages/angular_devkit/build_angular/src/angular-cli-files/models/webpack-configs/typescript.ts#L72-L78

The paths setted in lazyModule are also used as names of the lazy module. Should we add a new feature that the lazyModule could be an array object instead of a string array, or detect both cases (for back compatibility)? e.g.:

{
...
"lazyModule": [
{"name": "rich-text-editor", "path": "src/.../.../rich-text-editor.module.ts"}
]
...
}

futbolsalas15 avatar Apr 18 '19 19:04 futbolsalas15

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.