Yii Framework Forum: Why asset converters cannot work with asset source path? - Yii Framework Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • This topic is locked

Why asset converters cannot work with asset source path? Rate Topic: -----

#1 User is offline   Ertong 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 3
  • Joined: 27-June 13

Posted 30 March 2015 - 09:59 AM

interface AssetConverterInterface
{
    /**
     * Converts a given asset file into a CSS or JS file.
     * @param string $asset the asset file path, relative to $basePath
     * @param string $basePath the directory the $asset is relative to.
     * @return string the converted asset file path, relative to $basePath.
     */
    public function convert($asset, $basePath);
}


For example, I use less for my styles. And I need to convert them to css.
Current implementation forces me to copy less sources to assets directory and convert them, after that.
The directory is published based on its timestamp.

So if my less file is changed, directory timestamp is not changed and I need to delete assets or set forceCopy to true in AssetManager in order to see my changes.

In production it is not a problem to delete assets after update. But in development it is not possible to change less file, press "refresh" is the browser and see the results.

I propose to pass one more parameter to this function with AssetBundle object. It will allow to immplement any logic on converter side. In current architecture is is not possible, because convert() is called from AssetBundle, which cannot be overrided for all bundles at once.
0

#2 User is offline   phtamas 

  • Master Member
  • PipPipPipPip
  • Yii
  • Group: Members
  • Posts: 777
  • Joined: 26-February 11
  • Location:Mezőtúr, Hungary

Posted 31 March 2015 - 10:43 AM

View PostErtong, on 30 March 2015 - 09:59 AM, said:

I need to [...] set forceCopy to true in AssetManager in order to see my changes.


What's the problem with that?
0

#3 User is offline   Ertong 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 3
  • Joined: 27-June 13

Posted 31 March 2015 - 10:55 AM

It is very slow. It requires building of all assets, even if they are not changed. I'm not even saying about copying.
On my machine and project it takes approximately 15 sec/request. It is not very critical, but slows down the development.

Ofcourse, SSD, more memory, more CPU, tuned environment can solve a problem at least partially, but not always affordable.
0

#4 User is offline   phtamas 

  • Master Member
  • PipPipPipPip
  • Yii
  • Group: Members
  • Posts: 777
  • Joined: 26-February 11
  • Location:Mezőtúr, Hungary

Posted 01 April 2015 - 02:05 AM

15 sec/request is way too long, indeed. Before switched to Grunt I have used the forceCopy => true setting (in the development environment, of course) and it never took noticeable amount of time to publish assets on an absolutely average PC. Maybe your application requires much more asset processing than mine did.

Using an external tool like Grunt (which - as you would expect from a dedicated build tool - is much more configurable/customizable than AssetManager) or an IDE plugin for less compilation and skipping asset publishing by working directly in a web-accessible directory isn't an option for you? Yii's asset publishing is more suited for reusable extensions than applications.
0

#5 User is offline   Ertong 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 3
  • Joined: 27-June 13

Posted 01 April 2015 - 04:52 AM

It is an option in some extent. But some files are in those "reusable extensions" and it would be nice not to completely destroy and idea of assets.
0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • This topic is locked

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users