yii2-gii icon indicating copy to clipboard operation
yii2-gii copied to clipboard

cannot change asset

Open yurii-github opened this issue 8 years ago • 6 comments

I have removed bower, I want to use custom js etc. I do replace all framework assets in config like

		'assetManager' => [
			//'appendTimestamp' => true,
			'converter' => [
				'class' => 'yii\web\AssetConverter'
			],
			'class' => 'app\components\AssetManager',
			'linkAssets' => false, //symblic linking
			'basePath' => '@webroot/assets',
			'bundles' => [
			  // reset Yii2 
			  'yii\web\YiiAsset' => [ 'sourcePath' => null, 'js' => [] ],

but Gii generates error 'the file or directory to be published does not exist: ...vendor/bower-asset/jquery/dist'

If I run in bootstrap this line of code

final class MyLibraryBootstrap implements BootstrapInterface
{
	/**
	 * (non-PHPdoc)
	 *
	 * @see \yii\base\BootstrapInterface::bootstrap()
	 * @param $app \yii\web\Application        	
	 */
	public function bootstrap($app)
	{
	  $app->view->registerAssetBundle(\yii\web\JqueryAsset::class);

this error gets fixed. How can I make Gii read my config in first place?

regards

yurii-github avatar Feb 25 '17 20:02 yurii-github

The problem in your case is that YiiAsset depends on another asset called JqueryAsset which you should override in config as well.

samdark avatar Feb 25 '17 21:02 samdark

I didn't copy that part of config, my bad

			'bundles' => [
			  // reset Yii2 
			  'yii\web\YiiAsset' => [ 'sourcePath' => null, 'js' => [] ],
			  'yii\web\JqueryAsset' => [ 'sourcePath' => null, 'js'=> [] ],
			  'yii\bootstrap\BootstrapAsset' => [ 'sourcePath' => null,
			    'css' => [] // ['https://maxcdn.bootstrapcdn.com/bootstrap/3.3.4/css/bootstrap.min.css'],
			  ],
			  'yii\bootstrap\BootstrapPluginAsset' => [
			    'sourcePath' => null, 'js' => []
			    //'js' => ['https://maxcdn.bootstrapcdn.com/bootstrap/3.3.4/js/bootstrap.min.js']
			  ],
			  'yii\gii\TypeAheadAsset' => [ 'sourcePath' => null ]
			]
		],

yurii-github avatar Feb 26 '17 14:02 yurii-github

So that's still a problem with the config above?

samdark avatar Feb 26 '17 14:02 samdark

yes, it was like this before, I just didn't copy whole config. Pushed my code, here it is

config https://github.com/yurii-github/yii2-mylib/blob/category/app/config/config.php app asset https://github.com/yurii-github/yii2-mylib/blob/category/app/assets/App.php (forces load from config in Gii module)

or another way is to force load in bootstrap component https://github.com/yurii-github/yii2-mylib/blob/category/app/components/MyLibraryBootstrap.php

I thought that module should catch main config or not?

regards

yurii-github avatar Feb 26 '17 15:02 yurii-github

Overwriting global bundles configuration wont work, as gii resets it: https://github.com/yiisoft/yii2-gii/blob/master/src/Module.php#L135

/**
 * Resets potentially incompatible global settings done in app config.
 */
protected function resetGlobalSettings()
{
    if (Yii::$app instanceof \yii\web\Application) {
        Yii::$app->assetManager->bundles = [];
    }
}

kasparsklavins avatar Jan 18 '19 09:01 kasparsklavins

This is also a problem in using npm assets. this my code which produce the same problem.

`$config['bootstrap'][] = 'gii';
$config['modules']['gii'] = [
    'class' => 'yii\gii\Module',
    // uncomment the following to add your IP if you are not connecting from localhost. By default localhost is allowed.
    //'allowedIPs' => ['127.0.0.1', '::1'],
    'components' => [
        'assetManager' => [
            'class' => 'yii\web\AssetManager',
            'linkAssets' => true,
            'forceCopy' => false,
            'appendTimestamp' => true,
            'bundles' => [
                'yii\web\JqueryAsset' => [
                    'sourcePath' => '@npm/jquery/dist',
                    'js' => [
                        YII_ENV_DEV ? 'jquery.js' : 'jquery.min.js'
                    ]
                ],
            ],
            ],
        ],
];

` and i get similar error of The file or directory to be published does not exist: C:\vhosts\kassem.local\project\config/../../vendor/bower-asset/jquery/dist

esaesa avatar Sep 28 '19 22:09 esaesa