PHPackages                             ischenko/yii2-jsloader-requirejs - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Templating &amp; Views](/categories/templating)
4. /
5. ischenko/yii2-jsloader-requirejs

ActiveYii2-extension[Templating &amp; Views](/categories/templating)

ischenko/yii2-jsloader-requirejs
================================

An Yii2 extension that allows to handle asset bundles via requirejs

v1.2.1(6y ago)5812MITPHPPHP &gt;=7.1

Since Oct 28Pushed 6y ago2 watchersCompare

[ Source](https://github.com/ischenko/yii2-jsloader-requirejs)[ Packagist](https://packagist.org/packages/ischenko/yii2-jsloader-requirejs)[ RSS](/packages/ischenko-yii2-jsloader-requirejs/feed)WikiDiscussions master Synced 2mo ago

READMEChangelog (4)Dependencies (7)Versions (5)Used By (0)

yii2-jsloader-requirejs
=======================

[](#yii2-jsloader-requirejs)

[![Latest Stable Version](https://camo.githubusercontent.com/7cf21cc04befae95ed0f2ec6d75d88b0485f5927e95a7b75fc40cfd75656f799/68747470733a2f2f706f7365722e707567782e6f72672f69736368656e6b6f2f796969322d6a736c6f616465722d726571756972656a732f762f737461626c65)](https://packagist.org/packages/ischenko/yii2-jsloader-requirejs)[![Total Downloads](https://camo.githubusercontent.com/19c06c4e1bd54f34ab1f86b4c8f58a4196d81e47807520859847cabf1cbaa468/68747470733a2f2f706f7365722e707567782e6f72672f69736368656e6b6f2f796969322d6a736c6f616465722d726571756972656a732f646f776e6c6f616473)](https://packagist.org/packages/ischenko/yii2-jsloader-requirejs)[![Build Status](https://camo.githubusercontent.com/73e85890787a0c306a68aaa5ce5f7f2951b0dda8d3e6b3a0cd1adae790f5e6ad/68747470733a2f2f7472617669732d63692e6f72672f69736368656e6b6f2f796969322d6a736c6f616465722d726571756972656a732e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/ischenko/yii2-jsloader-requirejs)[![Code Climate](https://camo.githubusercontent.com/e9781c2f7d88f93a83b34107ad43ea20b78fbd7f7f5e2101cf82b6a5f22beffe/68747470733a2f2f636f6465636c696d6174652e636f6d2f6769746875622f69736368656e6b6f2f796969322d6a736c6f616465722d726571756972656a732f6261646765732f6770612e737667)](https://codeclimate.com/github/ischenko/yii2-jsloader-requirejs)[![Test Coverage](https://camo.githubusercontent.com/a54702784f9195efe27ecf4fb2480ec10a9133cbf47d18f2e22eee852d209f1e/68747470733a2f2f636f6465636c696d6174652e636f6d2f6769746875622f69736368656e6b6f2f796969322d6a736c6f616465722d726571756972656a732f6261646765732f636f7665726167652e737667)](https://codeclimate.com/github/ischenko/yii2-jsloader-requirejs/coverage)[![License](https://camo.githubusercontent.com/e81e0364cf289b75e1eb556a06dcefe3b470e4a8a0f24ebf0682642edf17b486/68747470733a2f2f706f7365722e707567782e6f72672f69736368656e6b6f2f796969322d6a736c6f616465722d726571756972656a732f6c6963656e7365)](https://packagist.org/packages/ischenko/yii2-jsloader-requirejs)

An Yii2 extension that allows to register asset bundles as [RequireJS](http://requirejs.org) modules.

Installation
------------

[](#installation)

\*Requires PHP &gt;= 7.1

\*Requires [ischenko/yii2-jsloader](https://github.com/ischenko/yii2-jsloader) &gt;= 1.2

The preferred way to install this extension is through [composer](http://getcomposer.org/download/).

Either run

```
composer require ischenko/yii2-jsloader-requirejs

```

or add

```
"ischenko/yii2-jsloader-requirejs": "*"
```

to the `require` section of your composer.json.

Usage
-----

[](#usage)

Add the [behavior](https://github.com/ischenko/yii2-jsloader#usage) and requirejs loader to the view configuration

```
    ...
    'components' => [
        ...
        'view' => [
            'as jsLoader' => [
                'class' => 'ischenko\yii2\jsloader\Behavior',
                'loader' => [
                    'class' => 'ischenko\yii2\jsloader\RequireJs',
                ]
            ]
        ]
        ...
    ]
    ...
```

Modules configuration accepts options described in [RequireJS API docs](http://requirejs.org/docs/api.html#config). It is also possible to set aliases for modules, for example:

```
    ...
    'components' => [
        ...
        'view' => [
            'as jsLoader' => [
                'class' => 'ischenko\yii2\jsloader\Behavior',
                'loader' => [
                    'config' => [
                        'shim' => [
                            'yii\web\JqueryAsset' => [
                                'exports' => 'jQuery'
                            ],
                            'app\assets\jQueryFireflyAsset' => [
                                'deps' => ['yii\web\JqueryAsset']
                            ]
                        ],
                        'aliases' => [
                            'yii\web\JqueryAsset' => 'jq',
                            'app\assets\jQueryFireflyAsset' => 'jqff'
                        ]
                    ],
                    'class' => 'ischenko\yii2\jsloader\RequireJs',
                ]
            ]
        ]
        ...
    ]
    ...
```

Or you can set alias, exports, init options from asset bundle:

```
class jQueryFireflyAsset extends AssetBundle
{
    public $js
        = [
            'jquery.firefly.min.js'
        ];

    public $jsOptions
        = [
            'requirejs' => [
                'alias' => 'jqff',
                //'init' => 'function(jQuery) { /* do some init here */ }'
                //'exports' => 'some-exported'
            ]
        ];

    public $depends
        = [
            'yii\web\JqueryAsset',
        ];

//    public function registerAssetFiles($view)
//    {
//        parent::registerAssetFiles($view);

//        $this->jsOptions['requirejs']['init'] =
