I have successfully installed npm-asset/socket.io package and its dependencies by using Asset Packagist in yii2. Now, I cannot include it in my pages. I tried in AppAsset.php like this:
public $js = ['@npm/socket.io/client-dist/socket.io.js'];
Keep in mind that in your Asset config, the @alias attribute should be used in the $basePath class variable, while the alias must be properly configured.
For more detailed explanation in assets, you can read this article: Yii2 Assets
I have created a separate class for the specific package like this:
namespace app\assets;
use yii\web\AssetBundle;
class SocketIOAsset extends AssetBundle
{
public $sourcePath = "@npm/socket.io-client/dist";
public $css = [];
public $js = [
'socket.io.js'
];
}
and then called in main assets file
public $depends = [
‘yii\web\YiiAsset’,
‘yii\bootstrap\BootstrapAsset’,
SocketIOAsset::class
];