We would like to configure vite settings in Angular 17 via a vite.config.js file or some other way. Specifically, these settings:
export default {
optimizeDeps: {
disabled: false,
exclude: [
'my-third-party-package',
],
},
}
Things I have tried but yielded no results:
ng ejectvite.config.js in the root folder and "hoping" Angular picks it up at build time.Probably when you serve the app with the new Angular build system, you will have an error like this:
typeError: Failed to fetch dynamically imported module
This is because some dependencies are not optimized for Vite.
In order to fix this you must set optimizeDeps on your vite.config.js but it is not possible in Angular.
See https://github.com/angular/angular-cli/issues/26859
I found the next solution:
Inside angular.json disable cli cache:
"cli": {
"cache": {
"enabled": false,
}
}
See https://github.com/angular/angular-cli/issues/26345
Angular documentation provides a way to exclude dependenies from optimization/bundling by Vite using prebundle options in serve task configuration. Example:
"serve": {
"builder": "@angular/build:dev-server",
"configurations": {
"production": {
"buildTarget": "sapphire-manager-ui:build:production"
},
"development": {
"buildTarget": "sapphire-manager-ui:build:development"
}
},
"options": {
"prebundle": {
"exclude": ["tsyringe", "zod", "nanoid"]
}
},
"defaultConfiguration": "development"
},
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With