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

Monorepo support for config imports #3067

Closed
swandir opened this issue Apr 20, 2021 · 3 comments
Closed

Monorepo support for config imports #3067

swandir opened this issue Apr 20, 2021 · 3 comments

Comments

@swandir
Copy link
Contributor

swandir commented Apr 20, 2021

Clear and concise description of the problem

Vite currently supports monorepo-based setups for application code.

Now, in a monorepo, I want to implement a vite-plugin package in TypeScript that I plan to make use of in other monorepo packages without additional build step.

Right now Vite crashed when trying to load vite.config.ts that imports my plugin.

That happens because all bare imports are externalized during config bundling here:

build.onResolve({ filter: /.*/ }, (args) => {
const id = args.path
if (id[0] !== '.' && !path.isAbsolute(id)) {
return {
external: true

Suggested solution

Vite could check if a package being imported in the config is a local package before externalizing it.

Alternative

UPD: Build step can be avoided on the local vite-plugin package by using an intermediary index.js module that wires up esbuild-register or tsm and then re-exports the actual entry point written in TS.

Additional context

@bluwy
Copy link
Member

bluwy commented Mar 6, 2022

This sounds like it would open a can of worms, especially if the linked dependency contains transitive dependencies too. Node can't resolve those normally as we would have bundled the linked dependency, unless we bundle everything in the linked dependency, including it's transitive dependencies. Though now, there are two issues: (1) The Vite config would have to bundle a lot every time, (2) Transitive dependencies could be duplicated, causing weird runtime errors. With the reasons, I think it's simpler to have a build step for the linked dependency instead.

@bluwy bluwy closed this as completed Mar 6, 2022
@swandir
Copy link
Contributor Author

swandir commented Mar 6, 2022

Makes sense.

And build step can be avoided on the local vite-plugin package by using an intermediary index.js module that wires up esbuild-register or tsm and then re-exports the actual entry point in TS.

@bluwy
Copy link
Member

bluwy commented Mar 10, 2022

Actually I just noticed that we have a duplicate #5370 too proposing the same thing, so perhaps it's something doable within Vite, but let's keep that issue open up as it has more discussion about the feature.

@github-actions github-actions bot locked and limited conversation to collaborators Mar 25, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

2 participants