Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How YII2 optimizes vendor through composer

2025-02-21 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/02 Report--

This article introduces the relevant knowledge of "how YII2 optimizes vendor through composer". In the operation of actual cases, many people will encounter such a dilemma, so let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!

Frame installation problem

There is a common problem in the Yii2 community, that is, after installing the officially recommended version

1 Why is there no vendor folder?

In Yii2, vendor is a dependent library file downloaded by composer, the official project template code only has its own project file, and the dependent yii framework and other class libraries are recorded in composer.json, as long as composer is installed, and then install or update can be.

2 in the self-installed Yii2 project, the packages in vendor cannot be found in composer.json, and most of these packages are not needed for the time being, how to remove and keep vendor to a minimum?

2.1 deleting a package using composer remove

Deleted packages must be recorded in the composer.json under the vendor folder, and all packages will be reinstalled when the package is deleted.

2.2 use composer update-- no-dev to delete a package

The package in development mode will be deleted directly, run the project after deletion, and report an error directly. Therefore, all packages in the development mode cannot be deleted.

Vendor.jpg

Composer.jpg

2.3 delete packages using remove codeception/verify, most of the packages in test mode are deleted. According to my previous development experience, the components related to unit testing are not used, so you can simplify the compposer package of Yii2 with the remove codeception/verify command. This command is a key part of optimizing the composer package.

When more than 3 projects are under one project, will there be performance problems caused by loading too many composer packages for the first time? can the self-contained delayed loading solve this problem?

Components that are obviously not needed by the project can be disposed of directly by remove, and the performance impact has not been encountered yet. Deferred loading is a framework-level optimization, and I choose to believe in its ability.

4 vendor path problem

There is no prompt for directories or files caused by vendor path problems

Suppose our project path is E:\ sources\ templates

When there is a problem with the Vendor path, a similar problem occurs, that is, a composer package does not exist

Invalid Parameter-yii\ base\ InvalidParamException

The file or directory to be published does not exist: e:\ sources\ templates\ backend\ vendor\ bower-asset/jquery/dist

The fact that the package does not exist is just performance, mainly because the vendor path does not correspond to the configuration file of the project.

Under the project's main configuration file main.php, there is a configuration entry for vendor and the specific value of VendorPath. To combine the path of the configuration file, please refer to the following two figures and the related path configuration.

The first one

VendorPath.jpg

'vendorPath' = > dirname (dirname (DIR)). '/ vendor'

The second picture

VendorPath3.jpg

VendorPath' = > dirname (DIR). '/ vendor'

Summary

There are three issues we need to consider when using compser

1 the difference between composer install and composer update

2 composer version management and stability

3 how to output and maintain common components in the form of composer packages

Composer install

Should be the most commonly used command, composer will install the package according to the local composer.json, put the downloaded package into the vendor directory of the project, and put the installation package version information into composer.lock in order to lock the version.

In fact, in install, if you find that the version of composer.lock is the same as the version of the code in the current vendor directory, Composer will do nothing. The purpose of composer.lock is to make you feel at ease working in the current version without getting the latest version of the package.

Composer update

The package version in the composer.lock file is updated, and all packages recorded by composer.json are updated.

This command should be used with caution.

If the component has been referenced into the project using composer and becomes a public component, you need to use the composer command carefully. Of course, you need to be responsible for maintenance and do not set the permission for sharing operations.

Another way of thinking can also be tried, for the version of the software installation package, unified to the latest official version, if the resulting compatibility or other problems, targeted to solve new problems.

This is the end of "how YII2 optimizes vendor through composer". Thank you for reading. If you want to know more about the industry, you can follow the website, the editor will output more high-quality practical articles for you!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report