前端vue組件庫(kù)開發(fā)注意點(diǎn)

初始化

文件目錄

- packages  #組件
- cli  # 腳手架,一件添加新組件的文件,包括文檔里的文件
- docs  # 文檔
- play  #  組件開發(fā)環(huán)境
  1. 使用pnpm 的workspace, 需要pnpm-workspace.yaml 和package.json里配置有哪些包。

pnpm-workspace.yaml

packages:
  - packages/*
  - cli
  - docs
  - play
  # exclude packages that are inside test directories
  - '!**/test/**'

package.json

"workspaces": [
    "packages/*",
    "cli",
    "docs",
    "play"
  ],
  1. package.json要設(shè)置type為module

  2. 不需要?jiǎng)?chuàng)建一個(gè) .npmrc 文件,配置 shamefully-hoist 為 true(扁平結(jié)構(gòu)), 因?yàn)槭褂胮npm就避免了這個(gè)問題。

  3. 使用 npx eslint --init 初始化 ESLint 配置, 后面的自動(dòng)下載會(huì)失敗,可以手動(dòng)復(fù)制,加上 -D -w下載。后面的開發(fā)可以配合vite-plugin-eslint強(qiáng)制代碼風(fēng)格正確。

打包注意事項(xiàng)

  1. 盡量打包到dist里,不要改成其他如lib,可能外部項(xiàng)目導(dǎo)致無法導(dǎo)出子文件(我這里導(dǎo)不出style.css)

  2. package.json要正確加上配置

"type": "module",
  "main": "./dist/hj-ui-plus.umd.js",
  "module": "./dist/hj-ui-plus.es.js",
  "types": "./dist/hj-ui-plus/index.d.ts",
  "files": [
    "./dist",
    "package.json",
    "README.md"
  ],
  "exports": {
    ".": {
      "types": "./dist/hj-ui-plus/index.d.ts", // 雖然上面加了,但這里還要加,不然typescript會(huì)報(bào)錯(cuò)(雖然可以在tsconfig.json里的compilerOptions改"noImplicitAny": false,但這樣及降低健壯性了)
      "require": "./dist/hj-ui-plus.umd.js",
      "import": "./dist/hj-ui-plus.es.js"
    },
    "./*": "./*"  // 這個(gè)也必須加,不然也導(dǎo)不出子項(xiàng)目
  },

發(fā)布gihub page

可以用包 gh-pages

不過要注意項(xiàng)目的.git - config 里的url要是ssh的地址,不然命令行運(yùn)行時(shí)會(huì)報(bào)錯(cuò)443。

遇見一奇怪錯(cuò)誤,features文案中有<script setup>的話編譯生產(chǎn)后,主頁會(huì)報(bào)讀locales錯(cuò)誤,還無法點(diǎn)擊跳轉(zhuǎn)。vitepress版本1.0.0-rc.30

基本框例子: https://github.com/Garyhjj/hj-ui-plus

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容