2

Can someone help me speed up my ViteJs Server a bit?

The problem is that in development mode the server is mega slow. I start the server, then start the page in the browser and wait 3-6 minutes for the page to load! Initially, ViteJs downloads a few kilobytes of resources, then the request is in the "pending" state for 2-3 minutes.

Then the loading of all resources starts every time. Although I also specified in the config that all css should be local.

Page reloading is also very slow.

I start the project like this:

vite

Here is my config:

import {defineConfig} from 'vite'
import vue from '@vitejs/plugin-vue'
import {resolve} from 'path'

export default defineConfig({
  plugins: [vue()],
  resolve: {
    alias: {
      "@": resolve(__dirname, "./src"),
    },
  },
  publicDir: 'public',
  server: {
    port: 8080,
    watch: {
      usePolling: true,
      ignored: ['!**/bundle/**', '!**/lib/**']
    }
  },
  css: {
    modules: {
      scopeBehaviour: "local"
    }
  },
  preview: {
    port: 8080,
  }
})
JDev
  • 2,157
  • 3
  • 31
  • 57
  • 1
    Do you have network throttling turned on in devtools? – Reyno Aug 02 '22 at 08:51
  • @Reyno - nope. Chrome -> Network -> NoThrottling – JDev Aug 02 '22 at 08:56
  • I have windows, and starting vite from wsl2. Could this be a problem? Although it shouldn't, I start all other services the same way. And there are no problems with speed. – JDev Aug 02 '22 at 08:58

2 Answers2

7

Wow, the problem is in WSL2! Just tried, for the sake of interest, to start vite from Windows. Start page loaded in 1 second! I think I solved my problem myself! Thanks!

JDev
  • 2,157
  • 3
  • 31
  • 57
  • 1
    Can you tell a bit more about it what does it mean "start vite from Windows"? You turned off WSL2 on windows? – Konrad Grzyb Dec 30 '22 at 17:20
  • Yes. Just start npm/node process(npm run dev for example) from Windows cmd/powerShell. – JDev Dec 31 '22 at 09:07
  • I agree. Start your npm run dev in cmd or Powershell. It's a hell lot faster. I used to run mine in VSCode. – Jan Michael Jan 04 '23 at 02:34
  • This hasn't solved my problem, on my side it still works slowly, even after running dev server from PowerShell :/ Any other ideas, why could it be? – Bulchsu Apr 21 '23 at 13:28
  • The problem could have been caused by the fact that Vite was running on Windows, but the files were accessible on WSL2 running Linux, or vice versa. The main issue is the slow write speed between the WSL2 and Windows file systems. Vite.js creates a cache, builds the project, and immediately updates it live if there are any changes in the source code. --> So Vite performs a lot of writing, especially during development. – rozsazoltan Jul 05 '23 at 09:28
  • It's important to note that if you store your project on a Windows system, it's advisable to also start the development server from Windows. If you store your project on WSL2 with installed Linux, then run Vite there as well. This way, you can avoid the lingering slow file write issue with WSL2. [More information - another stackoverflow answer](https://stackoverflow.com/a/68974497/15167500) - [WSL Github Issue](https://github.com/microsoft/WSL/issues/4197#issuecomment-1400282463) – rozsazoltan Jul 05 '23 at 09:34
-2

Vite is not a suitable tool for large projects, because it does not bundle the source code for you during development, and in order to reload your browser needs to make thousands of requests

It is very slow, if you are a large project (with 1000+ source files) don't use vite or you will have bad development experience

NOname
  • 1
  • Your answer could be improved with additional supporting information. Please [edit] to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Jul 07 '23 at 20:31