Installations
npm install vite-plugin-build-routes
Developer Guide
Typescript
Yes
Module System
ESM
Min. Node Version
>=22
Node Version
22.12.0
NPM Version
10.9.0
Score
51.5
Supply Chain
74.7
Quality
83.4
Maintenance
100
Vulnerability
98.6
License
Releases
Contributors
Unable to fetch Contributors
Languages
TypeScript (56.47%)
JavaScript (43.53%)
Developer
node-ecosystem
Download Statistics
Total Downloads
195
Last Day
6
Last Week
28
Last Month
137
Last Year
195
GitHub Statistics
18 Commits
1 Branches
1 Contributors
Bundle Size
0.98 kB
Minified
576.00 B
Minified + Gzipped
Package Meta Information
Latest Version
0.2.1
Package Id
vite-plugin-build-routes@0.2.1
Unpacked Size
5.96 kB
Size
2.77 kB
File Count
5
NPM Version
10.9.0
Node Version
22.12.0
Publised On
08 Jan 2025
Total Downloads
Cumulative downloads
Total Downloads
195
Last day
100%
6
Compared to previous day
Last week
0%
28
Compared to previous week
Last month
136.2%
137
Compared to previous month
Last year
0%
195
Compared to previous year
Daily Downloads
Weekly Downloads
Monthly Downloads
Yearly Downloads
Peer Dependencies
1
vite-plugin-build-routes
A Vite plugin to simplify the build of API routes: copy all files from a target directory to a build output directory.
⚙️ Install
1yarn add -D vite-plugin-build-routes
📖 Usage
Example:
/server/api
as target directory that contains/server/api/user/index.ts
file/dist
as build output directory- register
vite-plugin-build-routes
plugin and server plugin (see below) - build with Vite (e.g.
yarn vite build
) - the result is
/dist/server/api/user/index.mjs
Register the Vite Plugin (example with Vike)
1// vite.config.ts 2import vike from 'vike/plugin' 3import { vikeNode } from 'vike-node/plugin' 4import type { UserConfig } from 'vite' 5import viteBuildRoutes from 'vite-plugin-build-routes' 6 7export default { 8 plugins: [ 9 vike(), 10 vikeNode('server/index.ts'), 11 viteBuildRoutes('server/api') 12 // OR use a pattern instead of default '**/*.ts' 13 // viteBuildRoutes({ 14 // entry: 'server/api', 15 // pattern: '**/*.js' 16 // }) 17 ] 18} satisfies UserConfig
Use the Server Plugin (example with Hono)
Use the universal-autorouter package to automatically scan and load all routes to the server.
1// /server/index.ts 2import path from 'node:path' 3import { serve } from '@hono/node-server' 4import { Hono } from 'hono' 5import vike from 'vike-node/hono' 6import autoloadRoutes from 'universal-autorouter' 7 8const app = new Hono() 9 10await autoloadRoutes(app, { 11 pattern: process.env.NODE_ENV === 'production' ? '**/*.mjs' : '**/*.ts', 12 prefix: '/api', 13 routesDir: path.resolve(import.meta.dirname, 'api'), 14 viteDevServer: globalThis.__vikeNode?.viteDevServer // needed for Vite's HMR 15}) 16 17app.use(vike()) 18 19const port = +(process.env.PORT || 3000) 20 21serve({ 22 fetch: app.fetch, 23 port 24}, () => console.log(`Server running at http://localhost:${port}`))
No vulnerabilities found.
No security vulnerabilities found.