简体   繁体   English

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

[英]Angular2 slow auto page refresh in local development - Windows

I am new to angular2 and following the heros tutorial from docs. 我是新来angular2和之后的英雄从文档教程。 I am experiencing quite slow development experience with angular2. 我在使用angular2时遇到了相当慢的开发经验。 It takes about 5 secs for angular2 to detect changes in file, and then next 30-40 seconds to reload the page. 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)

Although this time may seems not significant but when I have to make regular changes and check output, it starts to add up. 虽然这个时间似乎并不重要但是当我必须定期更改并检查输出时,它开始累加起来。

Any suggestions why angular2 is slow in development..?? 有什么建议为什么angular2在开发中很慢.. ??

Problem 问题

The problem was not with angular2, rather it was with Windows/Antivirus as they were slowing down node.js due to their so-called security measures. 问题不在于angular2,而是与Windows / Antivirus有关,因为他们因为所谓的安全措施而放慢了node.js的速度。

Solution

  • Disable realtime protection from windows defender (or any other antivirus), as it slows down node.js 禁用windows defender(或任何其他防病毒软件)的实时防护,因为它会降低node.js的速度
  • Run console (or gitbash if you use that) as an administrator 以管理员身份运行控制台(或gitbash,如果您使用它)
  • Use SSD drive 使用SSD驱动器

Ultimate Solution 终极解决方案

The constant problems of performance and node modules not being installed, forced me to completely ditch Windows . 性能和节点模块的不断安装问题,迫使我彻底抛弃Windows And the day I shifted to mac, node and angular development experience was WAY better, the difference was like dark-night and full-sunny-shiny-broady-day. 我转移到Mac上,节点和角度开发经验的一天是更好的方式 ,所不同的是喜欢黑暗的夜和全阳光明媚闪亮-布罗迪天。

More details 更多细节

Read this excellent answer to get more details. 阅读这个优秀的答案,以获得更多细节。

You can also try to have lite-server not monitor your node_modules directory. 您还可以尝试让lite-server不监视您的node_modules目录。 See here for config instructions: https://github.com/johnpapa/lite-server 请参阅此处获取配置说明: https//github.com/johnpapa/lite-server

  • Add a bs-config.json to your project and specify files to watch for a reload bs-config.json添加到项目中,并指定要监视重新加载的文件

     { "port": 8000, "files": ["./app/**/*.{html,htm,css,js}", "./*.{html,css,js,json}"], "server": { "baseDir": "./" } } 
  • Add the config file to your startup in packages.json 将配置文件添加到packages.json的启动

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

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

ng serve --aot

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM