Vite Plugin Node
Note: this plugin is still under active development
A vite plugin to allow you to use vite as node dev server.
Why?
- While frontend development tooling is evolving rapidly in recent years, backend DX is still like in stone age. No hot module replacement; Typescript recompiling slow as funk; Lack of plugin system etc. Thanks to Vitejs created by Evan You (a.k.a creator of vuejs; my biggest idol developer), makes all those dreams for backend development come true!
Get started
-
Install vite and this plugin with your favourite package manager, here use npm as example:
$ npm install vite vite-plugin-node -D
-
Create a vite.config.js
file in your project root to config vite to actually use this plugin:
import { VitePluginNode } from 'vite-plugin-node';
const config = {
plugins: [
VitePluginNode({
server: 'express',
appPath: './app.ts',
port: 3000,
tsCompiler: 'esbuild',
createCustomServer: () => IServer
})
]
}
export default config;
-
Update your server entry to export your app named createViteNodeApp
ExpressJs
const app = express();
if (process.env.NODE_ENV === 'production') {
app.listen(3000)
}
export const createViteNodeApp = app;
NestJs
import { NestFactory } from '@nestjs/core';
import { AppModule } from './app.module';
if (process.env.NODE_ENV === 'production') {
async function bootstrap() {
const app = await NestFactory.create(AppModule);
await app.listen(3000);
}
bootstrap();
}
export const createViteNodeApp = NestFactory.create(AppModule);
-
Add a npm script to run the dev server:
"scripts": {
"dev": "vite-node"
},
-
Run the script! npm run dev
To-Do
As this plugin just fresh developed, there are still lots ideas need to be implemented, including:
Bugs
Create an issue if you found any bugs to helpe me to improve this project