<ruby id="bdb3f"></ruby>

    <p id="bdb3f"><cite id="bdb3f"></cite></p>

      <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
        <p id="bdb3f"><cite id="bdb3f"></cite></p>

          <pre id="bdb3f"></pre>
          <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

          <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
          <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

          <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                <ruby id="bdb3f"></ruby>

                ??一站式輕松地調用各大LLM模型接口,支持GPT4、智譜、豆包、星火、月之暗面及文生圖、文生視頻 廣告
                >[success] # 總結來源使用內容來自[深入Vue3+TypeScript技術棧-coderwhy大神新課](https://coderwhy.ke.qq.com/) # 項目搭建規范 ## 一. 代碼規范 ### 1.1. 集成editorconfig配置 EditorConfig 有助于為不同 IDE 編輯器上處理同一項目的多個開發人員維護一致的編碼風格。 ```yaml # http://editorconfig.org root = true [*] # 表示所有文件適用 charset = utf-8 # 設置文件字符集為 utf-8 indent_style = space # 縮進風格(tab | space) indent_size = 2 # 縮進大小 end_of_line = lf # 控制換行類型(lf | cr | crlf) trim_trailing_whitespace = true # 去除行首的任意空白字符 insert_final_newline = true # 始終在文件末尾插入一個新行 [*.md] # 表示僅 md 文件適用以下規則 max_line_length = off trim_trailing_whitespace = false ``` VSCode需要安裝一個插件:EditorConfig for VS Code ![image-20210722215138665](https://tva1.sinaimg.cn/large/008i3skNgy1gsq2gh989yj30pj05ggmb.jpg) ### 1.2. 使用prettier工具 Prettier 是一款強大的代碼格式化工具,支持 JavaScript、TypeScript、CSS、SCSS、Less、JSX、Angular、Vue、GraphQL、JSON、Markdown 等語言,基本上前端能用到的文件格式它都可以搞定,是當下最流行的代碼格式化工具。 1.安裝prettier ```shell npm install prettier -D ``` 2.配置.prettierrc文件: * useTabs:使用tab縮進還是空格縮進,選擇false; * tabWidth:tab是空格的情況下,是幾個空格,選擇2個; * printWidth:當行字符的長度,推薦80,也有人喜歡100或者120; * singleQuote:使用單引號還是雙引號,選擇true,使用單引號; * trailingComma:在多行輸入的尾逗號是否添加,設置為 `none`; * semi:語句末尾是否要加分號,默認值true,選擇false表示不加; ```json { "useTabs": false, "tabWidth": 2, "printWidth": 80, "singleQuote": true, "trailingComma": "none", "semi": false } ``` 3.創建.prettierignore忽略文件 ``` /dist/* .local .output.js /node_modules/** **/*.svg **/*.sh /public/* ``` 4.VSCode需要安裝prettier的插件 ![image-20210722214543454](https://tva1.sinaimg.cn/large/008i3skNgy1gsq2acx21rj30ow057mxp.jpg) 5.測試prettier是否生效 * 測試一:在代碼中保存代碼; * 測試二:配置一次性修改的命令; 在package.json中配置一個scripts: ```json "prettier": "prettier --write ." ``` ### 1.3. 使用ESLint檢測 1.在前面創建項目的時候,我們就選擇了ESLint,所以Vue會默認幫助我們配置需要的ESLint環境。 2.VSCode需要安裝ESLint插件: ![image-20210722215933360](https://tva1.sinaimg.cn/large/008i3skNgy1gsq2oq26odj30pw05faaq.jpg) 3.解決eslint和prettier沖突的問題: 安裝插件:(vue在創建項目時,如果選擇prettier,那么這兩個插件會自動安裝) ```shell npm i eslint-plugin-prettier eslint-config-prettier -D ``` 添加prettier插件: ```json extends: [ "plugin:vue/vue3-essential", "eslint:recommended", "@vue/typescript/recommended", "@vue/prettier", "@vue/prettier/@typescript-eslint", 'plugin:prettier/recommended' ], ``` ### 1.4. git Husky和eslint 雖然我們已經要求項目使用eslint了,但是不能保證組員提交代碼之前都將eslint中的問題解決掉了: * 也就是我們希望保證代碼倉庫中的代碼都是符合eslint規范的; * 那么我們需要在組員執行 `git commit ` 命令的時候對其進行校驗,如果不符合eslint規范,那么自動通過規范進行修復; 那么如何做到這一點呢?可以通過Husky工具: * husky是一個git hook工具,可以幫助我們觸發git提交的各個階段:pre-commit、commit-msg、pre-push 如何使用husky呢? 這里我們可以使用自動配置命令: ```shell npx husky-init && npm install ``` 這里會做三件事: 1.安裝husky相關的依賴: ![image-20210723112648927](https://tva1.sinaimg.cn/large/008i3skNgy1gsqq0o5jxmj30bb04qwen.jpg) 2.在項目目錄下創建 `.husky` 文件夾: ``` npx huksy install ``` ![image-20210723112719634](https://tva1.sinaimg.cn/large/008i3skNgy1gsqq16zo75j307703mt8m.jpg) 3.在package.json中添加一個腳本: ![image-20210723112817691](https://tva1.sinaimg.cn/large/008i3skNgy1gsqq26phpxj30dj06fgm3.jpg) 接下來,我們需要去完成一個操作:在進行commit時,執行lint腳本: ![image-20210723112932943](https://tva1.sinaimg.cn/large/008i3skNgy1gsqq3hn229j30nf04z74q.jpg) 這個時候我們執行git commit的時候會自動對代碼進行lint校驗。 ### 1.5. git commit規范 #### 1.5.1. 代碼提交風格 通常我們的git commit會按照統一的風格來提交,這樣可以快速定位每次提交的內容,方便之后對版本進行控制。 ![](https://tva1.sinaimg.cn/large/008i3skNgy1gsqw17gaqjj30to0cj3zp.jpg) 但是如果每次手動來編寫這些是比較麻煩的事情,我們可以使用一個工具:Commitizen * Commitizen 是一個幫助我們編寫規范 commit message 的工具; 1.安裝Commitizen ```shell npm install commitizen -D ``` 2.安裝cz-conventional-changelog,并且初始化cz-conventional-changelog: ```shell npx commitizen init cz-conventional-changelog --save-dev --save-exact ``` 這個命令會幫助我們安裝cz-conventional-changelog: ![image-20210723145249096](https://tva1.sinaimg.cn/large/008i3skNgy1gsqvz2odi4j30ek00zmx2.jpg) 并且在package.json中進行配置: ![](https://tva1.sinaimg.cn/large/008i3skNgy1gsqvzftay5j30iu04k74d.jpg) 這個時候我們提交代碼需要使用 `npx cz`: * 第一步是選擇type,本次更新的類型 | Type | 作用 | | -------- | ------------------------------------------------------------ | | feat | 新增特性 (feature) | | fix | 修復 Bug(bug fix) | | docs | 修改文檔 (documentation) | | style | 代碼格式修改(white-space, formatting, missing semi colons, etc) | | refactor | 代碼重構(refactor) | | perf | 改善性能(A code change that improves performance) | | test | 測試(when adding missing tests) | | build | 變更項目構建或外部依賴(例如 scopes: webpack、gulp、npm 等) | | ci | 更改持續集成軟件的配置文件和 package 中的 scripts 命令,例如 scopes: Travis, Circle 等 | | chore | 變更構建流程或輔助工具(比如更改測試環境) | | revert | 代碼回退 | * 第二步選擇本次修改的范圍(作用域) ![image-20210723150147510](https://tva1.sinaimg.cn/large/008i3skNgy1gsqw8ca15oj30r600wmx4.jpg) * 第三步選擇提交的信息 ![image-20210723150204780](https://tva1.sinaimg.cn/large/008i3skNgy1gsqw8mq3zlj60ni01hmx402.jpg) * 第四步提交詳細的描述信息 ![image-20210723150223287](https://tva1.sinaimg.cn/large/008i3skNgy1gsqw8y05bjj30kt01fjrb.jpg) * 第五步是否是一次重大的更改 ![image-20210723150322122](https://tva1.sinaimg.cn/large/008i3skNgy1gsqw9z5vbij30bm00q744.jpg) * 第六步是否影響某個open issue ![image-20210723150407822](https://tva1.sinaimg.cn/large/008i3skNgy1gsqwar8xp1j30fq00ya9x.jpg) 我們也可以在scripts中構建一個命令來執行 cz: ![image-20210723150526211](https://tva1.sinaimg.cn/large/008i3skNgy1gsqwc4gtkxj30e207174t.jpg) #### 1.5.2. 代碼提交驗證 如果我們按照cz來規范了提交風格,但是依然有同事通過 `git commit` 按照不規范的格式提交應該怎么辦呢? * 我們可以通過commitlint來限制提交; 1.安裝 @commitlint/config-conventional 和 @commitlint/cli ```shell npm i @commitlint/config-conventional @commitlint/cli -D ``` 2.在根目錄創建commitlint.config.js文件,配置commitlint ```js module.exports = { extends: ['@commitlint/config-conventional'] } ``` 3.使用husky生成commit-msg文件,驗證提交信息: ```shell npx husky add .husky/commit-msg "npx --no-install commitlint --edit $1" ```
                  <ruby id="bdb3f"></ruby>

                  <p id="bdb3f"><cite id="bdb3f"></cite></p>

                    <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
                      <p id="bdb3f"><cite id="bdb3f"></cite></p>

                        <pre id="bdb3f"></pre>
                        <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

                        <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
                        <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

                        <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                              <ruby id="bdb3f"></ruby>

                              哎呀哎呀视频在线观看