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

Loading a config file is slow #284

Open
ArnaudBarre opened this issue Feb 23, 2022 · 2 comments
Open

Loading a config file is slow #284

ArnaudBarre opened this issue Feb 23, 2022 · 2 comments
Labels
bug Something isn't working

Comments

@ArnaudBarre
Copy link

When adding this plugin, vite startup time goes from ~400ms to ~550ms without config file to ~700ms with config file.

I don't know what causes the first slow down, but for the second one it seems to be how the config is compiled. And caching doesn't seems to help a lot on restart. I think this plugin could use esbuild to bundle the config instead of jiti. I can try a PR if you want.

Screenshot 2022-02-23 at 20 23 04

@ArnaudBarre ArnaudBarre added the bug Something isn't working label Feb 23, 2022
@jinzhubaofu
Copy link

jinzhubaofu commented Dec 14, 2022

@ArnaudBarre I got this problem too. I figured out a solution which maybe can help you.

TLDR: you should keep windi.config.ts as easy as possible. Put your configurations which depends on 3rd party npm package in your vite.config.ts.

import {defineConfig} from 'vite';
import windicss from 'vite-plugin-windicss';

export default defineConfig({
  // ...
  plugins: [
    windicss({
      async onConfigResolved(config) {
         // override the windicss config, eg: extract, etc.
        return merge({}, config, {extract: {extractros: []}});
      }
    })
  ]
});

Here is why:

  1. vite-plugin-windicss will load your windi.config.ts using jiti.
  2. jiti will transform all the depedencies of windi.config.ts with babel, to compile ts into js and make sure it's cjs format.

So, jiti will cost a lot time.

@jinzhubaofu
Copy link

Maybe jiti is not a good option for vite-plugin-windicss:
jiti runs in cjs mode, and uses require and cjs-format npm package first. But this conflicts with vite. jiti will throw error if a npm package doesn't provide a cjs-format export. Though, we can set env variable JITI_ESM_RESOLVE to get over the error, but this cost too much efforts to debug.

And jiti's transpile cache is disabled in @windicss/config for now. Maybe we should enable it?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants