New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[WIP] New asset management #4855
Conversation
@@ -89,16 +89,16 @@ following way: | |||
```php | |||
class LanguageAsset extends AssetBundle | |||
{ | |||
public $language; | |||
public static $language; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why static?
Why it was changed overall ? Does other fw use |
Amount of steps will be the same when it will be bound to Composer. |
no, now i need to install |
It's extremely easy using both Windows, MacOS and Linux. Easier than installing Composer actually. |
i am not sure what is overall profit ? only switching |
It's all described in asset-related issues. But here's the summary of two main reasons:
|
So now when creating extension everyone should mention it in packagist and in bower packages ? is not it too much ? |
Not if your extension uses third party JS instead of your own. |
so bower actually installs all packages in some other directory, and in our extendsions and widgets we should somehow link to it with aliases ? should we create |
Check the code. |
from where |
@qiangxue can you clarify overall advantages ( just interesting ) ? and what advantage of |
@Ragazzo Mark, it's a step forward, could you present any benefit in not using bower? A positive effect of sticking with previous situations, apart from |
So what are real advantages and |
Again, it was all discussed and answered: |
@samdark the solution with
seems very hacky to me, all this unneeded prefixes and suffixes . Whatever overall |
That's why current approach is different while it solves the same problems. |
Ok , thank you |
I am no expert at Bower, but as I see it behaves similar to Composer, placing all packages files under particular directory. I don't lilke the idea of entire loosing ability to specify assets from extension local directory. This ability is very usefull while creating java script solutions, which are specific for the particular project. For example: I often create a custom widget to encapsulate complex catalog filter, which uses JavaScript and Ajax for funcy effects. During this process I create JQuery component named like 'itemFilter' and place it in the separated js file. It makes no sense for mwe to create a separated bower package to store it, because it is unlikely will be used anywhere else, but I still want my Widget to publish my js and include it to the page. Current fix makes this not possible. |
yes , i also support |
Well, pardon we if I am wrong, but as see from the soure code of this PR |
I updated the description of this PR trying to clarify some of your concerns. If you still have concerns, please feel free to keep discussing about them here. Yes, this change is very significant and may require change of your previous development habit, but I feel it is necessary and we are on the right direction |
@klimov-paul so other fw works fine and |
I have never told we should not move on. Usage of Bower (or its analog) is nice modern feature, which should be present - we have decided this already.
At the present state this is done automatically. When I want ot use a widget, which requires specific asset file(s) I do not need any special actions - I just put it into the view code, and does everything else without me. With this change I have to run bower (or "specific console command") before I can really use a widget. I just imagine numerous complains about "widget XXX not working" we will receive afterwards.
Here is JS related to this widget: |
Ah , i see your point , true and valid though |
Maybe I'm getting something wrong, but creating a bower package for every asset bundle sounds really uncomfortable to me. In my opinion the previous pattern was more sound. Also having to convince our systems architect, that to run Yii2 we need node.js installed, because asset management has to be done via bower — does not sound like much fun. I would not argue, that the option to manage assets via bower is a great optional feature, but, in my opinion, it ought to remain an optional feature, not one of core requirements. |
@klimov-paul your use case is valid but only till the project goes production where you'll combine/compress all JavaScript to For extensions we can add a special composer.json command that copies (or symlinks) assets at installation same way as it's now changing permissions. If there's a bower packages it could run bower command as well. It will solve a problem with immediate extension usage. @U-D13 you can use http://bowerphp.org/ if your architect absolutely insists about avoiding node. The main reason for it is that if we'll use bower, extension authors will have proper dependencies so you won't end up with two jQueryUI included by two different extensions. |
Current implementation covers compoistion of the source files for such compression, which this PR removes.
I am talking not only about extensions. I am talking about widgets and modules, which developer may create for the particular project My opinion, with this PR we throwing ourthelves from one edge to another. |
Any idea on how to take the best from both approaches while keeping extension authors from using common library JS/CSS from bower? |
I have posted it at my first enty in this disscussion: We may created a specific alias named So class JqueryAsset extends AssetBundle
{
public $sourcePath = '@vendor/yiisoft/jquery';
public $js = [
'jquery.js',
];
} to: class JqueryAsset extends AssetBundle
{
public $sourcePath = '@bower/dist/jquery';
public $js = [
'jquery.js',
];
} |
Better even use class JqueryAsset extends AssetBundle
{
public $baseUrl = '@bower/dist/jquery';
public $js = [
'jquery.js',
];
} Since |
@qiangxue what do you think about what @klimov-paul proposes? |
@samdark I was having a discussion with our sysarchitect right while I was writing that comment, and "there's also BowerPHP," was his exact words, "but it does not work properly". BowerPHP is alpha, not something one would want to rely on in a production environment. |
@U-D13, you may compose your deployment process in a way production server will not call Bower. Such problems can be solved. |
Yes, perhaps we should bring back asset publishing because based on the feedback, it seems many developers are relying on this feature implicitly or explicitly. We may also need to put 3rd party asset libs under Regarding the dependency on bower/npm, I have evaluated bowerphp. Unfortunately, it has a lot of issues and is not usable. So now we are counting on https://github.com/francoispluchino/composer-asset-plugin/, which based on its documentation is very promising. It will eliminate the requirement of installing nodejs/bower and making installing an extension just like a regular composer package. |
This is awesome! |
@creocoder for francoispluchino/composer-asset-plugin:
The package cleanup after install is supported for bower asset. Only bower script is not supported.
For use the plugin in project mode (webroot), the PR composer/composer#3082 has a status 'feature' and should be merged. Currently, the plugin has only 39 stars, which is low, but if you include the plugin in the framework, this digit will increase rapidly. Of course I am open to any suggestions to improve the plugin. |
@francoispluchino Thank you for your comment. I tried your plugin, and it worked great! I'm now eagerly looking forward to seeing its project mode support getting merged soon. This will make everything transparent to end users. |
$asset = $bundle->sourcePath . '/' . $asset; | ||
} | ||
|
||
$n = strlen($asset); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Directory may contain non-latin characters so mb_strlen
should be used instread of strlen
.
@qiangxue have not read it but maybe interesting information: composer/composer#3078 (comment) |
Conflicts: apps/basic/composer.json composer.json
…ugin to manage the dependencies on 3rd-party JS libraries
@francoispluchino FYI, yii2 master is now using your plugin to manage the asset package dependencies. So far it worked very well in my personal tests. Great job! |
Fixes #4454
Problems being addressed
Most css/js libs are not registered as Composer packages. As a result, if an extension has dependency on them, it becomes very troublesome to install the extension. As an example, the
yii2-jui
extension is including the whole JUI lib because there is no JUI composer package. And because of this, it is possible that two extensions are using different ways to reference the same 3rd party js lib and thus cause double inclusion of the same js file.Current status
Basic app (including debugger and gii) can work running the following composer commands:
Tasks to be done
asset
command to support asset bundle listing and asset combining/compression via grunt and other tools (may postpone this task to 2.0.1)Summary of changes
@bower
and@npm
aliases to refer to the directories that should be used to install bower and npm packages, respectively.Assets specific to application
Put the assets under a Web folder, and declare them in one or multiple asset bundle classes. For an example, see https://github.com/yiisoft/yii2/blob/new-asset/apps/basic/assets/AppAsset.php
Assets for non-redistributable widgets/modules
Put the assets under either a Web folder or the directory containing the widget/module class file. If the latter, make sure you specify
AssetBundle::sourcePath
so that the assets can be published when being used.Assets for extensions
Put the assets in a directory (e.g.
assets
) under the extension base path. List them in a bundle class and make sure you setAssetBundle::sourcePath
to be@vendor/PackageName/assets
.Third-party assets
If your application or extension uses a third-party asset package, do these steps:
AssetBundle::sourcePath
to be@bower/PackageName
, if the third-party package is a bower package (@npm/PackageName
for npm packages,@vendor/PackageName
for Composer packages).composer.json
of your application/extension, list the third-party package as a dependency.