当前位置:网站首页>Yarn package management tool
Yarn package management tool
2022-06-13 08:39:00 【Medlar plus】
Introduce
The code passes package (package) ( Otherwise known as modular (module)) To share , A project may exist that depends on multiple packages , and yarn Namely factbook Launched an open source package management tool .
advantage
Fast : During installation, a local cache will be created for the installed package , So that the next time another project installs the same package, it can read directly from the cache
reliable : adopt yarn.lock To maintain the version of the package , This ensures that when a project reinstalls package dependencies in different environments , Ensure the consistency of versions .
Security : Check the integrity of the package through the algorithm .
install
Official website installation documents :https://yarn.bootcss.com/docs/install/#mac-stable
yarn command
1. Common commands ( remember )
yarn init | initialization yarn project , A... Will be created in the current directory package.json file |
yarn -V | see yarn edition |
yarn add [[email protected]] [--offline] | Install the specified version of the package --offline Is to install directly from the local cache |
yarn upgrade [[email protected]] | Update the package to the specified version |
yarn remove [[email protected]] | Remove the specified version of the package |
yarn/yarn install | according to package.json Install all dependent packages |
yarn ls | List all installed dependencies |
yarn publish | Read the current path package.json The content in , Release package . Generally, you will be asked to enter npm Your account and password |
yarn run/yarn xxx | If you are already in package.json It's defined in the file scripts, Then you can use this command to execute the specified [script] |
2. Other commands ( understand )
yarn cache ls | List locally cached dependent packages |
yarn cache clean | Clear the local cache of dependent packages |
yarn check [--integrity] | Verify the of the project package.json Whether the dependent version described in the file is the same as yarn.lock Consistent with the records in the document . --integrity Parameter can further verify whether the hash value matches |
yarn Profile description
1.package.json file
package.json The file stores all the dependencies of the project
1.1 name
The name of the package , Will be used in URLs, Command line arguments , and node_modules Directory name in , No uppercase letters , Do not point in English (.) Or underline (_) start .
yarn add [name] node_modules/[name] https://registry.npmjs.org/[name]/-/[name]-[version].tgz
1.2 version
Describe the version of the package .
1.3 scripts
scripts It is convenient for us to manage various scripts and other configurations that need to be run , Common examples are dev、build、lint etc. , We can go through yarn run <script> /yarn <script> To run various scripts .
"scripts": { "dev": "cross-env NODE_ENV=local node build/dev-server.js", "local": "cross-env NODE_ENV=local node build/dev-server.js", "build": "node build/build.js", "unit": "cross-env BABEL_ENV=test karma start test/unit/karma.conf.js --single-run", "e2e": "node test/e2e/runner.js", "test": "npm run unit && npm run e2e", "lint": "eslint --ext .js,.vue src test/unit/specs test/e2e/specs", "https": "cross-env NODE_ENV=local HTTP_TYPE=HTTPS node build/dev-server.js" },
1.4 dependencies
yarn The dependence is distinguished according to different situations , Common dependency configurations are as follows :
- dependencies: The dependencies that the configured package needs to add in the development and production environments , command :yarn add <package...>
- devDependencies: The configuration is the package that only needs to be depended on in the development environment , Will not be added to the production environment , command :yarn add <package...> --dev
- peerDependencies: The configuration dependency will be applied to the current component / The hosting environment of the plug-in , Remind them to check whether this installation has installed peerDependencies Dependency packages in , If not, a warning will be provided ️. For example, a project will introduce antd Components , During the installation process, if there is no dependency in our project dependency react, The following prompt will appear :

This is because antd Of package.json Configured in configuration peerDependencies, This reminds developers , Want to use antd, We need to rely on antd The dependent react. command :yarn add <package...> --peer

- optionalDependencies: Optional , If there is no optional package , Installation continues . command :yarn add <package...> --optional
- bundledDependencies: The value is an array of package names , These dependencies are bundled with the package when the package is released .
1.5 bundlesize
Set the maximum volume of the specified file when publishing . for example :
"bundlesize": [ { "path": "./dist/antd.min.js", "maxSize": "270 kB" }, { "path": "./dist/antd.min.css", "maxSize": "65 kB" }, { "path": "./dist/antd.dark.min.css", "maxSize": "67 kB" }, { "path": "./dist/antd.compact.min.css", "maxSize": "65 kB" } ],
1.6 keywords
The key words of the package , Other developers can search your package by keyword .
1.7 homepages
Home page of package , The home page should include an introduction to the package 、 Documents and other resources .
1.8 contributors
Contributors to the package , If other developers have contributed to your package , Then you can list these people in contributors in .
2.yarn.lock file
Stores the exact version of the dependent package , yes yarn Automatically generated , So we do not need to modify it manually , When we use yarn To add 、 upgrade 、 When deleting dependencies , It will update automatically yarn.lock.yarn.lock Should be submitted to the source repository , To ensure that the dependencies installed on the items pulled from the warehouse are consistent .
3.node_modules
node_modules The file stores the dependency packages we downloaded .
Information
yarn Github Address :https://github.com/yarnpkg
Chinese document :https://yarn.bootcss.com/docs/getting-started/
边栏推荐
- Document contains question type
- Microservice project construction III: automatic code generation
- In order to resist the flood, the soldiers have been fighting for 89 hours. How many days and hours are there in total?
- How to efficiently manage commodities and inventory in the beverage wholesale industry
- LVM management exercise
- MySQL parsing serialized fields
- VS安装VAssistX插件导致WPF-XAML文件输入中文出现乱码问题解决方案
- Buuctf web (VI)
- Emotion handling skills
- Filebeat collects logs to elk
猜你喜欢

JS - max. of array cases

Guidance process and service control

Which is the stronger fresh food distribution and sorting management system?

4、 Js-es5-i / O

Several precise order receiving methods suitable for fresh food wholesale industry

VS安装VAssistX插件导致WPF-XAML文件输入中文出现乱码问题解决方案

centos 安装mysql及设置远程访问

Start from scratch - implement the jpetstore website -1- establish the project framework and project introduction
![WARNING:tornado.access:404 GET /favicon.ico (172.16.8.1) 1.84ms [附静态文件设置]](/img/6d/6eef1f0ebcab45e9a209a3b6c62b03.png)
WARNING:tornado.access:404 GET /favicon.ico (172.16.8.1) 1.84ms [附静态文件设置]

Methods of importing and exporting settings in Altium Designer
随机推荐
VS安装VAssistX插件导致WPF-XAML文件输入中文出现乱码问题解决方案
Shellshock Attack Lab
logstash配置参考文章
WARNING:tornado. access:404 GET /favicon. ICO (172.16.8.1) 1.84ms [with static file settings]
filebeat采集日志到ELK
Homestead environment setup
Input prohibit copy and paste
浅析Visual Studio 使用
PHP isset() method ignores data error handling caused by null parameter value
Phpexcel 10008 error resolution
Is there any good management software to solve the problems faced by tea wholesalers
JS - max. of array cases
Vs installation of vassistx plug-in causes Chinese input of wpf-xaml file to be garbled. Solution
Methods of importing and exporting settings in Altium Designer
微服务项目搭建二:数据库设计
How to download and install stm32cubemx
JS - print 99 multiplication table of the for cycle case
HCIP_ OSPF irregular area
Filebeat collects logs to elk
Buuctf web (IV)