Replies: 1 comment 1 reply
-
|
This is a common issue with linked packages, especially combined with Yarn PnP. A few things to check: 1. Vite's file watcher doesn't see linked packages by defaultVite uses Add the linked packages to the watch scope: // vite.config.ts
export default defineConfig({
server: {
watch: {
// Watch linked package directories
ignored: ['!**/node_modules/@your-org/**'],
},
},
});2. Exclude linked packages from dependency optimizationVite pre-bundles dependencies with esbuild for performance. Linked packages get pre-bundled once and then cached, so subsequent changes aren't picked up: export default defineConfig({
optimizeDeps: {
exclude: ['@your-org/component', '@your-org/common'],
},
});This forces Vite to load these packages fresh on every request in dev mode. 3. Yarn PnP complicationsWith Yarn PnP, there are no
4. The
|
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Hello everyone! I'm hoping to get some help with an issue. It's a bit complicated, so I'll try my best to explain it.
We have three different repositories in my project:
frontend- a web application, using vue and vitecomponent- one repository containing a large vue component. Built using vite. The frontend imports this package.common- a monorepo style repository, containing many small packages. Not using vite to build, only usingtsc. The frontend also imports packages from hereAll these repos also use Yarn (version 4 and PnP). In order to test changes in multiple repos at the same time, we use
yarn link(docs). This allows the frontend repo to use a local package instead of one published to npm.So when starting the frontend repo locally, it usually looks like this:
vite build --watchyarn link ../componentso that the frontend uses the local version of the componentviteAfter having done this, any changes made in the component (changing the text somewhere, updating a color) is NOT registered by the running
viteinstance in the frontend. So the expected behaviour I want is that whenever the component is rebuilt, the frontend instance of vite detects that change and rebuilds.However, if doing the same with a package in the
commonrepository, thenviteregisters the changes in the dependency reloads (using HMR) so that those changes appear in the browser.I have tried using
optimizeDepsbut I haven't had any luck with it so far. It is not needed for thecommonrepository to work.Does anyone have any clue what could be going wrong here? Or any direction for me to look in? Or any thoughts to why this works for
commonbut not forcomponent?EDIT: I have a minor breakthrough, and maybe it is
yarn linkthat is the culprit. For some reason, the linking works differently for the two repos. When printing logs in vite, one points to a local file and another points to node module:Beta Was this translation helpful? Give feedback.
All reactions