Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I update jquery to version 3.* in yii2 project using composer

I have a project which is working off of yii2's advanced template. When I checked the version of jquery in vendor/bower/jquery/dist/jquery.js the current version is 2.2.4. I want to update this version to version 3.2.1 but doing a composer update doesn't seem to update my bower assets. I tried setting composer global require "fxp/composer-asset-plugin:>=1.3.1" and then ran composer update again but no luck. The jquery version is still 2.2.4.

Is there something I'm missing?

like image 711
natral Avatar asked Dec 18 '22 06:12

natral


2 Answers

You don't actually need to use composer for switching to newer jQuery version. By configuring yii\web\JqueryAsset you can override loaded jQuery library at your wish, e.g.

in /config/main.php:

...
'components' => [
    'assetManager' => [
        'bundles' => [
            'yii\web\JqueryAsset' => [
                'js' => [YII_DEBUG ? 'https://code.jquery.com/jquery-3.2.1.js' : 'https://code.jquery.com/jquery-3.2.1.min.js'],
                'jsOptions' => ['type' => 'text/javascript'],
            ],
        ],
    ],
],
like image 96
lubosdz Avatar answered Jan 05 '23 16:01

lubosdz


The problem is that the Yii2 framework has a dependency defined in its own composer file /vendor/yiisoft/yii2/composer.json file that looks like this:

"bower-asset/jquery": "2.2.*@stable | 2.1.*@stable | 1.11.*@stable | 1.12.*@stable"

Basically that restricts the jQuery version for your application.

Unfortunately, I can't see how to get around this issue right now. But there is already an issue raised on GitHub for it and the Milestone is set to 2.0.13 so hopefully it'll be updated then: https://github.com/yiisoft/yii2/issues/14338

like image 34
BlueZed Avatar answered Jan 05 '23 17:01

BlueZed