{"action":"created","issue":{"url":"https://api.github.com/repos/yiisoft/yii2/issues/10605","labels_url":"https://api.github.com/repos/yiisoft/yii2/issues/10605/labels{/name}","comments_url":"https://api.github.com/repos/yiisoft/yii2/issues/10605/comments","events_url":"https://api.github.com/repos/yiisoft/yii2/issues/10605/events","html_url":"https://github.com/yiisoft/yii2/issues/10605","id":127223094,"number":10605,"title":"Better vendor / asset path finding.","user":{"login":"SamMousa","id":547021,"avatar_url":"https://avatars.githubusercontent.com/u/547021?v=3","gravatar_id":"","url":"https://api.github.com/users/SamMousa","html_url":"https://github.com/SamMousa","followers_url":"https://api.github.com/users/SamMousa/followers","following_url":"https://api.github.com/users/SamMousa/following{/other_user}","gists_url":"https://api.github.com/users/SamMousa/gists{/gist_id}","starred_url":"https://api.github.com/users/SamMousa/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/SamMousa/subscriptions","organizations_url":"https://api.github.com/users/SamMousa/orgs","repos_url":"https://api.github.com/users/SamMousa/repos","events_url":"https://api.github.com/users/SamMousa/events{/privacy}","received_events_url":"https://api.github.com/users/SamMousa/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":2,"created_at":"2016-01-18T13:08:24Z","updated_at":"2016-01-18T13:17:04Z","closed_at":null,"body":"Currently Yii2 offers no way to automatically \"find\" the vendor path.\r\n\r\nBasically there are 2 options:\r\n1. Put it in the default location.\r\n2. Put it somewhere else and set the path in the configuration.\r\n\r\nI think I have found an alternative (https://github.com/francoispluchino/composer-asset-plugin/issues/183):\r\n\r\n````\r\n$vendorPath = dirname(dirname((new \\ReflectionClass(\\Composer\\Autoload\\ClassLoader::class))->getFileName()))\r\n````\r\n\r\nThis way we can always find the vendor path and when we reconfigure composer.json we do not have to reconfigure the application.\r\n\r\nWe could even go one step further and set the aliases `@bower` and `@npm` more intelligently by just reading the `installed.json` file in the composer directory. (This is what is done in the Symfony bundle https://github.com/francoispluchino/FxpRequireAssetBundle)\r\n\r\n\r\nPros:\r\n1. Less configuration\r\n2. More robust\r\n\r\nCon:\r\n1. Theoretically a little less performant since installed.json gets read on each request.\r\n\r\n-- Note, I did some tests on a real installed.json file for a yii2 project, size about 160KB, running on core i2500k inside a homestead vm, got the following results doing 20 iterations of 1000 loads:\r\n````\r\nAverage 1000x: 1.6277709126472\r\nMax 1000x: 1.7626240253448\r\nMin 1000x: 1.5363171100616\r\n````\r\nSo basically this would add about `2ms` to page load times.\r\n"},"comment":{"url":"https://api.github.com/repos/yiisoft/yii2/issues/comments/172524844","html_url":"https://github.com/yiisoft/yii2/issues/10605#issuecomment-172524844","issue_url":"https://api.github.com/repos/yiisoft/yii2/issues/10605","id":172524844,"user":{"login":"francoispluchino","id":567393,"avatar_url":"https://avatars.githubusercontent.com/u/567393?v=3","gravatar_id":"","url":"https://api.github.com/users/francoispluchino","html_url":"https://github.com/francoispluchino","followers_url":"https://api.github.com/users/francoispluchino/followers","following_url":"https://api.github.com/users/francoispluchino/following{/other_user}","gists_url":"https://api.github.com/users/francoispluchino/gists{/gist_id}","starred_url":"https://api.github.com/users/francoispluchino/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/francoispluchino/subscriptions","organizations_url":"https://api.github.com/users/francoispluchino/orgs","repos_url":"https://api.github.com/users/francoispluchino/repos","events_url":"https://api.github.com/users/francoispluchino/events{/privacy}","received_events_url":"https://api.github.com/users/francoispluchino/received_events","type":"User","site_admin":false},"created_at":"2016-01-18T13:17:04Z","updated_at":"2016-01-18T13:17:04Z","body":"As I indicated in francoispluchino/composer-asset-plugin#183, I will create a small library for performing this task, with the ability to cache the analysis.\r\n\r\nSo, @qiangxue, @cebe, @samdark if you're interested ..."}}