如何使用angular-CLI

时间:2016-12-09 09:21:39

标签: angular angular-cli

我使用angular-cli作为webpack。

  

ng serve

并且构建成功,我看到了

  

** NG Live Development Server正在http://localhost:4200上运行。 **
  哈希:dd30d5aeee6e21802b4d e时间:9397ms
  chunk {0} styles.bundle.js,styles.bundle.map(styles)163 kB {4} [initial] [rendered]
  chunk {1} main.bundle.js,main.bundle.map(main)6.52 kB {3} [initial] [rendered]
  chunk {2} scripts.bundle.js,scripts.bundle.map(scripts)361 kB {4} [initial] [rendered]
  chunk {3} vendor.bundle.js,vendor.bundle.map(vendor)2.22 MB [initial] [rendered]
  chunk {4} inline.bundle.js,inline.bundle.map(内联)0字节[entry] [rendering]
  webpack:bundle现在是VALID。

似乎没有错。但是当我访问http://localhost:4200时,我在控制台上看不到任何日志。无论如何我可以打开服务器登录控制台吗?

5 个答案:

答案 0 :(得分:4)

您无法将角度代码记录到以ng serve开头的shell,抱歉: - (

您只会在该控制台中看到构建错误

答案 1 :(得分:1)

您需要在Google Chrome浏览器的控制台窗口中更改过滤器,然后您才能看到您在console.log()方法中编写的消息。 enter image description here

答案 2 :(得分:1)

虽然您无法在控制台中记录不会导致服务器请求的dom / web事件,但您可以通过传递--verbose标志来增加编译过程和静态Web服务器提供的信息量。启动:ng serve --verbose

此外,如果您正在运行代理服务器以访问本地API服务器,并且您想要更多关于如何代理这些请求的日志记录,则可以增加代理配置中的logLevel

示例proxy.conf.json { "/api": { "target": "http://localhost:3001", "secure": false, "logLevel": "debug" } }

然后您将以ng serve --proxy-config proxy.conf.json --verbose启动服务器。

答案 3 :(得分:1)

您还可以安装并运行其他服务器。可以通过npm安装一个简单的使用方法:

npm install spa-http-server

如果使用路由,则可能要使用spa-http-server

{{1}}

答案 4 :(得分:0)

当我执行 console.log(“某事”)时,日志会出现在浏览器检查器控制台选项卡中。我不需要任何配置。