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

Slow Hot Reload Times In Vite #5

Closed
sam-frampton opened this issue Nov 15, 2022 · 3 comments
Closed

Slow Hot Reload Times In Vite #5

sam-frampton opened this issue Nov 15, 2022 · 3 comments

Comments

@sam-frampton
Copy link

sam-frampton commented Nov 15, 2022

Hey, thanks for making the library.

I've been using Macaron plugin with Vite in a medium size TS Monorepo project with a React Project. After introducing the plugin library to Vite project I've noticed my hot reload times have increased substantially to 30-60 secs.

These hot reload times are bigger than when I used library such as Chakra UI with Vite in the past. To be truthful, I'm no expert in debugging hot reload speed problem but from what I can see in my network tab, the lag in web-page rendering is when the macaron plugin transpiles code.

Screenshot 2022-11-15 at 22 54 45

Packages

"vite": "^3.0.9"
"@vitejs/plugin-react": "1.3.2"
"@macaron-css/core": "^0.1.10"
"@macaron-css/react": "^0.1.10"
"@macaron-css/vite": "^0.1.12"

My current Vite config

import { defineConfig } from 'vite';
import { macaronVitePlugin } from '@macaron-css/vite';
import react from '@vitejs/plugin-react';

export default defineConfig({
  plugins: [macaronVitePlugin(), react()],
  server: {
    port: 3000
  },
  build: {
    target: 'esnext'
  },
  optimizeDeps: {
    esbuildOptions: { preserveSymlinks: true }
  }
});

Can you offer any tips or suggestions to get the hot reload times down?

@Mokshit06
Copy link
Member

Hey, macaron shouldn't be affecting your HMR times this much unless its also evaluating the code that is not required. One of the ways I've encountered this is when using barrel exports and imports, i.e. export * in a file and then importing that file and using it's exports inside style declarations.

If this doesn't fix your issue I'll be happy to look at a reproduction if that's something that's possible.

@sam-frampton
Copy link
Author

sam-frampton commented Nov 17, 2022

@Mokshit06 Hey thanks for the tip. I think it's most definitely evaluating code that is not required. I currently have a UI folder that exports a lot of components that I import in other components in my React App.

Each time a component my app begins to HMR for an abnormal amount of time. I'll take your advice and remove barrel imports inside other style declarations. If the issue persists I'll send a reproduction.

Many thanks for responding

@sam-frampton
Copy link
Author

@Mokshit06 I can confirm it was the barrel imports! It's nice blazingly fast again 🎉

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants