ischenko/yii2-jsloader

An Yii2 extension designed to handle JS files, code and asset bundles via various js loaders

Installs: 1 063

Dependents: 2

Suggesters: 0

Security: 0

Stars: 1

Watchers: 1

Forks: 1

Open Issues: 0

Type:yii2-extension

v1.3.2 2020-03-18 13:34 UTC

This package is auto-updated.

Last update: 2024-11-18 23:23:49 UTC


README

Latest Stable Version Total Downloads Build Status Code Climate Test Coverage License

An extension provides behavior which allows to process js files, code and asset bundles by various js loaders such as RequireJS.

Along with behavior it provides a set of interfaces and base classes for implementing a js loader.

Currently available implementations of js loaders are:

Installation

*Requires PHP >= 7.1

The preferred way to install this extension is through composer.

Either run

composer require ischenko/yii2-jsloader

or add

"ischenko/yii2-jsloader": "*"

to the require section of your composer.json.

Usage

Add the behavior and concrete loader implementation to a view configuration

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

By default the loader skips scripts and bundles/files located in the head section, but if you need to include those scripts or exclude another section(s) you can do this via ignorePositions property:

    ...
    'components' => [
        ...
        'view' => [
            'as jsLoader' => [
                'class' => 'ischenko\yii2\jsloader\Behavior',
                'loader' => [
                    'class' => 'loader\namespace\LoaderClass',
                    'ignorePositions' => [
                        View::POS_HEAD,
                        View::POS_BEGIN
                    ]
                ]
            ]
        ]
        ...
    ]
    ...

Additionally you can set a list of an asset bundles that should be ignored by the loader via ignoreBundles property:

    ...
    'components' => [
        ...
        'view' => [
            'as jsLoader' => [
                'class' => 'ischenko\yii2\jsloader\Behavior',
                'loader' => [
                    'class' => 'loader\namespace\LoaderClass',
                    'ignoreBundles' => [
                        'app\assets\AppCssAsset'
                    ]
                ]
            ]
        ]
        ...
    ]
    ...