创建Angular项目常用CLI命令

项目初始化

ng new my-proj --directory=my-proj --create-application=false --new-project-root='' --package-manager=yarn --skip-install --strict=false

创建项目应用

若项为空项目创建应用,则该应用会被设置成默认应用,修改默认应用需要修改angular.json 的 defaultProject设置。

ng g application jd-demo-app --style=scss --routing --skip-install --strict=false

ESLint

yarn add eslint -D @typescript-eslint/parser @typescript-eslint/eslint-plugin @typescript-eslint/eslint-plugin-tslint
.eslintrc.yml

env:
  es6: true
  node: true
extends:
  - "plugin:@typescript-eslint/recommended"
parser: "@typescript-eslint/parser"
parserOptions:
  sourceType: module
  # project: 'tsconfig.json'
plugins:
  - "@typescript-eslint"
  # - '@typescript-eslint/tslint'
  - "prettier"
ignorePatterns:
  - "dist/"
  - "node_modules/"
  - "*.d.ts"
  - "*.json"
  - "*/assets/*"
rules:
  ## Coding style
  no-nested-ternary: error
  quotes:
    - error
    - single
    - avoidEscape: true
      allowTemplateLiterals: false
  comma-style:
    - error
    - last
  no-mixed-spaces-and-tabs: error
  no-trailing-spaces: error
  no-multi-str: error
  semi:
    - error
    - always
  ## Error-prone
  eqeqeq:
    - error
    - smart
  no-func-assign: error
  no-prototype-builtins: error
  no-redeclare: error
  no-sequences: error
  no-unreachable: error
  ## eslint rule no-unused-vars gonna have problem when lint typescript
  no-unused-vars: "off"
  "@typescript-eslint/no-unused-vars":
    - error
    - args: all
      argsIgnorePattern: "^_"
      vars: all
      varsIgnorePattern: "^_"
  ## -------------Prettier ---------------
  "prettier/prettier": ["warn"]
  ## -------------Override typescript-eslint recommended rules ---------------
  "@typescript-eslint/array-type":
    - error
    - default: "array"
      readonly: "array"
  # "@typescript-eslint/await-thenable": ["error"]
  "@typescript-eslint/ban-types":
    - "error"
    - extendDefaults: true
  "@typescript-eslint/no-use-before-define":
    - error
    - classes: false
  "@typescript-eslint/no-inferrable-types":
    - "off"
    - ignoreParameters: false
      ignoreProperties: false
  # "@typescript-eslint/explicit-module-boundary-types":
  #     ["error"]
  # "@typescript-eslint/no-empty-interface":
  #     ["error"]
  # '@typescript-eslint/no-explicit-any': ['warn', { 'fixToUnknown': false, 'ignoreRestArgs': true }]
  # "@typescript-eslint/no-extra-non-null-assertion":
  #     ["error"]
  # "@typescript-eslint/no-floating-promises":
  #     ["error"]
  # "@typescript-eslint/no-for-in-array":
  #     ["error"]
  # "@typescript-eslint/no-implied-eval":
  #     ["error"]
  # "@typescript-eslint/no-misused-new":
  #     ["error"]
  # "@typescript-eslint/no-misused-promises":
  #     ["error"]
  # "@typescript-eslint/no-namespace":
  #     ["error"]
  # For now the framework is using TypeScript ~2.7.0.
  # If you are not using TypeScript 3.7 (or greater), then you will not need to use this rule, as the operator is not supported.
  # "@typescript-eslint/no-non-null-asserted-optional-chain":
  #     ["error"]
  # '@typescript-eslint/no-this-alias': ['error', { 'allowDestructuring': true, 'allowedNames': ['self'] }]
  # Magic number
  # Need to turnoff ESLint rule and valid TSLint rule
  # "no-magic-numbers": ["off"]
  # '@typescript-eslint/no-magic-numbers':
  #   ['off', { 'ignoreEnums': true, 'ignoreNumericLiteralTypes': true, 'ignoreReadonlyClassProperties': true }]
  # Constructors with parameters are valid. No need to add this rule
  #"@typescript-eslint/no-empty-function":
  #   ["error", { "allow": ["constructors"] }]
  ## -------------Tslint config ---------------
  # "@typescript-eslint/tslint/config": ["error", {
  #     "rulesDirectory": ['codelyzer'],
  #     "rules": {
  #     }
  # }]

Prettier

yarn add -D prettier eslint-config-prettier eslint-plugin-prettier

.prettierrc.yml

# recommend 120
printWidth: 120

# indentation-level spaces
tabWidth: 2

# use spaces as indent lines
useTabs: false

# Add a semicolon at the end of every statement
semi: true

# Use single quotes instead of double quotes
singleQuote: true

# Change when properties in objects are quoted
# as-needed - Only add quotes around object properties where required
# consistent - If at least one property in an object requires quotes, quote all properties
# preserve - Respect the input use of quotes in object properties
quoteProps: "preserve"

# Use single quotes instead of double quotes in JSX (not for Angular)
# jsxSingleQuote: false

# Print trailing commas wherever possible when multi-line. (A single-line array, for example, never gets trailing commas.)
# es5 - Trailing commas where valid in ES5 (objects, arrays, etc.)
# none - No trailing commas
# all - Trailing commas wherever possible (including function arguments). This requires node 8 or a transform
trailingComma: "none"

# Print spaces between brackets in object literals.
bracketSpacing: true

# Put the > of a multi-line JSX element at the end of the last line instead of being alone on the next line (does not apply to self closing elements).
# false - Example
# <button
#   className="prettier-class"
#   id="prettier-id"
#   onClick={this.handleClick}>
#   Click Here
# </button>
# true - Example
# <button
#   className="prettier-class"
#   id="prettier-id"
#   onClick={this.handleClick}
# >
#   Click Here
# </button>
# jsxBracketSameLine: false

