Our great sponsors
-
SurveyJS
Open-Source JSON Form Builder to Create Dynamic Forms Right in Your App. With SurveyJS form UI libraries, you can build and style forms in a fully-integrated drag & drop form builder, render them in your JS app, and store form submission data in any backend, inc. PHP, ASP.NET Core, and Node.js.
-
Nest
A progressive Node.js framework for building efficient, scalable, and enterprise-grade server-side applications with TypeScript/JavaScript 🚀
-
InfluxDB
Power Real-Time Data Analytics at Scale. Get real-time insights from all types of time series data with InfluxDB. Ingest, query, and analyze billions of data points in real-time with unbounded cardinality.
Another option is to clone the starter repo from GitHub. Note that to install the JavaScript flavor of the starter project, we can clone this repo, but you’ll need Babel to compile vanilla JavaScript).
Another option is to clone the starter repo from GitHub. Note that to install the JavaScript flavor of the starter project, we can clone this repo, but you’ll need Babel to compile vanilla JavaScript).
import { defineConfig } from 'vite'; import { VitePluginNode } from 'vite-plugin-node'; export default defineConfig({ // ...vite configures server: { // vite server configs, for details see \[vite doc\](https://vitejs.dev/config/#server-host) port: 3000 }, plugins: [ ...VitePluginNode({ // Nodejs native Request adapter // currently this plugin support 'express', 'nest', 'koa' and 'fastify' out of box, // you can also pass a function if you are using other frameworks, see Custom Adapter section adapter: 'nest', // tell the plugin where is your project entry appPath: './src/main.ts', // Optional, default: 'viteNodeApp' // the name of named export of you app from the appPath file exportName: 'viteNodeApp', // Optional, default: 'esbuild' // The TypeScript compiler you want to use // by default this plugin is using vite default ts compiler which is esbuild // 'swc' compiler is supported to use as well for frameworks // like Nestjs (esbuild dont support 'emitDecoratorMetadata' yet) // you need to INSTALL `@swc/core` as dev dependency if you want to use swc tsCompiler: 'esbuild', }) ], optimizeDeps: { // Vite does not work well with optionnal dependencies, // mark them as ignored for now exclude: [ '@nestjs/microservices', '@nestjs/websockets', 'cache-manager', 'class-transformer', 'class-validator', 'fastify-swagger', ], }, });
Make sure you have the latest Node.js version installed on your machine (except v13, which is not supported).
One of the advantages of using the Vite plugin (vite-plugin-node) is that we can choose to use either esbuild or swc to compile our TypeScript files, though we used only esbuild in this post.
The vite build command bundles our code with Rollup and spits out highly optimized assets for our production environment. When we build our app with Vite by running the npm run build command after the entire setup, we can see the output below.
Vite works by first dividing the modules in an application into two categories, dependencies and source code, because dependencies rarely change during development. Vite pre-bundles these dependencies using esbuild under the hood. For source code that might need transforming (CSS, JSX, etc.), Vite serves them over native ESM to the browser.