{"id":15630680,"url":"https://github.com/bluwy/vite-plugin-warmup","last_synced_at":"2025-04-09T05:09:01.155Z","repository":{"id":149228038,"uuid":"621213706","full_name":"bluwy/vite-plugin-warmup","owner":"bluwy","description":"Warm up Vite's transform cache","archived":false,"fork":false,"pushed_at":"2024-09-18T03:41:06.000Z","size":51,"stargazers_count":222,"open_issues_count":0,"forks_count":4,"subscribers_count":4,"default_branch":"master","last_synced_at":"2025-04-02T04:01:53.529Z","etag":null,"topics":["vite-plugin"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/bluwy.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null},"funding":{"github":"bluwy"}},"created_at":"2023-03-30T08:05:31.000Z","updated_at":"2025-03-15T23:21:47.000Z","dependencies_parsed_at":null,"dependency_job_id":"951d22ef-3ed0-47f4-b8e7-e203399c7bbc","html_url":"https://github.com/bluwy/vite-plugin-warmup","commit_stats":null,"previous_names":[],"tags_count":4,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bluwy%2Fvite-plugin-warmup","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bluwy%2Fvite-plugin-warmup/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bluwy%2Fvite-plugin-warmup/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bluwy%2Fvite-plugin-warmup/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/bluwy","download_url":"https://codeload.github.com/bluwy/vite-plugin-warmup/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247980837,"owners_count":21027808,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["vite-plugin"],"created_at":"2024-10-03T10:35:10.018Z","updated_at":"2025-04-09T05:09:01.134Z","avatar_url":"https://github.com/bluwy.png","language":"JavaScript","funding_links":["https://github.com/sponsors/bluwy"],"categories":["JavaScript"],"sub_categories":[],"readme":"# vite-plugin-warmup\n\nWarm up Vite's transform cache as soon as the server initializes.\n\n**Requires Vite \u003e=4.3. Does not work with `middlewareMode`.**\n\n**For Vite 5, use [server.warmup](https://vitejs.dev/guide/performance.html#warm-up-frequently-used-files) instead.**\n\n## Why\n\n### On-demand nature\n\nVite at it's core is an on-demand file server. When a request comes in, it will transform the file and serve it. This means we only do the work that is requested, keeping the dev server fast.\n\nHowever, sometimes we know in advance which files will be requested when we start our development cycle. Instead of Vite idling before we open up the page, we can start transforming the files beforehand so when it gets requested, it's cached and can be served immediately.\n\n### Deep module graph\n\nTake this module graph where the left file would import the right file:\n\n```\nfoo.js -\u003e bar.vue -\u003e baz.js -\u003e qux.json\n```\n\nThe imported ids can only be known after the file is transformed, so if `bar.vue` takes some time to transform, `baz.js` has to wait for it's turn, and so on. This causes an internal waterfall the deeper the imports are.\n\nBy warming up `baz.js`, or any files that you know is hot path in your app, they'll be cached and can be served immediately.\n\n## Usage\n\n### Setup\n\nInstall `vite-plugin-warmup`:\n\n```bash\nnpm install vite-plugin-warmup\n```\n\nUse the Vite plugin:\n\n```js\n// vite.config.js\nimport { defineConfig } from 'vite'\nimport { warmup } from 'vite-plugin-warmup'\n\nexport default defineConfig({\n  plugins: [\n    warmup({\n      // warm up the files and its imported JS modules recursively\n      clientFiles: ['./**/*.html', './src/components/*.jsx']\n    })\n  ]\n})\n```\n\nThe plugin accepts `clientFiles` and `ssrFiles` options. As the name suggests, the files specified would be warmed up for the client and server transforms respectively.\n\nThe files can be direct file names or glob patterns using [fast-glob](https://github.com/mrmlnc/fast-glob).\n\n\u003e **NOTE:** It's recommended to **not** turn off `server.preTransformRequests` in the Vite config, as that prevents transforming the module graph recursively.\n\n### Which files should I warm up?\n\nIf you're using Vite SPA with a `index.html` file, add that to the `clientFiles` option and you're good to go!\n\n```js\nwarmup({ clientFiles: ['./**/*.html'] })\n```\n\nYou can also run `DEBUG=\"vite:transform\" vite` to see the files that are being transformed. With `vite-plugin-warmup`, you should see these logs before you load the page.\n\nLogs that appear after the page load are URLs that didn't get warmed up, if so, you can add more of them into the `clientFiles` option. Note that only actual files in the file system are supported.\n\n```bash\nvite:transform 28.72ms /@vite/client +1ms\nvite:transform 62.95ms /src/components/BigComponent.jsx +1ms\n```\n\n```js\nwarmup({ clientFiles: ['./**/*.html', './src/components/BigComponent.jsx'] })\n```\n\nIf you're using SSR, you can use the `ssrFiles` option instead. As the Vite logs doesn't differentiate between client and server transforms, make sure the files added are safe to be transformed in the client or server respectively.\n\n\u003e **NOTE:** Make sure to read the [Why](#why) section to understand which files to add to not overload the Vite server on startup.\n\n### Metaframeworks\n\nSome metaframeworks don't load the files through Vite directly, so this plugin might not work for them. To be sure which files are loaded by Vite, you can start the metaframework with the `DEBUG=\"vite:transform\"` flag and follow the [steps above](#which-files-should-i-warm-up).\n\n`vite-plugin-warmup` also exports a `warmupFile` function you can use to warm up specific files (absolute paths only). If you need more control, you can reuse the `warmupFile` implementation in [index.js](./index.js).\n\n## Attribution\n\n- [Nuxt's warmup phase](https://github.com/nuxt/nuxt/blob/826c05415400e899779f61e2e20e757786baa200/packages/vite/src/utils/warmup.ts).\n\n## Sponsors\n\n\u003cp align=\"center\"\u003e\n  \u003ca href=\"https://bjornlu.com/sponsors.svg\"\u003e\n    \u003cimg src=\"https://bjornlu.com/sponsors.svg\" alt=\"Sponsors\" /\u003e\n  \u003c/a\u003e\n\u003c/p\u003e\n\n## License\n\nMIT\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbluwy%2Fvite-plugin-warmup","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbluwy%2Fvite-plugin-warmup","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbluwy%2Fvite-plugin-warmup/lists"}