{"id":20276184,"url":"https://github.com/vanilla-icecream/vite-plugin-fastify","last_synced_at":"2025-04-11T05:42:09.120Z","repository":{"id":61953145,"uuid":"556528892","full_name":"Vanilla-IceCream/vite-plugin-fastify","owner":"Vanilla-IceCream","description":"Fastify plugin for Vite with Hot-module Replacement.","archived":false,"fork":false,"pushed_at":"2024-10-07T02:12:26.000Z","size":271,"stargazers_count":11,"open_issues_count":0,"forks_count":1,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-04-09T04:47:56.728Z","etag":null,"topics":["fastify","hmr","vite"],"latest_commit_sha":null,"homepage":"https://vitesheet.onrender.com/vite-plugin-fastify/","language":"TypeScript","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/Vanilla-IceCream.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}},"created_at":"2022-10-24T02:45:06.000Z","updated_at":"2025-01-12T05:34:15.000Z","dependencies_parsed_at":"2024-01-07T18:06:17.716Z","dependency_job_id":"a39bf0f4-957b-496a-9e20-e4ab4341d59d","html_url":"https://github.com/Vanilla-IceCream/vite-plugin-fastify","commit_stats":{"total_commits":7,"total_committers":1,"mean_commits":7.0,"dds":0.0,"last_synced_commit":"84e7ac98b2f9d1c49b0b38975b403d4d03ddcee2"},"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Vanilla-IceCream%2Fvite-plugin-fastify","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Vanilla-IceCream%2Fvite-plugin-fastify/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Vanilla-IceCream%2Fvite-plugin-fastify/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Vanilla-IceCream%2Fvite-plugin-fastify/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Vanilla-IceCream","download_url":"https://codeload.github.com/Vanilla-IceCream/vite-plugin-fastify/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248351385,"owners_count":21089269,"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":["fastify","hmr","vite"],"created_at":"2024-11-14T13:12:47.344Z","updated_at":"2025-04-11T05:42:09.094Z","avatar_url":"https://github.com/Vanilla-IceCream.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# vite-plugin-fastify\n\nFastify plugin for Vite with Hot-module Replacement.\n\n## Installation\n\nInstall `vite-plugin-fastify` with your favorite package manager:\n\n```sh\n$ npm i vite-plugin-fastify -D\n# or\n$ yarn add vite-plugin-fastify -D\n# or\n$ pnpm i vite-plugin-fastify -D\n# or\n$ bun add vite-plugin-fastify -D\n```\n\n## Usage\n\n### Add Scripts\n\nAdd the following scripts to your `package.json` file:\n\n```json\n{\n  // ...\n  \"type\": \"module\",\n  \"scripts\": {\n    \"dev\": \"vite\",\n    \"build\": \"vite build\",\n    \"preview\": \"vite preview\"\n  }\n  // ...\n}\n```\n\n### Configuration\n\nAdd the following configuration to your `vite.config.ts`:\n\n```ts\n// vite.config.ts\nimport { resolve } from 'path';\nimport { defineConfig } from 'vite';\nimport fastify from 'vite-plugin-fastify';\n\nexport default defineConfig({\n  server: {\n    host: '127.0.0.1',\n    port: 3000,\n  },\n  plugins: [\n    fastify({\n      appPath: './src/app.ts', // Default: \u003crootDir\u003e/src/app.ts\n      serverPath: './src/server.ts', // Default: \u003crootDir\u003e/src/server.ts\n    }),\n  ],\n  resolve: {\n    alias: {\n      '~': resolve(__dirname, 'src'),\n    },\n  },\n});\n```\n\n```ts\n// src/app.ts\nimport fastify from 'fastify';\n\nexport default () =\u003e {\n  const app = fastify();\n\n  app.get('/api/hello-world', async (req, reply) =\u003e {\n    return reply.send('Hello, World!');\n  });\n\n  return app;\n};\n```\n\n```ts\n// src/server.ts\nimport app from './app';\n\nconst server = app();\n\nconst start = () =\u003e {\n  try {\n    await server.listen({ host: '127.0.0.1', port: 3000 });\n  } catch (err) {\n    server.log.error(err);\n    \n    if (process.env.NODE_ENV === 'production') {\n      process.exit(1);\n    }\n  }\n};\n\nstart();\n```\n\n## Known Issues\n\nThis plugin does not support WebSocket.\n\nFor a workaround, use `vite-node` for development:\n\n```diff\n- \"dev\": \"vite\",\n+ \"dev\": \"vite-node -w src/server.ts\",\n```\n\nSet to `false` to disable HMR during development:\n\n```diff\n  plugins: [\n    fastify({\n+     devMode: false,\n    }),\n  ],\n```\n\nAdd `import.meta.hot` support to vite-node for HMR:\n\n```diff\nconst start = async () =\u003e {\n  try {\n    await server.listen({ host: '127.0.0.1', port: 3000 });\n  } catch (err) {\n    server.log.error(err);\n    \n    if (process.env.NODE_ENV === 'production') {\n      process.exit(1);\n    }\n  }\n\n+ if (import.meta.hot) {\n+   import.meta.hot.on('vite:beforeFullReload', async () =\u003e {\n+     await server.close();\n+   });\n\n+   import.meta.hot.dispose(async () =\u003e {\n+     await server.close();\n+   });\n+ }\n};\n```\n\nSee the [`examples`](./examples) folder for more details.\n\n## File-based Routing\n\n`vite-plugin-fastify` does not support `@fastify/autoload` when executing the build command, as Vite is a bundler that places bundled files in the `dist/assets` directory. If support is required, `@fastify/autoload` would need to be made compatible with `import.meta.glob` syntax, or alternatively, consider using `vite-plugin-fastify-routes`.\n\n- [vite-plugin-fastify-routes](https://github.com/Vanilla-IceCream/vite-plugin-fastify-routes)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fvanilla-icecream%2Fvite-plugin-fastify","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fvanilla-icecream%2Fvite-plugin-fastify","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fvanilla-icecream%2Fvite-plugin-fastify/lists"}