Skip to content

A Symfony bundle to create paths to webpack assets in your Twig templates.

License

Notifications You must be signed in to change notification settings

freshheads/FHWebpackBundle

Folders and files

NameName
Last commit message
Last commit date

Latest commit

f6fdb9b · Mar 1, 2024

History

53 Commits
Dec 11, 2023
Dec 11, 2023
Dec 11, 2023
Dec 11, 2023
Dec 11, 2023
Nov 28, 2019
Jun 24, 2020
Dec 11, 2023
Jul 8, 2020
Dec 11, 2023
Mar 1, 2024
Mar 1, 2024
Apr 7, 2022

Repository files navigation

FHWebpackBundle

A Symfony bundle to create paths to webpack assets in your Twig templates. This bundle uses the webpack statistics file to find the newest assets for a given webpack entry.

Installation

Install with composer:

composer require freshheads/webpack-bundle

Register the bundle

// config/bundles.php
return [
    // ...
    FH\Bundle\WebpackBundle\FHWebpackBundle::class => [ 'all' => true ]
];

Configuration

All configuration options, with default values:

fh_webpack:
    stats_filename: stats.json
    # web/document root, assets will be referenced from this path
    web_dir: '%kernel.project_dir%/public'

Usage

Link webpack files

<link rel="stylesheet" href="{{ webpack_asset('assets/frontend/build', 'app', 'css') }}" />
<script type="text/javascript" src="{{ webpack_asset('assets/frontend/build', 'app', 'js') }}"></script>

Dump the contents of a webpack file

<style type="text/css">
    {{ webpack_asset_contents('assets/frontend/build', 'email', 'css')|raw }}
</style>

Requirements

This library works with PHP version 8.1 and up.