【问题标题】:Angular build files not bundling in dist folder角度构建文件未捆绑在 dist 文件夹中
【发布时间】:2018-06-25 22:07:17
【问题描述】:

我最近将我的 Angular 4 项目升级到 Angular 5,然后是 Angular 6。之前,什么时候运行:

ng build --prod --build-optimizer --aot

Angular 会在dist 文件夹中创建一些捆绑文件,例如vendor.fa30abf0a6e84604aa92.bundle.js。然而,现在,在我运行相同的命令后,我在 dist 文件夹中得到了一堆似乎未优化的文件:

3rdpartylicenses.txt     fontawesome-webfont.ttf    main.js           runtime.js.map          Simple-Line-Icons.woff2  views-dashboard-dashboard-module-ngfactory.js
assets                   fontawesome-webfont.woff   main.js.map       Simple-Line-Icons.eot   styles.js                views-dashboard-dashboard-module-ngfactory.js.map
favicon.ico              fontawesome-webfont.woff2  polyfills.js      Simple-Line-Icons.svg   styles.js.map
fontawesome-webfont.eot  index.html                 polyfills.js.map  Simple-Line-Icons.ttf   vendor.js
fontawesome-webfont.svg  logo.png                   runtime.js        Simple-Line-Icons.woff  vendor.js.map

这些文件很大,使我的网站加载非常缓慢。仅下载 vendor.js 就需要 10 多秒。任何想法我做错了什么?

【问题讨论】:

  • 只运行ng build --prod会得到同样的结果吗?
  • 是的,相同的文件。
  • 你在使用 Angular CLI 吗?如果有,是什么版本?如果是 6+,打开 angular.json 并找到 configurations 部分并确保 aotbuildOptimizer 设置都设置为 true。
  • 在 package.json 中:"@angular/cli": "^6.0.7"。在 angular.json 中,我没有看到任何一个选项!我猜这是我从 Angular 4 升级时应该添加的东西?
  • 如果您使用ng update 升级,那么它应该已经为您添加到文件中。将它们添加到此路径的 angular.json 文件中:projects/your-project/achitect/build/configurations/production。看看有没有帮助。

标签: javascript angular build command-line-interface bundle


【解决方案1】:

感谢 R Richards 的提示。我可以通过手动删除angular.json 来解决这个问题,然后运行:

yarn global add @angular/cli
yarn add @angular/cli
ng update @angular/cli

【讨论】:

    猜你喜欢
    • 2019-10-30
    • 1970-01-01
    • 2017-01-09
    • 1970-01-01
    • 1970-01-01
    • 2019-02-28
    • 1970-01-01
    • 1970-01-01
    • 2020-01-19
    相关资源
    最近更新 更多