khernik
khernik

Reputation: 2091

Multiple webpack entries and chunkFilename

How can I use a [name] placeholder inside of the chunkFilename key in the webpack configuration?

I am using mutliple entries like this:

entry: {
  path1: "file1.js",
  path2: "file2.js"
},
output: {
  path: "/dist/bundle",
  publicPath: "/dist/",
  filename: "[name].js",
  chunkFilename: "[name]/[id].[chunkhash].chunk.js"
}

I would expect the chunkFilename to appear under path1/id.chunkhash.chunk.js and also under path2/id.chunkhash.chunk.js (because the name will be the key from entry object). What it does however is it replaces both name and id with 0.

How can I solve this?

Upvotes: 0

Views: 2824

Answers (1)

PlayMa256
PlayMa256

Reputation: 6831

Webpack async chunks by default have no name, unless you add webpackChunkName to the import, i.e: import(/*webpackChunkName: "test123"*/ './test.js').

If you don't manually do this, the default "name" for each async chunk is the id, which is the same as [id]. That is why it is happening.

Upvotes: 3

Related Questions