Skip to content

'manualChunks' gives inconsistent results for object and function #5090

@guaijie

Description

@guaijie

Feature Use Case

// using object split chunk
{
  output: {
    manualChunks: {antd: ['antd']}
  }
}
// using function split chunk
{
 output: {
    manualChunks: (id) => {
      if(id.includes('antd')) return 'antd'
    }
}

using object split chunk

image
using function split chunk

image

Why do we get inconsistent results?
Because module paths are resolved differently.
Using object for code splitting will get module paths, but Using function for code splitting will get a set of submodule paths that called 'ids'.
Using function for code splitting makes the split code unusable due to dependency issues.
So I need the 'id' to be the module path, or to provide an api to get the module path

manualChunks: (id, { resolve }) => {
  if(id === resolve('antd')) return 'antd'
}

I couldn't get the module path because I didn't know which module resolution was used(eg: esm or cjs)

Feature Proposal

// first method
manualChunks: (id, { resolve }) => {
  if(id === resolve('antd')) return 'antd'
}
// second method
manualChunks: (id) => {
 // The id is a module path, not a submodule path
  if(id.includes('antd')) return 'antd'
}

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions