当前位置:网站首页>Practice sharing of monorepo based on yarn1.x
Practice sharing of monorepo based on yarn1.x
2022-07-26 01:25:00 【ataola】
Background introduction
A few days ago , Captain Xiaodong asked me on wechat , Does your team have monorepo Practice , I regret to tell him that there is no , But this sows a seed of exploration in my heart , Just recently, the boss is going to start a new project in Inner Mongolia , I formed a double gun death squad with another front-end brother to escort , So I began to explore , Is there a possibility , You can manage multiple projects in one warehouse , The management here refers to the orderly and standardized management , Rather than simply trampling several projects together .
Introduction to related concepts
What is? monorepo?
In version control system ,monorepo It's a software development strategy , The code for many of these projects is stored in the same repository . This kind of software engineering practice can be traced back to at least 2000 In the early s , It was called “ Shared code base ”. A related concept is the whole , But although the overall sub projects are merged into a large project , But the overall warehouse may contain independent projects .( Translated from Wikipedia )
What is? yarn? What is yarn wrokspace?
In short ,Yarn Workspaces yes Yarn Provided monorepo The dependency management mechanism of , from Yarn 1.0 Start default support , It is used to manage multiple... Under the root directory of the code warehouse package Dependence
Practical course
Specific tutorial , I think the official website has written in great detail , I don't need to reread , So I will only introduce some key points related to this project .
This is how I build the architecture , Divide the project into two ,applications Represents the application directory , It contains some items , For example, the enterprise side 、 The capital side 、 Platform end , And applets and h5 etc. , and packages In this case , It's me who put applications Pull out the public part of , Make it reusable .

besides , The project has also done some optimization , such as
Configured with eslint + prettier To standardize the team's code
Configured with husky and commitlint To standardize the code submission of the team
The directory structure of the project is like this
applications/ent: Enterprise end
applications/plat: Platform end
applications/fund: The capital side
applications/mina: Applet /h5
packages/utils: Util Package
packages/componets: General component package
packages/service: General service package
packages/openapi: Universal openapi Interface package
packages/constants: General constant package
packages/types: Generic type package
packages/styles: Generic style pack
packages/hooks: Universal hook bag

In the root directory package.json as follows :
{
"name": "",
"version": "1.0.0",
"description": "",
"main": "index.js",
"repository": "",
"author": "",
"license": "MIT",
"private": true,
"workspaces": [
"applications/*",
"packages/*"
],
"scripts": {
"build": "yarn workspaces run build",
"clean": "yarn workspaces run clean",
"lint:fix": "yarn workspaces run lint:fix",
"prettier:fix": "yarn workspaces run prettier:fix",
"ent": "yarn workspace @sunyard-fin/ent",
"fund": "yarn workspace @sunyard-fin/fund",
"plat": "yarn workspace @sunyard-fin/plat",
"mina": "yarn workspace @sunyard-fin/mina",
"components": "yarn workspace @sunyard-fin/components",
"constants": "yarn workspace @sunyard-fin/constants",
"openapi": "yarn workspace @sunyard-fin/openapi",
"service": "yarn workspace @sunyard-fin/service",
"types": "yarn workspace @sunyard-fin/types",
"styles": "yarn workspace @sunyard-fin/styles",
"utils": "yarn workspace @sunyard-fin/utils"
},
"devDependencies": {
"@commitlint/cli": "^17.0.3",
"@commitlint/config-conventional": "^17.0.3",
"eslint": "^8.15.0",
"husky": "^8.0.1",
"lint-staged": "^13.0.3",
"prettier": "^2.7.1",
"typescript": "^4.7.4",
"@antfu/eslint-config": "^0.23.0",
"eslint-plugin-prettier": "4.0.0",
"eslint-config-prettier": "8.5.0"
},
"husky": {
"hooks": {
"commit-msg": "commitlint -E HUSKY_GIT_PARAMS"
}
},
"lint-staged": {
"*.{md,json}": [
"prettier --write"
],
"*.{css,js,jsx,vue,ts,tsx}": [
"prettier --write",
"eslint --fix --cache"
]
}
}
There are several points that need to be noted here
Under the root directory, you should accompany the corresponding package directory
"workspaces": [
"applications/*",
"packages/*"
],
"build": "yarn workspaces run build",This sentence means to build and package all project packages"ent": "yarn workspace @sunyard-fin/ent",
After configuring the sentence upstairs , It's like a shortcut , You don't have to go into sub projects to run , Execute directly in the root directory yarn ent dev You can enter the development environment , It is equivalent to entering the subdirectory to execute yarn dev, Then you may see , The project name here does not have to be the same as the directory name , Use @xxx Does it feel more ceremonial .
For example, I want to add utils Bag words , It can be executed
yarn workspace @sunyard-fin/ent add @sunyard-fin/utils -D, Of course, you can also write directly to the corresponding project package.json InsideInstall a package for all projects , perform
yarn add -D -W typescript, This will install typescript package
Others are used normally yarn Come on .
summary
monorepo Suitable for large projects , combination yarn1.x The advantage of using is that you don't need to install dependencies for every project , This greatly reduces the volume of the project , Then the management code is more organized , Each module is much clearer , It also achieves high reusability .
FAQ
Why choose yarn1.x, Not having yarn2.x Do you ?
In fact, in the initial selection , I've also considered using pnpm、yarn2、lerna wait , Time is tight and task is heavy , I don't have much energy to research one by one , Take a cursory look yarn1.x It's enough for our current project , And there are no disadvantages in the introduction. At present , Then it is also naturally integrated , There is no need to add extra learning costs ,yarn2 It's also good , It's just that I set yarn set version berry It seems that I can't succeed without scientific self-improvement , Considering this is a team ( forehead , Although it's just me and another brother hahaha ), So I'm still quite modest and didn't use 2.x, Um. .
reference
MonoRepo: https://en.wikipedia.org/wiki/Monorepo
yarn2 workspaces: https://yarnpkg.com/features/workspaces
yarn1 workspaces: https://classic.yarnpkg.com/en/docs/workspaces
边栏推荐
- FreeBSD bNXT Ethernet driver source code reading record 2:
- 《nlp入门+实战:第三章:梯度下降和反向传播 》
- Google gson usage details
- Network performance evaluation tool ping/mtr
- What if win11 cannot open its own anti-virus software? Win11's built-in anti-virus function cannot be turned on
- 8、学习MySQL 创建数据表
- poj1521
- Docker高级篇-Mysql主从复制
- Nodejs builds cloud native microservice applications based on dapr, a quick start guide from 0 to 1
- Leetcode 537. complex multiplication (netizens' thoughts, ashamed)
猜你喜欢

NLP introduction + practice: Chapter 3: gradient descent and back propagation

FreeBSD bNXT Ethernet driver source code reading record 2:

Mulda: a multilingual data augmentation framework for low resource cross linguistic ner reading notes

Pycharm automatically adds header comments when creating py files

Fastjason handles generics

1.30 upgrade bin file, add suffix and file length

Codeforces Round #810 (Div. 2)A~C

1.30 升级bin文件添加后缀及文件长度
![[go] III. The simplest restful API server](/img/1f/f6fc8cc9a3891d01a25e709170188d.png)
[go] III. The simplest restful API server

The application and principle of changing IP software are very wide. Four methods of dynamic IP replacement are used to protect network privacy
随机推荐
What if win11 cannot open its own anti-virus software? Win11's built-in anti-virus function cannot be turned on
NIO简易示例
Prime Ring Problem
Kubernetes pod start process
MulDA: A Multilingual Data Augmentation Framework for Low-Resource Cross-Lingual NER 阅读笔记
Arthas watch 命令查看数组中对象的属性
ORACLE——iSupplier 门户开票错误
Arthas watch command to view the properties of objects in the array
NLP introduction + practice: Chapter 4: using pytorch to manually realize linear regression
Lua basic grammar
【ICKIM 2022】第四届知识与信息管理国际会议
1.30 升级bin文件添加后缀及文件长度
Network performance evaluation tool ping/mtr
Failed to load DLL
腾讯员工晒出薪资:真实985毕业薪资,大家看我还有救吗?网友:日薪?
Detailed explanation of redis data structure, combined with books
MDK compilation process and arm compilation tool chain
Is it safe to buy funds on e fund? Professional answers
What is informatization? What is digitalization? What are the connections and differences between the two?
Tutorial on the principle and application of database system (057) -- MySQL exercises