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

mergeConfig can't unset manualChunks with inlineDynamicImports #19243

Closed
7 tasks done
fallemand opened this issue Jan 20, 2025 · 4 comments
Closed
7 tasks done

mergeConfig can't unset manualChunks with inlineDynamicImports #19243

fallemand opened this issue Jan 20, 2025 · 4 comments

Comments

@fallemand
Copy link
Contributor

fallemand commented Jan 20, 2025

Describe the bug

I have a problem trying to unset manualChunks from the default config using mergeConfig.

My default config defines some manualChunks:

const defaultConfig: {
  build: {
    rollupOptions: {
      output: {
        manualChunks: { ... }
      },
    },
  },
}

My appConfig defines inlineDynamicImports=true, so I need to set manualChunks=undefined. But this is not possible.

const appConfig: {
  build: {
    rollupOptions: {
      output: {
        manualChunks: undefined, // This will ignore it and use the manualChunks from the defaultConfig
        manualChunks: {} // This will fail. Invalid value for option "output.manualChunks" - this option is not supported for "output.inlineDynamicImports".
        manualChunks: () => {} // This will fail. Invalid value for option "output.manualChunks" - this option is not supported for "output.inlineDynamicImports".
        inlineDynamicImports: true,
      },
    },
  },
}

export default mergeConfig(defaultConfig, appConfig);

Vite should allow

inlineDynamicImports: true,
manualChunks: {},

How can I achieve this?

Reproduction

https://stackblitz.com/edit/vitejs-vite-1hhvb7yf?file=vite.config.ts

Steps to reproduce

npm i && num run build

System Info

-

Used Package Manager

npm

Logs

No response

Validations

@fallemand fallemand changed the title mergeConfig with manualChunks & inlineDynamicImports mergeConfig can't unset manualChunks & inlineDynamicImports Jan 20, 2025
@fallemand fallemand changed the title mergeConfig can't unset manualChunks & inlineDynamicImports mergeConfig can't unset manualChunks with inlineDynamicImports Jan 20, 2025
@hi-ogawa
Copy link
Collaborator

I think some limitations of mergeConfig is expected unfortunately. For your use case, would it suffice using config hook to mutate the options? Something like:

      {
        name: 'test',
        config(config) {
          delete config.build.rollupOptions.output.manualChunks;
          config.build.rollupOptions.output.inlineDynamicImports = true;
        }
      }

@patak-dev
Copy link
Member

I think you can also use manualChunks: () => {} here.

We could support something like manualChunks: enforceValue(undefined) that creates something like a EnforcedValue class but I don't know if the added complexity in typing for defineConfig will make this worth it. For now, I would say that we can close this issue and wait for more use cases of a way to enforce value overrides.

@fallemand
Copy link
Contributor Author

Unfortunately, manualChunks: () => {} doesn't work either.

Invalid value for option "output.manualChunks" - this option is not supported for "output.inlineDynamicImports".

I know the plugin option; it's what I'm currently using, but I was checking if there was a cleaner and more straightforward way 👍

@hi-ogawa
Copy link
Collaborator

Let me close this as it seems reasonable to rely on plugins for further control. FYI, there's an issue discussing a similar situation about null/undefined handling in #18943.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants