-
-
Notifications
You must be signed in to change notification settings - Fork 5.9k
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
Help with monorepo #1491
Comments
We should probably provide some documentation for this. /cc @LinusBorg @csr632 @AlexandreBonaventure who I know have been using Vite in monorepos |
I'm running a monorepo with yarn workspaces - lerna is only used to run multiple commands in packages in parallel, pretty much). I have aded the package(s) to the "example-ui" app's alias: {
'ui-common': 'ui-common/src/common.vue',
'ui-dashboard': 'ui-dashboard/src/dashboard.vue',
}, This means that the example app is able to properly resolve the src entry point for each package, so you don't need to have a build process running for them to keep the in my repo, all packages have entry files ( |
I am using pretty much the same setup as @LinusBorg (every package as an entry file with a async function getWorkspaces () {
const pkg = await fs.promises.readFile(path.resolve(process.cwd(), './package.json'), { encoding: 'utf-8' });
try {
const { dependencies } = JSON.parse(pkg);
const qualified = Object.keys(dependencies).filter(depName => depName.startsWith('@your-organization-name'));
return qualified;
} catch (e) {
console.error(e);
return [];
}
}
return {
optimizeDeps: {
link: getWorkspaces()
}
} |
I'm experimenting with Vite.js and Yarn Worskpaces and it works quite well: https://github.com/MatejBransky/worskpaces-in-workspaces Basically my app (examples/monorepo/app) loads my plugin which add aliases for all workspaces defined in root package.json (pkg.workspaces attribute) and aliases values are gathered from the workspaces pkg.source attributes. It's really just an experiment |
I have created a demo project for vite + monorepo:
Project strusture:
This is a valilla setup to show how to make vite wrok with monorepo. For a more smooth workflow for bigger project(more demos), checkout this demo project. |
RFC Hello guys, i'm coming to this thread referenced from #1554 where @yyx990803 call my attention to here. Would be great a cli tool to produce multi apps/libs and keep compatibility with vite-cli. Current i'm doing some research and prototyping with vite. Instead of using lerna (nothing against it, pretty good tool) but i would like to enrich vue/vite ecosystem with a tool more or less like nx.dev does to angular. I will leave here a idea spec for further discussion. This approach have some history (long a bit) that what i saw in many companies that follow lerna approach for multi vue apps and most of them regret on that decision. |
Hi, I have a similar setup: monorepo using lerna + local packages with some vue 3 components & styles. No entry point in the local packages and they are listed in my app package.json. Everything works pretty well, but I have some problem with local packages after vite build. For local development it works, but for code in my app: <script lang="ts">
import { defineComponent } from 'vue';
// local package
import Icon from 'local-package/Icon.vue';
export default defineComponent({
name: 'Sidebar',
components: {
Icon,
},
});
</script>
<template>
<div class="sidebar">
<a href="https://link.net">
<Icon name="Logo" size="medium" />
</a>
</div>
</template>
result: <div class="sidebar" data-v-1c836e6c="">
<a href="https://link.net">
<logo color="#00B6EB" name="icon" class="medium"></logo>
</a>
</div> but it should be <div class="sidebar" data-v-1c836e6c="">
<a href="https://link.net">
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 22 22">
<path fill-rule=...
</svg>
</a>
</div> I can create a new issue for this, but I hope it's related to monorepo stuff. It's up to you. Thx |
@JkmAS I don't think it has something to do with monorepo. It looks like the component is not resolved correctly at runtime. Sometimes it happens when you have circular dependencies. You should probably create a reproduction if you want some help. |
这是我的 monorepo 项目,目前遇到了一个问题,依赖的包里面的 .scss 文件 , @import 时找不到模块,有谁知道这么处理么 |
@yyx990803, I just made an example repo with 2 workspaces, with one one importing the other. I didn't have to list it in dependencies, and I didn't use |
@threepointone yeah, the internals changed quite a bit over the course of 2.0 beta and this thread is a bit out of date. I guess I'll close this thread to avoid confusion for new users. |
Apologies for digging up a closed thread, but it already contains some monorepo examples so feels like the best place to do it.
This does confuse me a bit I'm afraid, and the documentation isn't entirely clearing it up for me either. Setting up a fully functional (developer friendly) development workflow for a monorepo is rather complicated, especially if you add TS in the mix. The fact that Vite seems to help out here is pretty awesome, I'm just wondering if my understanding is correct:
If, in the first case, the imported project happened to be a Vite library-mode project with its own config (and plugins), would this still be respected during compilation, or would the consumer config and plugins be used instead? Lastly, do we know of any example/open-source projects that happen to be running a (non-trivial) monorepo Vite setup? edit: @LinusBorg's vue-lib-monorepo-template is a good starting point 🙂 |
Fair warning: I'm still tinkering with this. But it's been working good-ish so far. |
In case it helps others, I put together an example monorepo using Vite and npm 7 workspaces (I recently removed lerna on our team in favor of npm 7 workspaces). There's some other features here I needed like TS Project Reference integration, React component library support, and Storybook integration - |
hey,
i want to setup a monorepo (lerna) with vite and vue3 and i can´t find any working solutions.
The main problem is to consume the local repos in development and benefit from vites fast hot-reloading and all the other sugar it gives to us.
I played with optimizeDeps.link and rollup alias but cannot figure out an acceptable setup without hacky parts.
Can anyone please give an example how this is done right?
My folder structure looks like this:
THX for the great work!
The text was updated successfully, but these errors were encountered: