当前位置: 首页 > article >正文

Monorepo学习笔记

Monorepo学习笔记

使用 pnpm 配置 monorepo

1、创建项目

mkdir stars-ui && cd stars-ui && pnpm init
mkdir packages docs

2、.gitignore

# Logs
logs
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*
pnpm-debug.log*
lerna-debug.log*

node_modules
dist
dist-ssr
*.local

# Editor directories and files
.vscode/*
!.vscode/extensions.json
.idea
.DS_Store
*.suo
*.ntvs*
*.njsproj
*.sln
*.sw?

pnpm-lock.yaml

3、package.json

{
  "name": "@xumeng03/monorepo",
  "private": "true",
  "description": "A Component Library for Vue 3",
  "scripts": {
    "preinstall": "npx only-allow pnpm",
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "license": "ISC",
  "engines": {
    "node": ">=18"
  }
}

4、pnpm-workspace.yaml

packages:
  - "packages/*"
  - "docs"
  - "play"

5、初始化

5.1、docs

pnpm init

docspackage.json如下

{
  "name": "docs",
  "private": "true",
  "version": "1.0.0",
  "description": "",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "keywords": [],
  "author": "",
  "license": "ISC"
}

5.2、packages

for i in components hooks stars-ui themes utils; do
    mkdir $i && cd $i
    pnpm init
    cd ..
done

componentshooksthemesutilspackage.json如下

{
  "name": "@stars-ui/components",
  "version": "1.0.0",
  "description": "",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "keywords": [],
  "author": "",
  "license": "ISC"
}

stars-uipackage.json如下

{
  "name": "@xumeng03/stars-ui",
  "version": "1.0.0",
  "description": "A Component Library for Vue 3",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "keywords": [],
  "author": "",
  "license": "ISC"
}

5.3、play

# 根目录执行
pnpm create vite play -template vue-ts

playpackage.json如下

{
  "name": "play",
  "private": true,
  "version": "0.0.0",
  "type": "module",
  "scripts": {
    "dev": "vite",
    "build": "vue-tsc -b && vite build",
    "preview": "vite preview"
  },
  "dependencies": {
    "vue": "^3.4.37"
  },
  "devDependencies": {
    "@vitejs/plugin-vue": "^5.1.2",
    "typescript": "^5.5.3",
    "vite": "^5.4.1",
    "vue-tsc": "^2.0.29"
  }
}

6、依赖安装

6.1、根目录依赖

pnpm add -Dw vite
pnpm add -Dw typescript
pnpm add -w vue
pnpm add -w lodash-es

@xumeng03/stars-ui引入作为全局依赖

{
  "name": "@xumeng03/monorepo",
  "private": "true",
  "description": "A Component Library for Vue 3",
  "scripts": {
    "preinstall": "npx only-allow pnpm",
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "license": "ISC",
  "engines": {
    "node": ">=18"
  },
  "devDependencies": {
    "typescript": "^5.5.3",
    "vite": "^5.4.1"
  },
  "dependencies": {
    "lodash-es": "^4.17.21",
    "vue": "^3.4.37",
    "@xumeng03/stars-ui": "workspace:*"
  },
  "workspaces": [
    "packages/*",
    "play",
    "docs"
  ]
}

6.2、docs依赖

按需求添加,我这里目前没有依赖需要安装

6.3、package子包依赖安装

按需求添加,我这里只是在@xumeng03/stars-ui里面引入@stars-ui/components、@stars-ui/hooks、@stars-ui/themes、@stars-ui/utils

{
  "name": "@xumeng03/stars-ui",
  "version": "1.0.0",
  "description": "",
  "main": "index.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "dependencies": {
    "@stars-ui/components": "workspace:*",
    "@stars-ui/hooks": "workspace:*",
    "@stars-ui/themes": "workspace:*",
    "@stars-ui/utils": "workspace:*"
  },
  "keywords": [],
  "author": "",
  "license": "ISC"
}

6.4、play依赖

{
  "name": "play",
  "private": true,
  "version": "0.0.0",
  "type": "module",
  "scripts": {
    "dev": "vite",
    "build": "vue-tsc -b && vite build",
    "preview": "vite preview"
  },
  "dependencies": {
    "vue": "^3.4.37"
  },
  "devDependencies": {
    "@vitejs/plugin-vue": "^5.1.2",
    "typescript": "^5.5.3",
    "vite": "^5.4.1",
    "vue-tsc": "^2.0.29"
  }
}

6.5、安装依赖

pnpm install

6.6、测试Monorepo

cd play
pnpm run dev

7、发布

待补。。。


http://www.kler.cn/a/292084.html

相关文章:

  • 酒店行业数据仓库
  • 消息中间件分类
  • onlyoffice Command service(命令服务)使用示例
  • 十堰市数据治理:大数据治理在智慧城市中的应用探索
  • 如何编译 Cesium 源码
  • 第三百二十三节 Java线程教程 - Java同步器
  • react 子组件调用父组件方法,获取的数据不是最新值
  • 常用网络协议理解
  • 加锁造成的线程优先级反转
  • 搜维尔科技:使用Facewaer面部捕捉系统制作栩栩如生的脸部动画
  • Maven 的 pom.xml 文件中<dependency> 元素及其各个参数的解释
  • EmguCV学习笔记 C# 10.1 人脸检测 CascadeClassifier类
  • C语言猜数小游戏
  • SpringBoot2:请求处理原理分析-请求Path与接口的映射关系(HandlerMapping)
  • 51单片机——蜂鸣器
  • Springboot +vue 网络零食商城系统
  • 828华为云征文:华为云 Flexus X 实例性能测评——SuperBench 一键窥见性能
  • 数据丢失要怎么处理,助你一键恢复数据
  • 算法笔试-编程练习-好题-02
  • 【操作系统】线程同步之互斥量
  • ssh之登录服务器后,自动进入目录(四十七)
  • ssh登录服务器报错“no matching host key type found. Their offer: ssh-rsa,ssh-dss”解决方法
  • IOS 22 自定义标题栏(Toolbar)
  • 代码随想录 -- 二叉树 -- 翻转二叉树
  • Linux--目录与文件操作函数
  • Leetcode JAVA刷刷站(105)从前序与中序遍历序列构造二叉树