Is it possible to copy assets from development to prod and never regenerate them?

Hello Yii Community,

I have developed an app in Yii 2 and everything is fine in development. However, the hosting company my client is contracted with is very bad. Folders created by PHP on their system are not visible to me in any way, although I can tell they are there because I am unable to create them manually. There is no shell access. My client is funded in such a way that ongoing services like hosting are difficult for them to contract. They are well funded otherwise. So I am in this dilemma.

Is there any way to copy the assets from my development environment and never regenerate them on the production server? I would like to take care of this without any friction on my client.



You can configure the asset manager to link the assets:

    	'assetManager' => [

        	'linkAssets' => true,



And then, in the AppAsset, set the sourcePath:


namespace app\assets;

use yii\web\AssetBundle;

class AppAsset extends AssetBundle


	public $sourcePath = '@app/assets/dist';

	public $css = [

    	YII_ENV_DEV ? 'css/all.css' : 'css/all.min.css'


	public $js = [

    	YII_ENV_DEV ? 'js/all.js' : 'js/all.min.js',

    	YII_ENV_DEV ? 'yii/all.js' : 'js/yii.min.js'



Then, Yii will generate an asset directory, but it will be a symlink.

I am not sure if this is what you want? Or if it will be useful.

You should be able to see the asset directory, because you put it there.

If you don’t want bundles, you can turn them off in the assetmanager configuration, individually.

For instance:

        	'bundles' => [

            	'yii\bootstrap\BootstrapAsset' => false,

            	'yii\validators\ValidationAsset' => false,

            	'yii\web\YiiAsset' => false,

            	'yii\widgets\ActiveFormAsset' => false,

            	'yii\bootstrap\BootstrapPluginAsset' => false,

            	'yii\web\JqueryAsset' => false,

            	//'yii\authclient\widgets\AuthChoiceAsset' => false, //authchoice.js

            	//'yii\authclient\widgets\AuthChoiceStyleAsset' => false, //authchoice.css


Just want to add that the point of doing this is to use AppAsset without actually publishing any assets.

I also have

     		'appendTimestamp' => true,

in the asset manager configuration array, so the "asset link" looks like a normal asset link, and changes timestamp whenever the assets are changed (by me, not by Yii).


<link href="/assets/d54bbca/css/all.min.css?v=1484742742" rel="stylesheet">

That is a symlink pointing to assets/dist/css/all.min (outside of the web directory, obviously).

Alternatively, turn off bundles altogether, and don’t use AppAsset at all.

    	'assetManager' => [

        	'bundles' => false,

See the guide:

I think this is the approach I am going to have to take if there is no way to copy the assets to production. So links will have the same issues as folders.

I do not completely understand how asssets work, in particular widgets and assets. I’ll probably just parse the URL in order to decide what to load in my layout and turn AppAsset off.

Sure would be nice if I could copy them over and forget about it though.

Thanks for your input.

The reason why I am using assets is that it allows me to have Yii generate a link so that I can have them outside of the webroot, making things a bit cleaner.

The ‘linkAssets’ setting does not really publish, a link is the only thing that appears in webroot/assets.

But if you just put it in the webroot manually, then it should also work.

Provided that you don’t use assets in your views.

I don’t wholly understand assets, but they allow both your application and third-party extensions to put their assets where the webserver can access them.

And it also handles versioning and prevents name collisions…