crypto_scythe/bundledassets

用于添加由打包器创建的JavaScript和CSS资产的Laminas视图助手

1.0.3 2021-09-07 20:05 UTC

This package is auto-updated.

Last update: 2024-09-08 02:40:56 UTC


README

MIT License Run unit tests

用于添加由打包器创建的JavaScript和CSS资产的Laminas视图助手。

安装

Composer

composer require crypto_scythe/bundledassets

手动

您可以下载 最新发布版本的zip文件 并将其解压到自己的模块文件夹中。请确保安装composer.json中概述的依赖项,以确保其正确工作。

使用/示例

Laminas MVC

# Add module class to Modules configuration
CryptoScythe\BundledAssets\Module::class,

Laminas Mezzio

# Add config provider class to configuration
CryptoScythe\BundledAssets\ConfigProvider::class,

配置

# global.php
use CryptoScythe\BundledAssets\ConfigProvider as BundledAssetsConfigProvider;

BundledAssetsConfigProvider::GLOBAL_CONFIG_KEY_VIEW_HELPER_CONFIG => [
    BundledAssetsConfigProvider::class => [
        BundledAssetsConfigProvider::CONFIG_KEY_CACHE_PATH => 'data/bundled_assets_cache.php', # Path to cache file, mostly production 
            BundledAssetsConfigProvider::CONFIG_KEY_MANIFESTS => [ # Hash map of manifest files
                BundledAssetsConfigProvider::CONFIG_KEY_DEFAULT_MANIFEST => 'data/webpack-assets.json',
                'other_manifest' => 'data/other-assets.json', # [optional] You can use multiple asset manifests
        ],
    ],
],

在布局中使用

$this->bundledAssets('entry_point'); # Uses assets from default
$this->bundledAssets('some_other_entry_point', 'other_manifest'); # Uses additionally defined manifest

常见问题解答

什么是清单文件?

清单文件包含捆绑资产的列表,例如assets-webpack-plugin的输出。

看起来像这样

{
    "main": {
        "js": [
            "some_js_asset.12345.js",
            "some_other_js_asset.54321.js"
        ],
        "css": [
            "some_css_asset.12345.css",
            "another_css_asset.abcdef.css"
        ],
    },
    "another": {
        # even more of the same
    }
}

作者

许可证

MIT