美文网首页
Angular 命令速查

Angular 命令速查

作者: 一梦欧巴 | 来源:发表于2017-11-02 19:44 被阅读0次

    命令列表

    名称作用

    ng init在当前目录下创建应用

    ng new创建新的目录并在新目录下运行ng init命令

    ng serve启动

    ng doc在浏览器中打开Angular文档并搜索当前关键字

    ng e2e使用 protractor 在当前应用中运行e2e测试

    ng format使用 clang-format 格式化当前项目代码

    ng generate在项目中构建新代码

    ng gng generate的简写

    ng build构建项目

    ng github-pages:deploy [options]将项目部署到GitHub Pages

    ng version输出cli版本, node 版本和操作系统信息

    ng set设置环境

    任何指令后面都可以加--help以查看帮助

    ng new

    参数名类型默认值作用

    --dry-runbooleanfalse只输出要创建的文件和执行的操作,实际上并没有创建项目

    --verbosebooleanfalse输出详细信息

    --link-clibooleanfalse自动连接到angular-cli包

    --skip-installbooleanfalse在项目第一次创建时不执行npm install

    --skip-bowerbooleantrue不安装bower

    --skip-gitbooleanfalse不执行Git repository初始化工作

    --directorystring目录名默认与项目名称一样

    --source-dirstring'src'源文件目录名

    --stylestring'css'使用 ('css', 'less' 还是 'scss')编写css

    --prefixstring'app'生成新组件的前缀

    --mobilebooleanfalse生成 Progressive Web App (PWA)项目

    --routingbooleanfalse添加带路由的模块(module)并import到main app module中

    --inline-stylebooleanfalse生成新应用的时候使用inline styles(内联,不生成单独的css文件)方式

    --inline-templatebooleanfalse生成新应用的时候使用 inline templates(内联,不生成单独的html文件)方式

    --ng4无无使用Angular4的依赖创建空项目,现在默认已经是4的版本了

    ng serve

    参数名类型默认值作用

    --hoststring12.0.0.1自定义配置 IP

    --disable-host-check----跟在--host后面,允许使用localhost以外的host打开项目

    --portnumber4200自定义端口号

    --live-reload-portnumber4200时时重载端口号

    --hmr----热替换

    ng generate支持的类型

    名称示例

    Componentng g component my-new-component

    Directiveng g directive my-new-directive

    Pipeng g pipe my-new-pipe

    Serviceng g service my-new-service

    Classng g class my-new-class

    Interfaceng g interface my-new-interface

    Enumng g enum my-new-enum

    Moduleng g module my-module

    Routeng g route my-route 当前已禁用

    命令参数

    ng generate class

    参数名类型默认值作用

    --specbooleanfalse生成对应的单元测试文件

    ng generate component

    参数名类型默认值作用

    --flatbooleanfalse在src/app中生成component文件,而不是在当前目录下

    --inline-templatebooleanfalse使用inline template,而不是独立的HTML文件

    --inline-stylebooleanfalse使用inline styles,而不是独立的CSS文件

    --prefixbooleantrue使用在angular-cli.json指定的前缀来生成component selector(前缀表示selector的第一个单词)

    --specbooleantrue生成对应的单元测试文件

    ng generate directive

    参数名类型默认值作用

    --flatbooleanfalse在src/app中生成component文件,而不是在当前目录下

    --prefixbooleantrue默认true, 使用在angular-cli.json指定的前缀来生成component selector(前缀表示selector的第一个单词)

    --specbooleantrue生成对应的单元测试文件

    ng generate module

    参数名类型默认值作用

    --routingbooleanfalse新增一个与module对应的路由模块,并import到module中

    --specbooleanfalse用于检测模块是否存在

    ng generate service

    参数名类型默认值作用

    --flatbooleantrue在src/app中生成component文件,而不是在当前目录下

    --specbooleantrue生成单元测试文件

    ng build

    参数名类型默认值作用

    --aotstring无预编译

    --base-hrefstring‘/’设置index.html文件中的base href参数

    --environmentstringdev在哪个环境中使用,prod代表生成环境

    --output-pathstringdist文件输出目标路径

    --targetstringdevelopmentdevelopment:默认值,不压缩混淆,production:压缩混淆代码

    --watchbooleanfalse在哪个环境中使用

    ng github-pages:deploy

    参数名类型默认值作用

    --messagestring无构建的时候提交的message,必须写在引号中

    --targetstringdevelopment使用的环境

    --user-pagebooleanfalse是否以user/org页面部署到GitHub上

    --skip-buildbooleanfalse跳过构建直接部署

    --gh-tokenstring无使用Github的token

    --gh-usernamestring无使用Github用户名

    --base-hrefstring'/'在index.html文件中使用的base href值

    ng set

    参数名类型默认值作用

    --global--无是否设置全局

    packageManagerstring无可设置为npm\cnpm\yarn

    更多命令参数,可参考官网:https://github.com/angular/angular-cli/wiki

    作者:偶尔装沉默

    链接:http://www.jianshu.com/p/384cc631f0fa

    來源:简书

    著作权归作者所有。商业转载请联系作者获得授权,非商业转载请注明出处。

    相关文章

      网友评论

          本文标题:Angular 命令速查

          本文链接:https://www.haomeiwen.com/subject/ayuapxtx.html