How to set custom vite config settings in Angular 17?
Asked Answered
S

1

11

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:

Sitnik answered 9/1, 2024 at 8:31 Comment(4)
The vite config is internal to the CLI and cannot be modified.Zhao
I created a feature request on github github.com/angular/angular/issues/53897Oahu
The request is closed. So how to config vite now?Disturbance
Your best bet is to use a custom builder if you must configure vite.Sitnik
M
4

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

Mccallion answered 23/2, 2024 at 22:1 Comment(1)
This is the reason I was trying to change the vite config. I disalbed cli cache in angular.json as the alternative suggested and it workedArcanum

© 2022 - 2025 — McMap. All rights reserved.