Angular vite 优化

问题描述 投票:0回答:1

404(未找到)错误

优化 deps 目录中的路径 >/.angular/cache/18.1.4/vite/deps/browser-VFYTEBP2.js?v=ef5c984d" 不存在该文件。该依赖项可能与 dep 优化器不兼容尝试将其添加到

optimizeDeps.exclude

enter image description here

我调试的时候,在Vite文档中找到了以下内容

https://vitejs.dev/config/dep-optimization-options.html#optimizedeps-exclude

   export default defineConfig({
    optimizeDeps: {
      include: ['esm-dep > cjs-dep'],
    },
   })

我应该在 Angular 项目中的哪里添加它才能生效

package.json

"ng": "ng",
"start": "ng serve",
"build": "ng build",
"watch": "ng build --watch --configuration development",
"test": "ng test"



"@angular/animations": "^18.1.4",
"@angular/cdk": "^18.1.4",
"@angular/common": "^18.1.4",
"@angular/compiler": "^18.1.4",
"@angular/core": "^18.1.4",
"@angular/forms": "^18.1.4",
"@angular/material": "^18.1.4",
"@angular/platform-browser": "^18.1.4",
"@angular/platform-browser-dynamic": "^18.1.4",
"@angular/router": "^18.1.4",

角度.json

       "optimization": {
            "scripts": true,
            "styles": {
              "minify": true,
              "inlineCritical": false
            },
            "fonts": true
          }
angular optimization vite
1个回答
0
投票

我有一个类似的错误,但在 React 项目中,我通过运行以下命令解决了它:

rm -rf node_modules/.vite

这个命令会清除Vite的缓存,之后我重新启动开发服务器就可以正常工作了

© www.soinside.com 2019 - 2024. All rights reserved.