📜  Angular CLI-ng serve命令

📅  最后修改于: 2020-10-27 02:41:28             🧑  作者: Mango


句法

ng serve  [options]
ng s  [options]

ng serve命令构建并服务于应用程序。如果发生更改,它将重建应用程序。这里project是angular.json中定义的应用程序的名称。选项是可选参数。

争论

Sr.No. Argument & Syntax Description
1 The name of the project to build. Can be an application or a library.

选件

Sr.No. Option & Syntax Description
1 –allowedHosts Whitelist of hosts that are allowed to access the dev server.
2 –aot=true|false Build using Ahead of Time compilation.
3 –baseHref=baseHref Base url for the application being built.
4 –buildEventLog=buildEventLog EXPERIMENTAL Output file path for Build Event Protocol events
5 –commonChunk=true|false Use a separate bundle containing code used across multiple bundles.
6 –configuration=configuration

A named build target, as specified in the “configurations” section of angular.json. Each named target is accompanied by a configuration of option defaults for that target. Setting this explicitly overrides the “–prod” flag.

Aliases: -c

7 –deployUrl=deployUrl URL where files will be deployed.
8 –disableHostCheck=true|false

Don’t verify connected clients are part of allowed hosts.

Default: false

9 –help=true|false|json|JSON

Shows a help message for this command in the console.

Default: false

10 –hmr=true|false

Enable hot module replacement.

Default: false

11 –hmrWarning=true|false

Show a warning when the –hmr option is enabled.

Default: true

12 –host=host

Host to listen on.

Default: localhost

13 –liveReload=true|false

Whether to reload the page on change, using live-reload.

Default: true

14 –open=true|false

Opens the url in default browser.

Default: false

Aliases: -o

15 –optimization=true|false Enables optimization of the build output.
16 –poll Enable and define the file watching poll time period in milliseconds.
17 –port

Port to listen on.

Default: 4200

18 –prod=true|false Shorthand for “–configuration=production”. When true, sets the build configuration to the production target. By default, the production target is set up in the workspace configuration such that all builds make use of bundling, limited tree-shaking, and also limited dead code elimination.
19 –progress=true|false Log progress to the console while building.
20 –proxyConfig=proxyConfig Proxy configuration file.
21 –publicHost=publicHost The URL that the browser client (or live-reload client, if enabled) should use to connect to the development server. Use for a complex dev server setup, such as one with reverse proxies.
22 –servePath=servePath The pathname where the app will be served.
23 –servePathDefaultWarning=true|false

Show a warning when deploy-url/base-href use unsupported serve path values.

Default: true

24 –sourceMap=true|false Output sourcemaps.
25 –ssl=true|false

Serve using HTTPS.

Default: false

26 –sslCert=sslCert SSL certificate to use for serving HTTPS.
27 –sslKey=sslKey SSL key to use for serving HTTPS.
28 –vendorChunk=true|false Use a separate bundle containing only vendor libraries.
29 –verbose=true|false Adds more details to output logging.
30 –watch=true|false

Rebuild on change.

Default: true

首先移至使用ng build命令更新的角度项目,然后运行该命令。

\>Node\>TutorialsPoint> ng serve
chunk {main} main.js, main.js.map (main) 14.3 kB [initial] [rendered]
chunk {polyfills} polyfills.js, polyfills.js.map (polyfills) 141 kB [initial] [rendered]
chunk {runtime} runtime.js, runtime.js.map (runtime) 6.15 kB [entry] [rendered]
chunk {styles} styles.js, styles.js.map (styles) 12.4 kB [initial] [rendered]
chunk {vendor} vendor.js, vendor.js.map (vendor) 3 MB [initial] [rendered]
Date: 2020-06-04T04:01:47.562Z - Hash: a90c5fc750c475cdc4d1 - Time: 10164ms
** Angular Live Development Server is listening on localhost:4200, open your browser on http://localhost:4200/ **
: Compiled successfully.

此处的ng serve命令已成功构建并服务我们的项目TutorialsPoint。现在在浏览器窗口中打开http:// localhost:4200并验证输出。

输出