吃好喝好睡觉 發表於 2019-10-22 11:36:00

angular常用命令整理

<style>body { font-family: "Merriweather", serif; margin: 0; padding: 0; color: rgba(58, 58, 58, 1); line-height: 1.7; background-color: rgba(248, 248, 248, 1) }
h1, h2, h3 { color: rgba(53, 68, 88, 1); font-weight: 700 }
a { color: rgba(52, 152, 219, 1); text-decoration: none }
a:hover { text-decoration: underline }
pre { margin-top: 4px; background-color: rgba(240, 240, 240, 1); padding: 12px; border-radius: 4px; overflow: auto; font-family: "Courier New", monospace }
ul { list-style-type: none; padding-left: 0 }
#cnblogs_post_body ul { margin-left: 8px }
#cnblogs_post_body ul li { list-style-type: none }
li { margin-bottom: 15px }
p.note { color: rgba(192, 57, 43, 1); font-style: italic; margin-top: 5px }
.content { max-width: 800px; margin: 40px auto; padding: 20px; background-color: rgba(255, 255, 255, 1); border-radius: 5px; box-shadow: 0 2px 5px rgba(0, 0, 0, 0.05) }
.title { color: rgba(51, 51, 51, 1); text-align: center; margin: 40px 0 }
.note2 { color: rgba(0, 128, 0, 1) }</style>
#### 1. 创建项目 ng new
<pre>命令: ng new &lt;project-name&gt;
描述: 创建一个新的 Angular 项目,默认在当前所在目录下

参数:
--dry-run -d                只输出要创建的文件和执行的操作,实际上并没有创建项目
--verbose -v                输出详细信息
--skip-npm                  在项目第一次创建时不执行任何npm命令
--name                      指定创建项目的名称
</pre>
#### 2. 创建控件 ng g component
<pre>命令: ng generate &lt;type&gt;
      ng g &lt;type&gt;
描述: 在项目中构建新代码

支持的类型:
Component                ng g component my-new-component
Directive                ng g directive my-new-directive
Pipe                     ng g pipe my-new-pipe
Service                  ng g service my-new-service
Class                  ng g class my-new-class
Interface                ng g interface my-new-interface
Enum                     ng g enum my-new-enum
Module                   ng g module my-module
Route                  ng g route my-route (当前已禁用)

构建的组件都会使用自用目录,除非 --flat 单独指定.

参数:
--flat                  不在自用目录内创建代码
--route=&lt;route&gt;            指定父路由.仅用于生成组件和路由.默认为指定的路径.
--skip-router-generation跳过生成父路由配置。只能用于路由命令。
--default               指定路由应为默认路由。
--lazy                  指定路由是延迟的。 默认为true。
</pre>
#### 3. 查看版本 ng version
<pre>命令: ng version
描述: 输出cli版本, node 版本和操作系统信息

参数:
--watch 继续运行测试. 默认为true
</pre>
#### 4. 启动运行 ng serve
<pre>ng new PROJECT_NAME
cd PROJECT_NAME
ng serve

描述: 将会自动在浏览器中打开默认地址 http://localhost:4200/. 运行之后如果你修改了程序源代码.应用将会自动重载.

自定义配置:
ng serve --host 0.0.0.0 --port 4201 --live-reload-port 49153
</pre>
#### 5. 打包编译 ng build
<pre>描述: 构建工件将存储在/dist目录中。

ng build可以指定构建目标(--target = production或--target = development)和要与该构建一起使用的环境文件(--environment = dev或--environment = prod)。 默认情况下,使用开发构建目标和环境。

# 这是生产构建
ng build --target=production --environment=prod
ng build --prod --env=prod
ng build --prod
# 这是开发构建
ng build --target=development --environment=dev
ng build --dev --e=dev
ng build --dev
ng build
</pre><br><br>
来源:https://www.cnblogs.com/anans/p/11718846.html
頁: [1]
查看完整版本: angular常用命令整理