最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

vue3+ts項(xiàng)目之安裝eslint、prettier和sass的詳細(xì)過(guò)程

 更新時(shí)間:2023年10月12日 17:11:53   作者:假裝我不帥  
這篇文章主要介紹了vue3+ts項(xiàng)目02-安裝eslint、prettier和sass的詳細(xì)過(guò)程,在本文講解中需要注意執(zhí)行yarn format會(huì)自動(dòng)格式化css、js、html、json還有markdown代碼,需要的朋友可以參考下

創(chuàng)建項(xiàng)目

項(xiàng)目創(chuàng)建

安裝eslint

yarn add eslint -D

生成配置文件

npx eslint --init

安裝其他插件

yarn add  -D eslint-plugin-import eslint-plugin-vue eslint-plugin-node eslint-plugin-prettier eslint-config-prettier eslint-plugin-node @babel/eslint-parser vue-eslint-parser

修改.eslintrc.cjs

module.exports = {
  env: {
    browser: true,
    es2021: true,
    node: true,
    jest: true,
  },
  /* 指定如何解析語(yǔ)法 */
  parser: "vue-eslint-parser",
  parserOptions: {
    ecmaVersion: "latest",
    parser: "@typescript-eslint/parser",
    sourceType: "module",
  },
  extends: [
    "eslint:recommended",
    "plugin:@typescript-eslint/recommended",
    "plugin:vue/vue3-essential",
  ],
  overrides: [
    {
      env: {
        node: true,
      },
      files: [".eslintrc.{js,cjs}"],
      parserOptions: {
        sourceType: "script",
      },
    },
  ],
  plugins: ["@typescript-eslint", "vue"],
  rules: {
    // 參考 https://typescript-eslint.io/
    // 禁止// @ts-ignore
    "@typescript-eslint/ban-ts-ignore": "off",
    //要求函數(shù)和類方法有顯式返回類型。
    "@typescript-eslint/explicit-function-return-type": "off",
    //禁用any類型
    "@typescript-eslint/no-explicit-any": "off",
    //除 import 語(yǔ)句外,不允許使用 require 語(yǔ)句。
    "@typescript-eslint/no-var-requires": "off",
    //禁止空函數(shù)
    "@typescript-eslint/no-empty-function": "off",
    //在定義變量之前禁止使用變量。
    "@typescript-eslint/no-use-before-define": "off",
    //禁止 @ts-<directive> 注釋或要求指令后有描述。
    "@typescript-eslint/ban-ts-comment": "off",
    //禁止某些類型。
    "@typescript-eslint/ban-types": "off",
    //禁止使用 ! 進(jìn)行非空斷言后綴運(yùn)算符。
    "@typescript-eslint/no-non-null-assertion": "off",
    //要求導(dǎo)出函數(shù)和類的公共類方法顯式返回和參數(shù)類型。
    "@typescript-eslint/explicit-module-boundary-types": "off",
    // 參考 https://eslint.vuejs.org/rules/
    //強(qiáng)制執(zhí)行自定義事件名稱的特定大小寫(xiě)
    "vue/custom-event-name-casing": "off",
    //強(qiáng)制執(zhí)行屬性順序
    "vue/attributes-order": "off",
    //強(qiáng)制每個(gè)組件都應(yīng)位于自己的文件中
    "vue/one-component-per-file": "off",
    //不允許在標(biāo)簽的右括號(hào)之前換行
    "vue/html-closing-bracket-newline": "off",
    //強(qiáng)制每行的最大屬性數(shù)
    "vue/max-attributes-per-line": "off",
    //需要在多行元素的內(nèi)容之前和之后換行
    "vue/multiline-html-element-content-newline": "off",
    //需要在單行元素的內(nèi)容之前和之后換行
    "vue/singleline-html-element-content-newline": "off",
    //對(duì)模板中的自定義組件強(qiáng)制執(zhí)行屬性命名樣式
    "vue/attribute-hyphenation": "off",
    //強(qiáng)制執(zhí)行自關(guān)閉風(fēng)格
    "vue/html-self-closing": "off",
    //禁止向模板添加多個(gè)根節(jié)點(diǎn)
    "vue/no-multiple-template-root": "off",
    "vue/require-default-prop": "off",
    //禁止向自定義組件中使用的 v-model 添加參數(shù)
    "vue/no-v-model-argument": "off",
    //禁止使用箭頭函數(shù)來(lái)定義觀察者
    "vue/no-arrow-functions-in-watch": "off",
    //禁止 <template> 上的key屬性
    "vue/no-template-key": "off",
    //禁止使用v-html以防止XSS攻擊
    "vue/no-v-html": "off",
    //支持 <template> 中的注釋指令
    "vue/comment-directive": "off",
    //禁止 <template> 中出現(xiàn)解析錯(cuò)誤
    "vue/no-parsing-error": "off",
    //禁止使用已棄用的 .native 修飾符(在 Vue.js 3.0.0+ 中)
    "vue/no-deprecated-v-on-native-modifier": "off",
    //要求組件名稱始終為多個(gè)單詞
    "vue/multi-word-component-names": "off",
    // 參考 http://eslint.cn/docs/rules/
    //禁止添加論據(jù)v-model 用于定制組件
    "no-v-model-argument": "off",
    //禁止使用不必要的轉(zhuǎn)義字符
    "no-useless-escape": "off",
    //禁止稀疏數(shù)組
    "no-sparse-arrays": "off",
    //禁止直接在對(duì)象上調(diào)用某些 Object.prototype 方法
    "no-prototype-builtins": "off",
    //禁止條件中的常量表達(dá)式
    "no-constant-condition": "off",
    //在定義變量之前禁止使用變量
    "no-use-before-define": "off",
    //禁止指定的全局變量
    "no-restricted-globals": "off",
    //不允許指定的語(yǔ)法
    "no-restricted-syntax": "off",
    //在生成器函數(shù)中圍繞*運(yùn)算符強(qiáng)制執(zhí)行一致的間距
    "generator-star-spacing": "off",
    //不允許在return、throw、continue和break語(yǔ)句之后出現(xiàn)無(wú)法訪問(wèn)的代碼
    "no-unreachable": "off",
    //vue2只有一個(gè)節(jié)點(diǎn)但是vue3支持多個(gè)
    "no-multiple-template-root": "off",
    //該規(guī)則旨在消除未使用的變量,函數(shù)和函數(shù)的參數(shù)。
    "no-unused-vars": "error",
    //禁止case聲明
    "no-case-declarations": "off",
    //禁止console
    "no-console": "error",
  },
};

添加.eslintignore

*.sh
node_modules
lib
*.md
*.scss
*.woff
*.ttf
.vscode
.idea
dist
mock
public
bin
build
config
index.html
src/assets

安裝prettier

https://prettier.io/

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

添加.prettierrc.cjs

module.exports = {
	// 一行最多多少個(gè)字符
	printWidth: 150,
	// 指定每個(gè)縮進(jìn)級(jí)別的空格數(shù)
	tabWidth: 2,
	// 使用制表符而不是空格縮進(jìn)行
	useTabs: true,
	// 在語(yǔ)句末尾打印分號(hào)
	semi: true,
	// 使用單引號(hào)而不是雙引號(hào)
	singleQuote: true,
	// 更改引用對(duì)象屬性的時(shí)間 可選值"<as-needed|consistent|preserve>"
	quoteProps: 'as-needed',
	// 在JSX中使用單引號(hào)而不是雙引號(hào)
	jsxSingleQuote: false,
	// 多行時(shí)盡可能打印尾隨逗號(hào)。(例如,單行數(shù)組永遠(yuǎn)不會(huì)出現(xiàn)逗號(hào)結(jié)尾。) 可選值"<none|es5|all>",默認(rèn)none
	trailingComma: 'es5',
	// 在對(duì)象文字中的括號(hào)之間打印空格
	bracketSpacing: true,
	// jsx 標(biāo)簽的反尖括號(hào)需要換行
	jsxBracketSameLine: false,
	// 在單獨(dú)的箭頭函數(shù)參數(shù)周圍包括括號(hào) always:(x) => x \ avoid:x => x
	arrowParens: 'always',
	// 這兩個(gè)選項(xiàng)可用于格式化以給定字符偏移量(分別包括和不包括)開(kāi)始和結(jié)束的代碼
	rangeStart: 0,
	rangeEnd: Infinity,
	// 指定要使用的解析器,不需要寫(xiě)文件開(kāi)頭的 @prettier
	requirePragma: false,
	// 不需要自動(dòng)在文件開(kāi)頭插入 @prettier
	insertPragma: false,
	// 使用默認(rèn)的折行標(biāo)準(zhǔn) always\never\preserve
	proseWrap: 'preserve',
	// 指定HTML文件的全局空格敏感度 css\strict\ignore
	htmlWhitespaceSensitivity: 'css',
	// Vue文件腳本和樣式標(biāo)簽縮進(jìn)
	vueIndentScriptAndStyle: false,
	// 換行符使用 lf 結(jié)尾是 可選值"<auto|lf|crlf|cr>"
	endOfLine: 'lf',
};

添加.prettierignore

/dist/*
/html/*
.local
/node_modules/**
**/*.svg
**/*.sh
/public/*

安裝sass

yarn add sass sass-loader stylelint postcss postcss-scss postcss-html stylelint-config-prettier stylelint-config-recess-order stylelint-config-recommended-scss stylelint-config-standard stylelint-config-standard-vue stylelint-scss stylelint-order stylelint-config-standard-scss -D

https://stylelint.io/

配置.stylelintrc.cjs

// @see https://stylelint.bootcss.com/
module.exports = {
  extends: [
    'stylelint-config-standard', // 配置stylelint拓展插件
    'stylelint-config-html/vue', // 配置 vue 中 template 樣式格式化
    'stylelint-config-standard-scss', // 配置stylelint scss插件
    'stylelint-config-recommended-vue/scss', // 配置 vue 中 scss 樣式格式化
    'stylelint-config-recess-order', // 配置stylelint css屬性書(shū)寫(xiě)順序插件,
    'stylelint-config-prettier', // 配置stylelint和prettier兼容
  ],
  overrides: [
    {
      files: ['**/*.(scss|css|vue|html)'],
      customSyntax: 'postcss-scss',
    },
    {
      files: ['**/*.(html|vue)'],
      customSyntax: 'postcss-html',
    },
  ],
  ignoreFiles: [
    '**/*.js',
    '**/*.jsx',
    '**/*.tsx',
    '**/*.ts',
    '**/*.json',
    '**/*.md',
    '**/*.yaml',
  ],
  /**
   * null  => 關(guān)閉該規(guī)則
   * always => 必須
   */
  rules: {
    'value-keyword-case': null, // 在 css 中使用 v-bind,不報(bào)錯(cuò)
    'no-descending-specificity': null, // 禁止在具有較高優(yōu)先級(jí)的選擇器后出現(xiàn)被其覆蓋的較低優(yōu)先級(jí)的選擇器
    'function-url-quotes': 'always', // 要求或禁止 URL 的引號(hào) "always(必須加上引號(hào))"|"never(沒(méi)有引號(hào))"
    'no-empty-source': null, // 關(guān)閉禁止空源碼
    'selector-class-pattern': null, // 關(guān)閉強(qiáng)制選擇器類名的格式
    'property-no-unknown': null, // 禁止未知的屬性(true 為不允許)
    'block-opening-brace-space-before': 'always', //大括號(hào)之前必須有一個(gè)空格或不能有空白符
    'value-no-vendor-prefix': null, // 關(guān)閉 屬性值前綴 --webkit-box
    'property-no-vendor-prefix': null, // 關(guān)閉 屬性前綴 -webkit-mask
    'selector-pseudo-class-no-unknown': [
      // 不允許未知的選擇器
      true,
      {
        ignorePseudoClasses: ['global', 'v-deep', 'deep'], // 忽略屬性,修改element默認(rèn)樣式的時(shí)候能使用到
      },
    ],
  },
}

配置忽略文件.stylelintignore

/node_modules/*
/dist/*
/html/*
/public/*

package.json增加配置

"format": "prettier --write \"./**/*.{html,vue,ts,js,json,md}\"",
"lint:eslint": "eslint src/**/*.{ts,vue} --cache --fix",
"lint:style": "stylelint src/**/*.{css,scss,vue} --cache --fix",

執(zhí)行yarn format會(huì)自動(dòng)格式化css、js、html、json還有markdown代碼

到此這篇關(guān)于vue3+ts項(xiàng)目02-安裝eslint、prettier和sass的文章就介紹到這了,更多相關(guān)vue3 ts安裝eslint、prettier和sass內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!

