【问题标题】:Angular2 slow auto page refresh in local development - Windows本地开发中的Angular2慢速自动页面刷新 - Windows
【发布时间】:2016-05-17 06:50:25
【问题描述】:

我是 angular2 的新手,并遵循文档中的 heros 教程。我在使用 angular2 时遇到了相当缓慢的开发体验。 angular2 大约需要 5 秒来检测文件中的更改,然后在接下来的 30-40 秒内重新加载页面。

[0] 8:08:12 PM - File change detected. Starting incremental compilation...
[0] app/hero-detail.component.ts(2,8): error TS1192: Module '"app/app.component"' has no default export.
[0] 8:08:16 PM - Compilation complete. Watching for file changes.
[1][BS] File changed: app\app.component.js
[1] [BS] File changed: app\hero-detail.component.js
[1] [BS] File changed: app\main.js
[1] 16.02.07 20:08:39 304 GET /./index.html (Unknown - 8551ms)
[1] 16.02.07 20:08:45 304 GET /./index.html (Unknown - 1145ms)
[1] 16.02.07 20:08:45 304 GET /node_modules/es6-shim/es6-shim.min.js (Unknown - 384ms)
[1] 16.02.07 20:08:45 304 GET /node_modules/systemjs/dist/system-polyfills.js (Unknown - 393ms)
[1] 16.02.07 20:08:45 304 GET /node_modules/angular2/bundles/angular2-polyfills.js (Unknown - 399ms)
[1] 16.02.07 20:08:46 304 GET /node_modules/systemjs/dist/system.src.js (Unknown - 906ms)
[1] 16.02.07 20:08:46 304 GET /node_modules/rxjs/bundles/Rx.js (Unknown - 911ms)
[1] 16.02.07 20:08:47 304 GET /node_modules/es6-shim/es6-shim.min.js (Unknown - 962ms)
[1] 16.02.07 20:08:47 304 GET /node_modules/systemjs/dist/system-polyfills.js (Unknown - 967ms)
[1] 16.02.07 20:08:47 304 GET /node_modules/angular2/bundles/angular2.dev.js (Unknown - 972ms)
[1] 16.02.07 20:08:47 304 GET /node_modules/angular2/bundles/angular2-polyfills.js (Unknown - 977ms)
[1] 16.02.07 20:08:48 304 GET /node_modules/systemjs/dist/system.src.js (Unknown - 1429ms)
[1] 16.02.07 20:08:48 304 GET /node_modules/rxjs/bundles/Rx.js (Unknown - 1431ms)

虽然这个时间可能看起来并不重要,但是当我必须定期更改并检查输出时,它开始累加。

关于 angular2 开发缓慢的任何建议..??

【问题讨论】:

  • 有人否决我的问题的任何理由...???我正在开发 angular2 应用程序并且在开发过程中性能太慢,并且想要一种方法来加快它......

标签: javascript node.js typescript angular


【解决方案1】:

问题

问题不在于 angular2,而在于 Windows/Antivirus,因为它们由于所谓的安全措施而减慢了 node.js。

解决方案

  • 禁用 Windows Defender(或任何其他防病毒软件)的实时保护,因为它会变慢 节点.js
  • 以管理员身份运行控制台(或 gitbash,如果您使用它)
  • 使用 SSD 驱动器

终极解决方案

性能和节点模块未安装的持续问题迫使我完全放弃 Windows。而在我转向 mac 的那一天,node 和 Angular 开发体验WAY更好了,区别就像是黑夜和阳光灿烂的大白天。

更多详情

阅读此excellent answer 了解更多详情。

【讨论】:

  • 放弃窗户显然可以解决所有问题。它让我的妻子回来了。
【解决方案2】:

您也可以尝试让lite-server 不监视您的node_modules 目录。有关配置说明,请参见此处:https://github.com/johnpapa/lite-server

  • bs-config.json 添加到您的项目并指定要监视重新加载的文件

    {
    "port": 8000,
    "files": ["./app/**/*.{html,htm,css,js}", "./*.{html,css,js,json}"],
    "server": { "baseDir": "./" }
    }
    
  • 将配置文件添加到packages.json的启动中

    {
      ...
      "scripts": {
        ...
        "lite": "lite-server -c bs-config.json",
    

【讨论】:

    【解决方案3】:

    可以运行project add --aot param,比如

    ng serve --aot
    

    【讨论】:

      猜你喜欢
      • 2017-11-22
      • 1970-01-01
      • 2017-04-13
      • 1970-01-01
      • 2012-07-21
      • 1970-01-01
      • 1970-01-01
      • 2017-03-26
      相关资源
      最近更新 更多