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

Remix Vite Plugin triggers watchers during Build #8313

Closed
kube opened this issue Dec 16, 2023 · 4 comments
Closed

Remix Vite Plugin triggers watchers during Build #8313

kube opened this issue Dec 16, 2023 · 4 comments

Comments

@kube
Copy link

kube commented Dec 16, 2023

Reproduction

I'm using the Vite Plugin for building an app (and deploy it to Production), and I have two issues:

  1. vite build seems to trigger watchers on all files in my workspace.
    Using pnpm on Gitlab, I configured viteConfig.server.watch.ignored to include **/.pnpm-store/**.
    This prevents the CI to crash because of too many inotify watchers.

    (See kinda related issue https://gitlab.com/gitlab-org/gitlab/-/issues/434329)

    I'm not sure if the watchers are due to the Remix Plugin or to Vite itself, but I have to put context here.

    I don't understand why vite build would need to watch anything on the workspace?

  2. Until version 2.4.0 it was possible to configure which files had to be ignored, but since 2.4.0 (in this commit), the configuration of the Server does not overwrite User config but does an entire replace instead.

Configuration

export default defineConfig({
  server: { port: 3000, {
    watch: {
     ignored: ["**/.pnpm-store/**"] // This is not read by the plugin anymore
    }
  },
  plugins: [
    tsConfigPaths(),
    remix({
      ignoredRouteFiles: ["**/.*", "**/*.css", "**/*.test.{js,jsx,ts,tsx}"],
    }),
  ],
});

System Info

(System is not relevant here, the issue is on Gitlab CI.)

  System:
    OS: macOS 14.2
    CPU: (10) arm64 Apple M1 Max
    Memory: 16.54 GB / 64.00 GB
    Shell: 5.9 - /bin/zsh
  Binaries:
    Node: 21.3.0 - ~/.nvm/versions/node/v21.3.0/bin/node
    Yarn: 1.22.21 - ~/.nvm/versions/node/v21.3.0/bin/yarn
    npm: 10.2.4 - ~/.nvm/versions/node/v21.3.0/bin/npm
    pnpm: 8.7.6 - ~/Library/pnpm/pnpm
  Browsers:
    Chrome: 120.0.6099.109
    Safari: 17.2
  npmPackages:
    @remix-run/dev: 2.4.0 => 2.4.0 
    @remix-run/eslint-config: 2.4.0 => 2.4.0 
    @remix-run/express: 2.4.0 => 2.4.0 
    @remix-run/node: 2.4.0 => 2.4.0 
    @remix-run/react: 2.4.0 => 2.4.0 
    @remix-run/server-runtime: 2.4.0 => 2.4.0 
    vite: 5.0.10 => 5.0.10

Used Package Manager

pnpm

Expected Behavior

  1. Remix Vite plugin should not trigger watchers during build.

  2. It should be possible to configure which files should be ignored using viteConfig.server.watch.ignored.

Actual Behavior

  1. Remix Vite Plugin triggers watchers for all files in workspace (except node_modules/ and .git/ which are Vite defaults)

  2. viteConfig.server.watch.ignored is entirely skipped by the Remix Vite Plugin.

@kube
Copy link
Author

kube commented Dec 16, 2023

I just took a quick look at how SvelteKit managed the build, and it seems that they don't use vite.createServer but just vite.build:

https://github.com/sveltejs/kit/blob/c0f3c403b774df72b113646559e915e4f53a8566/packages/kit/src/exports/vite/index.js#L740

@pcattori pcattori added the vite label Dec 16, 2023
@kube
Copy link
Author

kube commented Dec 17, 2023

Quick and dirty fix (until implementation using vite.build) could be to set viteConfig.server.watch to null.

@hi-ogawa
Copy link
Contributor

hi-ogawa commented Dec 17, 2023

Interesting, thanks for reporting the issue.
The code you're referencing (around viteChildCompiler = await vite.createServer(...)) is currently necessary for both dev and build and it's used for transforming code independently from Vite (but still benefiting from Vite-powered transform).

Note that Remix makes use of vite.build API for main build already, but viteChildCompiler is still necessary and I think this is somewhat internal detail (and thus not inheriting all user config via { server: { ... viteUserConfig.server } } feels still right to me and there was an issue with that #7953 (comment)):

await vite.build({

To fix this, viteConfig.server.watch: null makes sense and I think that should be safe at least for build case. Thanks for the suggestion!

@markdalgleish
Copy link
Member

Fixed by #8320.

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

4 participants