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

Config option or plugin hooks for dependency pre-bundling #12547

Closed
4 tasks done
guoyunhe opened this issue Mar 23, 2023 · 1 comment
Closed
4 tasks done

Config option or plugin hooks for dependency pre-bundling #12547

guoyunhe opened this issue Mar 23, 2023 · 1 comment
Labels
duplicate This issue or pull request already exists

Comments

@guoyunhe
Copy link

Description

I have made a plugin, which converts, for example:

import { Button } from 'my-package';

to:

import { Button } from 'my-package';
import 'my-package/es/style';

Vite's dependency bundling can only bundle the main js of a package. Here is no way to tell Vite to pre-bundle extra stuff, like styles.

Suggested solution

Provide a hook to pre-bundle extra scripts/styles.

For example:

function plugin () {
  return {
    preBundleExtra: (pkgName) => {
      if (pkgName.startsWith('@myorg/')) {
        return [pkgName + '/es/style', pkgName + '/es/polyfill', ];
      } else {
        return [];
      }
    }
  }
}

Alternative

No response

Additional context

No response

Validations

@sapphi-red
Copy link
Member

You can use the config hook to edit optimizeDeps.include.

Note that CSS pre-bundling is not supported: #7719

@sapphi-red sapphi-red closed this as not planned Won't fix, can't repro, duplicate, stale Mar 25, 2023
@sapphi-red sapphi-red added duplicate This issue or pull request already exists and removed enhancement: pending triage labels Mar 25, 2023
@github-actions github-actions bot locked and limited conversation to collaborators Apr 9, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
duplicate This issue or pull request already exists
Projects
None yet
Development

No branches or pull requests

2 participants