angular-cli.json configuration parameter explanation, as well as general key parameter explanation for vaguely commonly used commands

1. Common configuration of angular-cli.json

{
  "project": {
    "name": "ng-admin", //Project name
    "ejected": false // mark whether the application has executed the eject command to release the webpack configuration
  },
  "apps": [
    {
      "root": "src", // source root directory
      "outDir": "dist", // The compiled output directory, the default is dist/
      "assets": [ // Record the asset folder and copy it to the directory specified by `outDir` when building
        "assets",
        "favicon.ico"
      ],
      "index": "index.html", // Specify the homepage file, the default value is "index.html"
      "main": "main.ts", // specifies the starter file for the application
      "polyfills": "polyfills.ts", // 指定polyfill文件
      "test": "test.ts", // Specify the test entry file
      "tsconfig": "tsconfig.app.json", // 指定tsconfig文件
      "testTsconfig": "tsconfig.spec.json", // Specify the tsconfig file of the TypeScript unit test script 
"tsconfig":"tsconfig.app.json",
      "prefix": "app", // The prefix name automatically added to the value of selector metadata when using the `ng generate` command
      "deployUrl": "//cdn.com.cn", // Specify the deployment address of the site, this value will eventually be assigned to the output.publicPath of webpack, which is often used for CDN deployment
      "styles": [ // Introduce global styles, which will be packaged during construction, and are often used for styles introduced by third-party libraries
        "styles.css"
      ],
      "scripts": [ // Introduce global scripts, which will be packaged during construction, commonly used scripts introduced by third-party libraries
      ],
      "environmentSource": "environments/environment.ts", // basic environment configuration
      "environments": { // child environment configuration file
        "dev": "environments/environment.ts",
        "prod": "environments/environment.prod.ts"
      }
    }
  ],
  "e2e": {
    "protractor": {
      "config": "./protractor.conf.js"
    }
  },
  "lint": [
    {
      "project": "src/tsconfig.app.json"
    },
    {
      "project": "src/tsconfig.spec.json"
    },
    {
      "project": "e2e/tsconfig.e2e.json"
    }
  ],
  "test": {
    "karma": {
      "config": "./karma.conf.js"
    }
  },
  "defaults": { // some default values ​​when executing `ng generate` command
    "styleExt": "scss", // Default generated style file suffix
    "component": {
      "flat": false, // Whether to create a new folder to wrap the component file when generating the component, the default is false (ie, create a new folder)
      "spec": true, // Whether to generate a spec file, the default is true
      "inlineStyle": false, // Whether to use inline style when creating, the default is false
      "inlineTemplate": false, // Whether to use an inline template when creating a new one, the default is false
      "viewEncapsulation": "Emulated", // Specifies the default value of the generated component's metadata viewEncapsulation
      "changeDetection": "OnPush", // Specify the default value of the metadata changeDetection of the generated component
    }
  }
}
2. Explanation of common key parameters of common commands
1.ng serve --host (self)
指定本地Server绑定的域名,默认值:localhost.如果希望使用self来访问你的站点,须加入以上参数
2.
ng serve --hmr
注意开启之后,只是在angular-cli里的webpack添加必要的扩展,等价于webpack-dev-server --hot,还需要在应用代码里处理hmr逻辑,如可在main.ts里添加:
if(module.hot) {
  module.hot.accept();
}

3.ng serve--aot
开启aot
4.
ng serve --proxy-config proxy.conf.json
指定后台转发地址,即nginx的proxy_pass代理功能。开发时为避免ajax跨域,需要指定后台接口的转发地址。
proxy.config.json文件示例如下:
{
  "/api": { // 匹配前缀
    "target": "http://localhost:3000", // 转发地址
    "secure": false
  }
}

5.
--base-href
指定站点的起始路径,如果你希望你的站点根路径为www.abc.com/mypath/,需要这样设置:
ng build --base-href /mypath/
6.
--target
指定构建的目标,默认值是development,如果指定为production,构建时会加入treeshaking、代码压缩混淆等。
The following two are equivalent:
of build --target = production
of build --prod
7.--environment
指定应用执行环境。CLI会根据指定的值加载对应的环境配置文件。
The following two sentences are equivalent:
of build --environment = prod
ng build --env=prod 
will load the environment configuration file specified by angular-cli.json when building:
"environments": { 
  "dev": "environments/environment.ts",
  "prod": "environments/environment.prod.ts"
}

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324804452&siteId=291194637