# Include parentheses around a sole arrow function parameter.
# always - Always include parens. Example: (x) => x
# avoid - Omit parens when possible. Example: x => x
arrowParens: "avoid"

# Specify which parser to use.
# Prettier automatically infers the parser from the input file path, so you shouldn't have to change this setting.
# parser: "angular"

# Specify the file name to use to infer which parser to use.
# filepath: "None"

# Prettier can restrict itself to only format files that contain a special comment, called a pragma, at the top of the file.
# This is very useful when gradually transitioning large, unformatted codebases to prettier.
# requirePragma: false

# Prettier can insert a special @format marker at the top of files specifying that the file has been formatted with prettier.
# This works well when used in tandem with the --require-pragma option.
# If there is already a docblock at the top of the file then this option will add a newline to it with the @format marker.
# insertPragma: false

# By default, Prettier will wrap markdown text as-is since some services use a linebreak-sensitive renderer,
# e.g. GitHub comment and BitBucket. In some cases you may want to rely on editor/viewer soft wrapping instead,
# so this option allows you to opt out with "never".
# proseWrap: "preserve"

# Specify the global whitespace sensitivity for HTML files, see whitespace-sensitive formatting for more info.
# css - Respect the default value of CSS display property.
# strict - Whitespaces are considered sensitive.
# ignore - Whitespaces are considered insensitive.
htmlWhitespaceSensitivity: "css"

# Whether or not to indent the code inside <script> and <style> tags in Vue files.
# Some people (like the creator of Vue) don’t indent to save an indentation level, but this might break code folding in your editor.
vueIndentScriptAndStyle: false

# "lf" – Line Feed only (\n), common on Linux and macOS as well as inside git repos
# "crlf" - Carriage Return + Line Feed characters (\r\n), common on Windows
# "cr" - Carriage Return character only (\r), used very rarely
# "auto" - Maintain existing line endings (mixed values within one file are normalised by looking at what's used after the first line)
endOfLine: "crlf"
©著作权归作者所有,转载或内容合作请联系作者
  • 序言:七十年代末,一起剥皮案震惊了整个滨河市,随后出现的几起案子,更是在滨河造成了极大的恐慌,老刑警刘岩,带你破解...
    沈念sama阅读 212,383评论 6 493
  • 序言:滨河连续发生了三起死亡事件,死亡现场离奇诡异,居然都是意外死亡,警方通过查阅死者的电脑和手机,发现死者居然都...
    沈念sama阅读 90,522评论 3 385
  • 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
    开封第一讲书人阅读 157,852评论 0 348
  • 文/不坏的土叔 我叫张陵,是天一观的道长。 经常有香客问我,道长,这世上最难降的妖魔是什么? 我笑而不...
    开封第一讲书人阅读 56,621评论 1 284
  • 正文 为了忘掉前任,我火速办了婚礼,结果婚礼上,老公的妹妹穿的比我还像新娘。我一直安慰自己,他们只是感情好,可当我...
    茶点故事阅读 65,741评论 6 386
  • 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
    开封第一讲书人阅读 49,929评论 1 290
  • 那天,我揣着相机与录音,去河边找鬼。 笑死,一个胖子当着我的面吹牛,可吹牛的内容都是我干的。 我是一名探鬼主播,决...
    沈念sama阅读 39,076评论 3 410
  • 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
    开封第一讲书人阅读 37,803评论 0 268
  • 序言:老挝万荣一对情侣失踪,失踪者是张志新(化名)和其女友刘颖,没想到半个月后,有当地人在树林里发现了一具尸体,经...
    沈念sama阅读 44,265评论 1 303
  • 正文 独居荒郊野岭守林人离奇死亡,尸身上长有42处带血的脓包…… 初始之章·张勋 以下内容为张勋视角 年9月15日...
    茶点故事阅读 36,582评论 2 327
  • 正文 我和宋清朗相恋三年,在试婚纱的时候发现自己被绿了。 大学时的朋友给我发了我未婚夫和他白月光在一起吃饭的照片。...
    茶点故事阅读 38,716评论 1 341
  • 序言:一个原本活蹦乱跳的男人离奇死亡,死状恐怖,灵堂内的尸体忽然破棺而出,到底是诈尸还是另有隐情,我是刑警宁泽,带...
    沈念sama阅读 34,395评论 4 333
  • 正文 年R本政府宣布,位于F岛的核电站,受9级特大地震影响,放射性物质发生泄漏。R本人自食恶果不足惜,却给世界环境...
    茶点故事阅读 40,039评论 3 316
  • 文/蒙蒙 一、第九天 我趴在偏房一处隐蔽的房顶上张望。 院中可真热闹,春花似锦、人声如沸。这庄子的主人今日做“春日...
    开封第一讲书人阅读 30,798评论 0 21
  • 文/苍兰香墨 我抬头看了看天上的太阳。三九已至,却和暖如春,着一层夹袄步出监牢的瞬间,已是汗流浃背。 一阵脚步声响...
    开封第一讲书人阅读 32,027评论 1 266
  • 我被黑心中介骗来泰国打工, 没想到刚下飞机就差点儿被人妖公主榨干…… 1. 我叫王不留,地道东北人。 一个月前我还...
    沈念sama阅读 46,488评论 2 361
  • 正文 我出身青楼,却偏偏与公主长得像,于是被迫代替她去往敌国和亲。 传闻我的和亲对象是个残疾皇子,可洞房花烛夜当晚...
    茶点故事阅读 43,612评论 2 350

推荐阅读更多精彩内容