Skip to content

Angular build ignores webpackChunkName magic comments in lazy module imports #16697

@alexnoz

Description

@alexnoz

🐞 Bug report

Command (mark with an x)

  • new
  • build
  • serve
  • test
  • e2e
  • generate
  • add
  • update
  • lint
  • xi18n
  • run
  • config
  • help
  • version
  • doc

Description

Angular build ignores webpackChunkName magic comments in lazy module imports.

🔬 Minimal Reproduction

  1. Add webpack's magic comment to lazy module's import(), like this:
const routes: Routes = [{
  path: 'lazy',
  loadChildren: () =>
    import(
      /* webpackChunkName: 'some-name' */
      './some/lazy.module'
    ).then(m => m.LazyModule),
}];
  1. Run ng build --prod.

Expected result:
There's a chunk named some-name-es2015.e2d08f36b5c9ed0b9118.js in dist/app.

Actual result:
The chunk is named something like this 7-es2015.e2d08f36b5c9ed0b9118.js.

🌍 Your Environment

Angular Version:



Angular CLI: 8.3.23
Node: 10.17.0
OS: linux x64
Angular: 8.2.14
... animations, common, compiler, compiler-cli, core, forms
... language-service, platform-browser, platform-browser-dynamic
... router

Package                           Version
-----------------------------------------------------------
@angular-devkit/architect         0.803.23
@angular-devkit/build-angular     0.803.23
@angular-devkit/build-optimizer   0.803.23
@angular-devkit/build-webpack     0.803.23
@angular-devkit/core              8.3.23
@angular-devkit/schematics        8.3.23
@angular/cli                      8.3.23
@ngtools/webpack                  8.3.23
@schematics/angular               8.3.23
@schematics/update                0.803.23
rxjs                              6.4.0
typescript                        3.5.3
webpack                           4.39.2


Anything else relevant?
webpackChunkName works as expected with other dynamic imports, e.g. inside components. Other magic comments work (tried webpackPrefetch).

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions