国产 无码 综合区,色欲AV无码国产永久播放,无码天堂亚洲国产AV,国产日韩欧美女同一区二区

vite vue3配置eslint和prettier以及sass

這篇具有很好參考價(jià)值的文章主要介紹了vite vue3配置eslint和prettier以及sass。希望對大家有所幫助。如果存在錯(cuò)誤或未考慮完全的地方,請大家不吝賜教,您也可以點(diǎn)擊"舉報(bào)違法"按鈕提交疑問。

準(zhǔn)備

教程

安裝eslint

官網(wǎng)
vue-eslint
ts-eslint

安裝eslint

yarn add eslint -D

生成配置文件

npx eslint --init

vite 配置eslint,js,vue,sass,vue.js,javascript
vite 配置eslint,js,vue,sass,vue.js,javascript
vite 配置eslint,js,vue,sass,vue.js,javascript
vite 配置eslint,js,vue,sass,vue.js,javascript
vite 配置eslint,js,vue,sass,vue.js,javascript
vite 配置eslint,js,vue,sass,vue.js,javascript
vite 配置eslint,js,vue,sass,vue.js,javascript
vite 配置eslint,js,vue,sass,vue.js,javascript
安裝其他插件

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,
  },
  /* 指定如何解析語法 */
  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": "error",
    //除 import 語句外,不允許使用 require 語句。
    "@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í)行自定義事件名稱的特定大小寫
    "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)簽的右括號之前換行
    "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",
    //對模板中的自定義組件強(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ù)來定義觀察者
    "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",
    //禁止直接在對象上調(diào)用某些 Object.prototype 方法
    "no-prototype-builtins": "off",
    //禁止條件中的常量表達(dá)式
    "no-constant-condition": "off",
    //在定義變量之前禁止使用變量
    "no-use-before-define": "off",
    //禁止指定的全局變量
    "no-restricted-globals": "off",
    //不允許指定的語法
    "no-restricted-syntax": "off",
    //在生成器函數(shù)中圍繞*運(yùn)算符強(qiáng)制執(zhí)行一致的間距
    "generator-star-spacing": "off",
    //不允許在return、throw、continue和break語句之后出現(xià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

測試
vite 配置eslint,js,vue,sass,vue.js,javascript
也可以執(zhí)行查看結(jié)果

yarn eslint .

安裝prettier

官網(wǎng)

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

添加.prettierrc.cjs

module.exports = {
	// 一行最多多少個(gè)字符
	printWidth: 150,
	// 指定每個(gè)縮進(jìn)級別的空格數(shù)
	tabWidth: 2,
	// 使用制表符而不是空格縮進(jìn)行
	useTabs: true,
	// 在語句末尾打印分號
	semi: true,
	// 使用單引號而不是雙引號
	singleQuote: true,
	// 更改引用對象屬性的時(shí)間 可選值"<as-needed|consistent|preserve>"
	quoteProps: 'as-needed',
	// 在JSX中使用單引號而不是雙引號
	jsxSingleQuote: false,
	// 多行時(shí)盡可能打印尾隨逗號。(例如,單行數(shù)組永遠(yuǎn)不會(huì)出現(xiàn)逗號結(jié)尾。) 可選值"<none|es5|all>",默認(rèn)none
	trailingComma: 'es5',
	// 在對象文字中的括號之間打印空格
	bracketSpacing: true,
	// jsx 標(biāo)簽的反尖括號需要換行
	jsxBracketSameLine: false,
	// 在單獨(dú)的箭頭函數(shù)參數(shù)周圍包括括號 always:(x) => x \ avoid:x => x
	arrowParens: 'always',
	// 這兩個(gè)選項(xiàng)可用于格式化以給定字符偏移量(分別包括和不包括)開始和結(jié)束的代碼
	rangeStart: 0,
	rangeEnd: Infinity,
	// 指定要使用的解析器,不需要寫文件開頭的 @prettier
	requirePragma: false,
	// 不需要自動(dòng)在文件開頭插入 @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屬性書寫順序插件,
    '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)先級的選擇器后出現(xiàn)被其覆蓋的較低優(yōu)先級的選擇器
    'function-url-quotes': 'always', // 要求或禁止 URL 的引號 "always(必須加上引號)"|"never(沒有引號)"
    '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', //大括號之前必須有一個(gè)空格或不能有空白符,方法標(biāo)記過時(shí)
    '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)格式化ts、js、html、json還有markdown代碼
yarn lint:eslint會(huì)進(jìn)行錯(cuò)誤檢查
yarn lint:style會(huì)進(jìn)行錯(cuò)誤檢查修改為正確的格式

如果使用vscode需要安裝如下插件
vite 配置eslint,js,vue,sass,vue.js,javascript
vite 配置eslint,js,vue,sass,vue.js,javascript
vite 配置eslint,js,vue,sass,vue.js,javascript文章來源地址http://www.zghlxwxcb.cn/news/detail-819370.html

到了這里,關(guān)于vite vue3配置eslint和prettier以及sass的文章就介紹完了。如果您還想了解更多內(nèi)容,請?jiān)谟疑辖撬阉鱐OY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!

本文來自互聯(lián)網(wǎng)用戶投稿,該文觀點(diǎn)僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務(wù),不擁有所有權(quán),不承擔(dān)相關(guān)法律責(zé)任。如若轉(zhuǎn)載,請注明出處: 如若內(nèi)容造成侵權(quán)/違法違規(guī)/事實(shí)不符,請點(diǎn)擊違法舉報(bào)進(jìn)行投訴反饋,一經(jīng)查實(shí),立即刪除!

領(lǐng)支付寶紅包贊助服務(wù)器費(fèi)用

相關(guān)文章

  • vue3+ts項(xiàng)目02-安裝eslint、prettier和sass

    vue3+ts項(xiàng)目02-安裝eslint、prettier和sass

    項(xiàng)目創(chuàng)建 生成配置文件 安裝其他插件 修改.eslintrc.cjs 添加.eslintignore https://prettier.io/ 添加.prettierrc.cjs 添加.prettierignore https://stylelint.io/ 配置.stylelintrc.cjs 配置忽略文件.stylelintignore package.json增加配置 執(zhí)行 yarn format 會(huì)自動(dòng)格式化css、js、html、json還有markdown代碼

    2024年02月06日
    瀏覽(20)
  • [GN] 使用vue3+vite+ts+prettier+eslint

    做到代碼格式等統(tǒng)一,此時(shí),esint和prettier就要登場了。 eslint是代碼檢測工具,可以檢測出你代碼中潛在的問題,比如使用了某個(gè)變量卻忘記了定義。 prettier是代碼格式化工具,作為代碼格式化工具,能夠統(tǒng)一你或者你的團(tuán)隊(duì)的代碼風(fēng)格。 = 安裝prettier+eslint包,并做一系列的

    2024年01月16日
    瀏覽(26)
  • vite+vue3+ts+eslint+prettier+husky+lint-stated 項(xiàng)目搭建

    項(xiàng)目搭建 創(chuàng)建初始項(xiàng)目 Node.js 版本 14.18+,16+ npm create vite@latest my-vue-app --template vue-ts 添加eslint eslint 初始化 npm init @eslint/config eslint初始化腳本,按自己的要求選擇相應(yīng)的eslint 配置,以下是我選擇的配置項(xiàng) ? How would you like to use ESLint? · style ? What type of modules does your project

    2024年02月08日
    瀏覽(30)
  • Vue3+Vite+TS項(xiàng)目集成ESlint +Prettier實(shí)現(xiàn)代碼規(guī)范檢查和代碼格式化

    Vue3+Vite+TS項(xiàng)目集成ESlint +Prettier實(shí)現(xiàn)代碼規(guī)范檢查和代碼格式化

    我在這里直接是通過vite提供的默認(rèn)模板來創(chuàng)建一個(gè)vue3?+ ts的項(xiàng)目。這里可以cmd,然后npm -v來查看版本。 這樣一個(gè)vue3 + ts的項(xiàng)目就創(chuàng)建好了,使用vscode打開該項(xiàng)目,然后執(zhí)行 yarn 安裝依賴 依賴安裝完成后,執(zhí)行?? yarn dev ?啟動(dòng)項(xiàng)目就可以在瀏覽器中正常訪問了。 ? 初始化

    2024年01月24日
    瀏覽(30)
  • vite 創(chuàng)建vue3項(xiàng)目,使用 Prettier 統(tǒng)一格式化代碼,集成 ESLint、Stylelint 代碼校驗(yàn)規(guī)范

    vite 創(chuàng)建vue3項(xiàng)目,使用 Prettier 統(tǒng)一格式化代碼,集成 ESLint、Stylelint 代碼校驗(yàn)規(guī)范

    在團(tuán)隊(duì)開發(fā)中,保持代碼風(fēng)格的一致性和代碼質(zhì)量的高度,對于項(xiàng)目的可維護(hù)性和可讀性非常重要。為了實(shí)現(xiàn)這一目標(biāo),我們可以使用工具來自動(dòng)格式化代碼并進(jìn)行代碼校驗(yàn),在開發(fā)過程中捕獲潛在的問題,并提供修復(fù)建議。 本示例中,我們將使用 Vite 來創(chuàng)建一個(gè)新的 Vue

    2024年04月28日
    瀏覽(24)
  • 在vite+vue3項(xiàng)目中配置使用css預(yù)處理器(less/sass)以及路徑別名

    在vite+vue3項(xiàng)目中配置使用css預(yù)處理器(less/sass)以及路徑別名

    vite已經(jīng)將這些預(yù)處理器的loader內(nèi)置了,我們不用再像在webpack項(xiàng)目中那樣,需要下載和配置一堆相關(guān)的loader,我們只需要下載less,sass依賴,就能直接在項(xiàng)目中使用啦 使用npm或者yarn來安裝以下依賴: Less預(yù)處理器: npm install -D less Sass預(yù)處理器: npm install -D sass 如圖,下載之后

    2024年02月11日
    瀏覽(42)
  • 基于Vue3+Vite+TS+ESLint+Prettier+Husky+lint-staged+commitlint+stylelint的項(xiàng)目構(gòu)建

    基于Vue3+Vite+TS+ESLint+Prettier+Husky+lint-staged+commitlint+stylelint的項(xiàng)目構(gòu)建

    博客后臺管理系統(tǒng)使用后的是基于Vue3+Vite+TS+ESLint+Prettier的開發(fā),具體項(xiàng)目構(gòu)建如下 ESLint: 控制代碼質(zhì)量 Prettier: 控制代碼風(fēng)格 2.1、安裝ESLint、Prettier相關(guān)相關(guān)包 eslint: ESLint的核心代碼庫 prettier: Prettier的格式化代碼的核心代碼庫 eslint-config-airbnb-base: airbnb的代碼規(guī)范(依賴pl

    2024年02月07日
    瀏覽(29)
  • 超級詳細(xì) 最新 vite4+vue3+ts+element-plus+eslint-prettier 項(xiàng)目搭建流程

    系列文章目錄 【element-plus】 table表格每行圓角解決方案 element也通用 【Vue3+Vite+Ts+element-plus】使用tsx實(shí)現(xiàn)左側(cè)欄菜單無限層級封裝 超級詳細(xì)GitBook和GitLab集成步驟【linux環(huán)境】 1.1、項(xiàng)目創(chuàng)建 執(zhí)行以下代碼將vite將會(huì)自動(dòng)生成初始的 vite4+vue3+ts的項(xiàng)目模板,pnpm、npm、yarn 選擇一種執(zhí)

    2024年02月04日
    瀏覽(25)
  • vue3項(xiàng)目中簡單實(shí)用的ESLint + Prettier配置

    vue3項(xiàng)目中簡單實(shí)用的ESLint + Prettier配置

    一個(gè)中大型項(xiàng)目,一般由團(tuán)隊(duì)成員共同開發(fā)維護(hù)。而團(tuán)隊(duì)的成員都有自己的編碼風(fēng)格,導(dǎo)致整個(gè)項(xiàng)目的代碼看上去很亂,很難維護(hù)。這時(shí)就需要我們的ESlint來進(jìn)行限制。 一、使用vue-cli創(chuàng)建vue3項(xiàng)目 執(zhí)行vue-cli的創(chuàng)建項(xiàng)目命令 在執(zhí)行以上命令的時(shí)候,會(huì)有一步選擇編碼規(guī)范,如

    2024年02月12日
    瀏覽(20)
  • vue3-eslint-prettier-czgit配置

    vue3-eslint-prettier-czgit配置

    一:vue3 1.1 vue3創(chuàng)建 輸入命令后根據(jù)提示選擇,項(xiàng)目是ts所以必選typescript 1.2 安裝依賴 1.3 運(yùn)行 二:配置eslint 2.1 執(zhí)行安裝命令 2.2 初始化eslint 依次選擇 2.3 依賴安裝完成后,會(huì)生成 .eslintrc.cjs 配置文件 2.4 在 package.json 文件中的 script 中添加 lint 命令 2.5 執(zhí)行 lint 命令 遇到這樣

    2024年02月15日
    瀏覽(17)

覺得文章有用就打賞一下文章作者

支付寶掃一掃打賞

博客贊助

微信掃一掃打賞

請作者喝杯咖啡吧~博客贊助

支付寶掃一掃領(lǐng)取紅包,優(yōu)惠每天領(lǐng)

二維碼1

領(lǐng)取紅包

二維碼2

領(lǐng)紅包