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

Viewed 3904

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?

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'],
            ],
        ],
    ],
],
Related