- Published on
The comparison of Vite build, SWC, and TSC in NestJS
- Authors
- Name
- Khánh
Purpose
- To choose the best ways to implement NestJS builder tools
Preparing
- Start nestjs project by command:
nest new nest-swc-test
- Implement build with swc:
npm i --save-dev @swc/cli @swc/core
# this step will be run after build with the default tool
# Add builder swc in nest-cli.json file
{
"compilerOptions": {
"builder": "swc"
}
}
- Implement with vite
npm install --save-dev vite @vitejs/plugin-vue @vitejs/plugin-react
# create a 'vite.config.js' file in the root of project
import { defineConfig } from 'vite';
import vue from '@vitejs/plugin-vue';
import react from '@vitejs/plugin-react';
export default defineConfig({
plugins: [vue(), react()],
build: {
rollupOptions: {
input: 'src/main.ts',
output: {
dir: 'dist',
format: 'cjs',
},
},
},
});
# add this script in package.json file
"build:vite": "vite build"
# command to build with vite
npm run build:vite
Build time
1. build with tsc (default of nestjs)
time npm run build
2. build with swc
- notice that add builder: swc in the nest-cli.json file before run this command
time npm run build
3. build with vite
time npm run build:vite
Conclusions
- Using SWC help for build faster than tsc and vite
- With this benefit, SWC can be use in development process (run code faster)
- More information about SWC