Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

splitChunks.cacheGroups.{cacheGroup}.name does not accept a function #3425

Closed
oqx opened this issue Jun 5, 2023 · 2 comments
Closed

splitChunks.cacheGroups.{cacheGroup}.name does not accept a function #3425

oqx opened this issue Jun 5, 2023 · 2 comments
Labels
bug Something isn't working duplicated The issue/PR is duplicate of others pending triage The issue/PR is currently untouched.

Comments

@oqx
Copy link

oqx commented Jun 5, 2023

System Info

System:
OS: macOS 13.3.1
CPU: (16) x64 Intel(R) Core(TM) i9-9980HK CPU @ 2.40GHz
Memory: 6.85 GB / 32.00 GB
Shell: 5.9 - /bin/zsh
Binaries:
Node: 19.6.0 - /usr/local/bin/node
Yarn: 1.22.19 - /usr/local/bin/yarn
npm: 9.6.2 - /usr/local/bin/npm
Browsers:
Brave Browser: 112.1.50.114
Chrome: 113.0.5672.126
Firefox: 109.0.1
Safari: 16.4
Safari Technology Preview: 16.4
npmPackages:
@rspack/cli: ^0.2.0 => 0.2.0

Details

The docs indicate that the name property within a chunkGroups object accepts a function, but rspack throws an error, and the types indicate that a function is not an acceptable value. This is also the case with splitChunks.name.

Error:

Error: Failed to convert JavaScript value `function name(..) ` into rust type `String`
    at Compiler._Compiler_instance_get (/Users/jaykariesch/projects/rspack/react/node_modules/.pnpm/@rspack+core@0.2.0_webpack-dev-server@4.13.1_webpack@5.76.0/node_modules/@rspack/core/src/compiler.ts:280:4)
    at __classPrivateFieldGet (/Users/jaykariesch/projects/rspack/react/node_modules/.pnpm/@rspack+core@0.2.0_webpack-dev-server@4.13.1_webpack@5.76.0/node_modules/@rspack/core/dist/compiler.js:34:48)
    at Compiler.build (/Users/jaykariesch/projects/rspack/react/node_modules/.pnpm/@rspack+core@0.2.0_webpack-dev-server@4.13.1_webpack@5.76.0/node_modules/@rspack/core/src/compiler.ts:815:24)
    at /Users/jaykariesch/projects/rspack/react/node_modules/.pnpm/@rspack+core@0.2.0_webpack-dev-server@4.13.1_webpack@5.76.0/node_modules/@rspack/core/src/compiler.ts:784:11
    at Hook.eval [as callAsync] (eval at create (/Users/jaykariesch/projects/rspack/react/node_modules/.pnpm/tapable@2.2.1/node_modules/tapable/lib/HookCodeFactory.js:33:10), <anonymous>:6:1)
    at Hook.CALL_ASYNC_DELEGATE [as _callAsync] (/Users/jaykariesch/projects/rspack/react/node_modules/.pnpm/tapable@2.2.1/node_modules/tapable/lib/Hook.js:18:14)
    at /Users/jaykariesch/projects/rspack/react/node_modules/.pnpm/@rspack+core@0.2.0_webpack-dev-server@4.13.1_webpack@5.76.0/node_modules/@rspack/core/src/compiler.ts:779:20
    at Hook.eval [as callAsync] (eval at create (/Users/jaykariesch/projects/rspack/react/node_modules/.pnpm/tapable@2.2.1/node_modules/tapable/lib/HookCodeFactory.js:33:10), <anonymous>:15:1)
    at Hook.CALL_ASYNC_DELEGATE [as _callAsync] (/Users/jaykariesch/projects/rspack/react/node_modules/.pnpm/tapable@2.2.1/node_modules/tapable/lib/Hook.js:18:14)
    at doRun (/Users/jaykariesch/projects/rspack/react/node_modules/.pnpm/@rspack+core@0.2.0_webpack-dev-server@4.13.1_webpack@5.76.0/node_modules/@rspack/core/src/compiler.ts:775:25) {
  code: 'StringExpected'
}

Providing a string or a function allows you to use a custom name. Specifying either a string or a function that always returns the same string will merge all common modules and vendors into a single chunk. This might lead to bigger initial downloads and slow down page loads.

Ideally I'd like to be able to leverage this feature as I do in webpack where each package that has a test match is fed through the chunkGroups group, so that I can return a new chunk for each package, rather than all of the packages being bundled into a single vendor chunk.

Reproduce link

https://github.com/oqx/rspack-vendor-chunks

Reproduce Steps

  1. pnpm install
  2. pnpm build
  3. pnpm build:vendor

Details and commands are also in the README, and annotations are in the config files. There's also an abbreviated webpack.config.js that I use in a few projects to code split node modules.

@oqx oqx added bug Something isn't working pending triage The issue/PR is currently untouched. labels Jun 5, 2023
@hyf0 hyf0 added the duplicated The issue/PR is duplicate of others label Jun 6, 2023
@hyf0
Copy link
Collaborator

hyf0 commented Jun 6, 2023

Rspack only supports passing string now.
image

The description parts have some mistakes, I will fix them soon.

I'm going to close this one for duplicated of #1653.

@hyf0 hyf0 closed this as not planned Won't fix, can't repro, duplicate, stale Jun 6, 2023
@hyf0
Copy link
Collaborator

hyf0 commented Jun 6, 2023

Support passing function may significantly slow the compiling time, so we haven't decided whether to implement it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working duplicated The issue/PR is duplicate of others pending triage The issue/PR is currently untouched.
Projects
None yet
Development

No branches or pull requests

2 participants