Skip to content

Add docs on NamedChunksPlugin #2545

Open
@jakub-g

Description

@jakub-g

Feature to document

NamedChunksPlugin
webpack/webpack#4553

Author(s)

@timse

Additional information

Didn't find any info on https://webpack.js.org/plugins/ (left hand side menu)

  • What problems does it solve?
  • Is it recommended? Deprecated?

It is recommended for long term caching (webpack/webpack#1315 (comment)) but it's not documented on the webpack website what the plugin does exactly and how (there's no info about its existence even ;))

    new webpack.NamedChunksPlugin(chunk => {
      if (chunk.name) {
        return chunk.name;
      }

      // eslint-disable-next-line no-underscore-dangle
      return [...chunk._modules]
        .map(m =>
          path.relative(
            m.context,
            m.userRequest.substring(0, m.userRequest.lastIndexOf("."))
          )
        )
        .join("_");
    }),

From quick check, AFAIU the goal is to have deterministic production code generated when using code splitting, like

  __webpack_require__.e("my-async-chunk-name").then(... // will stay the same

instead of

  __webpack_require__.e(7).then(... // this might change over time if new chunks are created

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions