Angular 18+ 高级教程 – Angular CLI
前言
这篇会列出我开发中常用的 command. 并给予一些简单的说明
Command Format
先了解一下几个简单的 command 格式:
-
缩写 shortform
这个是完整版
ng generate component my-component
这个是 shortform 版
ng g c my-component
generate 变成了 g,component 变成了 c,很多 command 都有 shortform 的哦。
-
Parameter
ng generate component --inline-style=true
-- 代表这是个参数,参数是 key value pair
-
Boolean parameter default value
ng generate component --inline-style
boolean 没有赋值表示 true
-
Parameter = vs space
ng generate component --inline-style false
不用 = 用 space 也可以,我比较喜欢 space。
-
Parameter shortform
完整版本
ng generate component --inline-style false
shortform 版
ng g c -s false
inline-style 变成了 s
-- 也变成了 - 哦
查看当前版本
ng version
升级项目/CLI
升级 Global CLI
npm uninstall -g @angular/cli npm install -g @angular/cli@latest // 升级到稳定版本 npm install -g @angular/cli@next // 升级到 preview 版本
升级项目
ng update // 查看最新稳定版 ng update --next // 查看最新 preview 版 ng update @angular/cli @angular/core --next // 更新指定 package 到最新 preview 版本
创建项目
ng new my-app
options
--routing // 包含 router --style=scss // 使用 Scss --standalone // 默认创建 standalone 组件 (without NgModule) --skip-tests // 不包含单元测试
创建组件
ng g c my-component // 创建组件 into module ng g c my-component --standalone false -m my-module // 创建组件 into path and module ng g c my-module/my-component --standalone false -m my-module
创建管道 Pipe
ng g p my-pipe
创建 Service
ng g s my-service
Build Production
ng build
如果想检查 build 出来的代码,可以把 uglify 关掉
ng build --optimization=false
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】凌霞软件回馈社区,博客园 & 1Panel & Halo 联合会员上线
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】博客园社区专享云产品让利特惠,阿里云新客6.5折上折
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 在鹅厂做java开发是什么体验
· 百万级群聊的设计实践
· WPF到Web的无缝过渡:英雄联盟客户端的OpenSilver迁移实战
· 永远不要相信用户的输入:从 SQL 注入攻防看输入验证的重要性
· 浏览器原生「磁吸」效果!Anchor Positioning 锚点定位神器解析
2021-04-04 Angular 学习笔记 (Typescript 版本更新)