相關(guān)文章

  • 實(shí)例講解vue源碼架構(gòu)

    實(shí)例講解vue源碼架構(gòu)

    在本篇文章中小編給大家分享了關(guān)于vue源碼架構(gòu)的相關(guān)知識(shí)點(diǎn)內(nèi)容,有需要的朋友們學(xué)習(xí)下。
    2019-01-01
  • 淺談Ant Design Pro 菜單自定義 icon

    淺談Ant Design Pro 菜單自定義 icon

    這篇文章主要介紹了Ant Design Pro 菜單自定義 icon,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過(guò)來(lái)看看吧
    2020-11-11
  • vue+Echart實(shí)現(xiàn)立體柱狀圖

    vue+Echart實(shí)現(xiàn)立體柱狀圖

    這篇文章主要為大家詳細(xì)介紹了vue+Echart實(shí)現(xiàn)立體柱狀圖,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2022-04-04
  • 解決iview打包時(shí)UglifyJs報(bào)錯(cuò)的問(wèn)題

    解決iview打包時(shí)UglifyJs報(bào)錯(cuò)的問(wèn)題

    下面小編就為大家分享一篇解決iview打包時(shí)UglifyJs報(bào)錯(cuò)的問(wèn)題,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過(guò)來(lái)看看吧
    2018-03-03
  • Vue3中的unref詳解與常見(jiàn)使用方法

    Vue3中的unref詳解與常見(jiàn)使用方法

    這篇文章主要給大家介紹了關(guān)于Vue3中unref詳解與常見(jiàn)使用的相關(guān)資料,Vue3中的unref是一個(gè)實(shí)用工具,用于簡(jiǎn)化訪問(wèn)響應(yīng)式引用和普通值的過(guò)程,通過(guò)自動(dòng)判斷類型,unref可以處理任何類型的值,從而使代碼更加簡(jiǎn)潔和易讀,需要的朋友可以參考下
    2024-11-11
  • Vue兩種組件類型:遞歸組件和動(dòng)態(tài)組件的用法

    Vue兩種組件類型:遞歸組件和動(dòng)態(tài)組件的用法

    這篇文章主要介紹了Vue兩種組件類型:遞歸組件和動(dòng)態(tài)組件的用法說(shuō)明,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過(guò)來(lái)看看吧
    2020-08-08
  • 基于Vue實(shí)現(xiàn)平滑過(guò)渡的拖拽排序功能

    基于Vue實(shí)現(xiàn)平滑過(guò)渡的拖拽排序功能

    這篇文章主要介紹了vue實(shí)現(xiàn)平滑過(guò)渡的拖拽排序功能,本文通過(guò)實(shí)例代碼給大家介紹的非常詳細(xì),具有一定的參考借鑒價(jià)值,需要的朋友可以參考下
    2019-06-06
  • Element UI 表格中實(shí)現(xiàn)搜索關(guān)鍵字高亮顯示功能

    Element UI 表格中實(shí)現(xiàn)搜索關(guān)鍵字高亮顯示功能

    在數(shù)據(jù)展示類應(yīng)用中,搜索功能是提升用戶體驗(yàn)的關(guān)鍵模塊,而關(guān)鍵字高亮則能讓搜索結(jié)果更加直觀醒目,本文詳解如何在ElementUI中實(shí)現(xiàn)表格搜索與關(guān)鍵字高亮,結(jié)合樹(shù)形結(jié)構(gòu)遞歸處理及CSS樣式,提升數(shù)據(jù)可讀性與用戶體驗(yàn),感興趣的朋友跟隨小編一起看看吧
    2025-06-06
  • Vue3?PDF預(yù)覽組件設(shè)計(jì)與實(shí)現(xiàn)方法分析

    Vue3?PDF預(yù)覽組件設(shè)計(jì)與實(shí)現(xiàn)方法分析

    隨著互聯(lián)網(wǎng)的發(fā)展,PDF文件在信息交流和文檔分享中起著重要的作用,通過(guò)在Vue組件中實(shí)現(xiàn)PDF預(yù)覽功能,我們可以為用戶提供便捷的內(nèi)容閱讀體驗(yàn),這篇文章主要介紹了Vue3?PDF預(yù)覽組件設(shè)計(jì)與實(shí)現(xiàn)方法的相關(guān)資料,需要的朋友可以參考下
    2026-03-03
  • Vue中的v-model,v-bind,v-on的區(qū)別解析

    Vue中的v-model,v-bind,v-on的區(qū)別解析

    vue.js是一套構(gòu)建用戶界面的框架,只關(guān)注視圖層,它不僅易于上手,還便于與第三方庫(kù)或既有項(xiàng)目整合,vue.js有配套的第三方類庫(kù),可以整合起來(lái)做大型項(xiàng)目的開(kāi)發(fā),這篇文章主要介紹了v-model,v-bind,v-on的區(qū)別,需要的朋友可以參考下
    2022-12-12

最新評(píng)論

隆尧县| 托里县| 大方县| 德钦县| 晋城| 林周县| 慈利县| 康马县| 澄城县| 合川市| 青浦区| 荣昌县| 天祝| 太康县| 平利县| 永康市| 怀集县| 望江县| 连平县| 临安市| 徐闻县| 潼关县| 达拉特旗| 武定县| 封丘县| 香港| 郓城县| 新乐市| 鞍山市| 繁昌县| 汉川市| 南宫市| 清河县| 黄骅市| 临西县| 邢台市| 广西| 乐至县| 清苑县| 图木舒克市| 华容县|