Angular2 本地开发中的慢速自动页面刷新 - Windows.

Angular2 slow auto page refresh in local development - Windows

本文关键字:刷新 Windows 开发 Angular2      更新时间:2023-09-26

我是 angular2 的新手,并遵循文档中的英雄教程。我正在经历 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,而在于Windows/Antivirus .js因为它们由于所谓的安全措施而减慢了节点速度。

溶液

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

终极解决方案

性能和节点模块未安装的持续问题迫使我完全放弃Windows。我转向 mac、node 和 angular 开发体验的那一天要好得多,区别就像黑夜和阳光明媚的宽泛日子。

更多详情

阅读这个优秀的答案以获取更多详细信息。

您也可以尝试让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",
    

你可以运行项目添加 --aot 参数,例如

ng serve --aot