【问题标题】:What does --minimal do in angular-cli `ng new`?--minimal 在 angular-cli `ng new` 中有什么作用?
【发布时间】:2018-01-07 19:32:37
【问题描述】:

Angular CLI 有一个名为--minimal 的选项。它有什么作用,它记录在哪里?命令ng help new 很少提及它

--minimal (Boolean) (Default: false) Should create a minimal app.
  aliases: --minimal

【问题讨论】:

  • 截至 2018 年 6 月 13 日 --minimal does nothing at all
  • 使用 ng new PROJECT_NAME --skip-tests、--inline-style 和 --inline-template 创建一个最小的 repo
  • 使用 Angular cli 7.0.7,--minimal 又回来了,这意味着 Create a barebones project without any testing frameworks

标签: angular-cli


【解决方案1】:

截至 2017 年 7 月 31 日 常规 Angular 应用会生成 5 个目录、26 个文件。 --minimal 生成 4 directories, 13 files。区别? --minimal 通过启用其他一些选项来排除多个文件的生成。

  • 你可以在code here看到这个
    • --skip-tests:停止生成测试(即 e2e、karma.conf.jsprotractor.conf.js*.spec. 文件),包括 tsconfig.spec.jsonapp.component.spec.ts
    • --inline-style:停止生成外部 css 存根,而是在 .ts 文件中保留一个空字符串。
    • --inline-template:停止生成外部 html,而是将其保存在 .ts 文件中的 template 变量中。
  • 停止生成以下文件,code here
    • README.md
    • tsconfig 和 tslint
    • favicon.ico

这里是没有--minimal的例子

my-app/
├── e2e
│   ├── app.e2e-spec.ts
│   ├── app.po.ts
│   └── tsconfig.e2e.json
├── karma.conf.js
├── package.json
├── package-lock.json
├── protractor.conf.js
├── README.md
├── src
│   ├── app
│   │   ├── app.component.css
│   │   ├── app.component.html
│   │   ├── app.component.spec.ts
│   │   ├── app.component.ts
│   │   └── app.module.ts
│   ├── assets
│   ├── environments
│   │   ├── environment.prod.ts
│   │   └── environment.ts
│   ├── favicon.ico
│   ├── index.html
│   ├── main.ts
│   ├── polyfills.ts
│   ├── styles.css
│   ├── test.ts
│   ├── tsconfig.app.json
│   ├── tsconfig.spec.json
│   └── typings.d.ts
├── tsconfig.json
└── tslint.json

--minimal 执行以下操作

├── package.json
├── package-lock.json
├── src
│   ├── app
│   │   ├── app.component.ts
│   │   └── app.module.ts
│   ├── assets
│   ├── environments
│   │   ├── environment.prod.ts
│   │   └── environment.ts
│   ├── index.html
│   ├── main.ts
│   ├── polyfills.ts
│   ├── styles.css
│   ├── tsconfig.app.json
│   └── typings.d.ts
└── tsconfig.json

【讨论】:

    【解决方案2】:

    目前截至 2018 年 12 月,在 Angular cli 7.0.7 中,已添加了最小选项。这意味着Create a barebones project without any testing frameworks

    您可以查看angular cli version 7 document 以获取选项列表。

    下面是 ng new --help 命令返回的选项列表。

    ng new --help 
    arguments:
      name
        The name of the workspace.
    
    options:
      --collection (-c)
        Schematics collection to use.
      --commit 
        Initial repository commit information.
      --create-application 
        Flag to toggle creation of an application in the new workspace.
      --defaults 
        When true, disables interactive input prompts for options with a default.
      --directory 
        The directory name to create the workspace in.
      --dry-run (-d)
        When true, run through and report activity without writing out results.
      --experimental-ivy 
        EXPERIMENTAL: Specifies whether to create a new application which uses the Ivy rendering engine.
      --force (-f)
        When true, force overwriting of existing files.
      --help 
        Shows a help message for this command in the console.
      --inline-style (-s)
        Specifies if the style will be in the ts file.
      --inline-template (-t)
        Specifies if the template will be in the ts file.
      --interactive 
        When false, disables interactive input prompts.
      --minimal 
        Create a barebones project without any testing frameworks
      --new-project-root 
        The path where new projects will be created.
      --prefix (-p)
        The prefix to apply to generated selectors.
      --routing 
        Generates a routing module.
      --skip-git (-g)
        Skip initializing a git repository.
      --skip-install 
        Skip installing dependency packages.
      --skip-tests (-S)
        Skip creating spec files.
      --style 
        The file extension to be used for style files.
      --verbose (-v)
        Adds more details to output logging.
      --view-encapsulation 
        Specifies the view encapsulation strategy.
    

    从 Angular cli 6.0.8 开始,最小选项似乎已被删除。您可能必须像其他答案建议的那样运行 --skip-tests、--inline-style 和 --inline-template 以获得最小的项目。

    根据angular cli wiki page,这些是可用的选项
    空运行

    冗长的 收藏
    内联样式
    内联模板
    视图封装
    路由
    前缀
    风格
    跳过测试
    跳过包json

    如果你运行这个命令:ng new --help,你可以看到 Angular cli 6.0.8 有哪些选项

    usage: ng new <name> [options]  
    options:  
      --collection (-c)  
        Schematics collection to use.  
    
    --directory   
        The directory name to create the workspace in.  
    
    --dryRun (-d)  
        Run through without making any changes.  
    
    --force (-f)  
        Forces overwriting of files.  
    
    --inline-style (-s)  
        Specifies if the style will be in the ts file.  
    
    --inline-template (-t)  
        Specifies if the template will be in the ts file.  
    
    --new-project-root   
        The path where new projects will be created.  
    
    --prefix (-p)  
        The prefix to apply to generated selectors.  
    
    --routing   
        Generates a routing module.  
    
    --skip-git (-g)  
        Skip initializing a git repository.  
    
    --skip-install   
        Skip installing dependency packages.  
    
    --skip-tests (-S)  
        Skip creating spec files.  
    
    --style   
        The file extension to be used for style files.  
    
    --verbose (-v)  
        Adds more details to output logging.  
    
    --view-encapsulation   
        Specifies the view encapsulation strategy. 
    

    【讨论】:

      猜你喜欢
      • 2018-10-02
      • 2021-06-26
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-03-25
      • 2020-01-03
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多