PHP code example of solas-wyrd / yii2-static-assets-publisher

1. Go to this page and download the library: Download solas-wyrd/yii2-static-assets-publisher library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

solas-wyrd / yii2-static-assets-publisher example snippets




declare(strict_types=1);

use SolasWyrd\Yii2StaticAssets\Configuration\StaticAssetsConfiguration;

$applicationPath = dirname(__DIR__);
$vendorPath = $applicationPath . '/vendor';

return new StaticAssetsConfiguration(
    targetPath: $applicationPath . '/web/assets/builds',
    allowedBuildRoot: $applicationPath . '/web/assets',
    baseUrl: '/assets/builds',
    scanPaths: [
        $applicationPath,
        $vendorPath,
    ],
    hashRoots: [
        'app' => $applicationPath,
        'vendor' => $vendorPath,
    ],
    manifestFileName: 'static-assets-manifest.json',
);



declare(strict_types=1);

use SolasWyrd\Yii2StaticAssets\Configuration\StaticAssetsConfiguration;
use SolasWyrd\Yii2StaticAssets\Contract\AssetBundleFinderInterface;
use SolasWyrd\Yii2StaticAssets\Contract\AssetBundlePublisherInterface;
use SolasWyrd\Yii2StaticAssets\Contract\AssetManifestReaderInterface;
use SolasWyrd\Yii2StaticAssets\Contract\AssetManifestWriterInterface;
use SolasWyrd\Yii2StaticAssets\Contract\AssetSourceHasherInterface;
use SolasWyrd\Yii2StaticAssets\Contract\ProgressReporterInterface;
use SolasWyrd\Yii2StaticAssets\Discovery\AstAssetBundleFinder;
use SolasWyrd\Yii2StaticAssets\Hash\ContentAssetSourceHasher;
use SolasWyrd\Yii2StaticAssets\Manifest\JsonFileAssetManifestReader;
use SolasWyrd\Yii2StaticAssets\Manifest\JsonFileAssetManifestWriter;
use SolasWyrd\Yii2StaticAssets\Publication\YiiAssetBundlePublisher;
use SolasWyrd\Yii2StaticAssets\Reporting\ConsoleProgressReporter;

/** @var StaticAssetsConfiguration $configuration */
$configuration = 



declare(strict_types=1);

use SolasWyrd\Yii2StaticAssets\Yii\AssetBuildController;

return [
    'controllerMap' => [
        'asset-build' => [
            'class' => AssetBuildController::class,
        ],
    ],
];



declare(strict_types=1);

use SolasWyrd\Yii2StaticAssets\Configuration\StaticAssetsConfiguration;
use SolasWyrd\Yii2StaticAssets\Hash\ContentAssetSourceHasher;
use SolasWyrd\Yii2StaticAssets\Hash\ManifestAssetPathHasher;
use SolasWyrd\Yii2StaticAssets\Manifest\JsonFileAssetManifestReader;
use yii\web\AssetManager;

/** @var StaticAssetsConfiguration $configuration */
$configuration = > false,
            'linkAssets' => false,
            'forceCopy' => false,
            'hashCallback' => $manifestHasher(...),
        ],
    ],
];

use SolasWyrd\Yii2StaticAssets\Contract\AssetBundleFinderInterface;

return [
    AssetBundleFinderInterface::class => ProjectAssetBundleFinder::class,
];

use SolasWyrd\Yii2StaticAssets\Contract\AssetBundlePublisherInterface;

return [
    AssetBundlePublisherInterface::class => CdnAssetBundlePublisher::class,
];

use SolasWyrd\Yii2StaticAssets\Contract\AssetManifestReaderInterface;
use SolasWyrd\Yii2StaticAssets\Contract\AssetManifestWriterInterface;

return [
    AssetManifestReaderInterface::class => RedisAssetManifestReader::class,
    AssetManifestWriterInterface::class => RedisAssetManifestWriter::class,
];

use SolasWyrd\Yii2StaticAssets\Contract\ProgressReporterInterface;
use SolasWyrd\Yii2StaticAssets\Reporting\NullProgressReporter;

return [
    ProgressReporterInterface::class => NullProgressReporter::class,
];
bash
php yii asset-build/publish
dockerfile
WORKDIR /var/www/html

COPY composer.json composer.lock ./

RUN composer install \
    --no-dev \
    --prefer-dist \
    --no-interaction \
    --no-progress

COPY . .

RUN composer dump-autoload \
        --optimize \
        --classmap-authoritative \
    && php yii asset-build/publish