![]() |
VOOZH | about |
Vite is a modern build tool that dramatically enhances the development experience of front-end systems. Originally developed for Vue.js, Vite has gained a reputation for speed and performance. This article will explore how to integrate Vite and Angular using Vite’s fast development server and effective bundling capabilities.
These are the following ways to use Vite with Angular:
This approach utilizes the Angular CLI to create an Angular project, followed by integrating Vite for development and production builds.
ng new my-angular-vite-appcd my-angular-vite-app
npm install vite --save-dev
Create a file named vite.config.js in the root of your project with the following content:
import { defineConfig } from 'vite';
import angular from 'vite-plugin-angular';
export default defineConfig({
plugins: [angular()],
server: {
port: 4200,
},
});
"scripts": {
"start": "ng serve",
"build": "ng build",
"vite": "vite"
}
Output: Run the application using:
npm run viteNote: You will see the output in the browser at http://localhost:4200.
This approach is useful for developers looking to transition an existing Angular application to use Vite for improved performance.
cd existing-angular-appnpm install vite --save-devimport { defineConfig } from 'vite';
import angular from 'vite-plugin-angular';
export default defineConfig({
plugins: [angular()],
server: {
port: 4200,
},
});
"scripts": {
"start": "vite"
}
Output: Run the application using:
npm startNote: The application will now run using Vite's development server, making it faster and more efficient.
Integrating Vite and Angular can dramatically improve your development experience, providing faster builds and more efficient workflows. Whether you are starting a new project or migrating an existing one, Vite is a powerful tool that can optimize your Angular application.