rodrigoq / simple-webpack-encore-bundle
Integration with your php and twig application & Webpack Encore!
Requires
- php: >=7.1.3
- symfony/service-contracts: ^1.0 || ^2.0
Requires (Dev)
- twig/twig: ^2.0 || ^3.0
This package is not auto-updated.
Last update: 2024-12-24 12:23:46 UTC
README
A very basic and simple implementation of WebpackEncoreBundle for projects that do not use Symfony, with easier setup and less dependencies. Recommended for old projects or projects that do not plan to add or setup Symfony. The frontend setup is the same as with Webpack Encore
Install with:
composer require rodrigoq/simple-webpack-encore-bundle
Configuration
In your twig setup file:
use Simple\WebpackEncoreBundle\Twig\EntryFilesTwigExtension; ... $entrypointJsonFile = "path/to/entrypoints.json"; $twigEnvironment->addExtension(new EntryFilesTwigExtension($entrypointJsonFile));
or for multiple builds:
use Simple\WebpackEncoreBundle\Twig\EntryFilesTwigExtension; ... $builds = [ 'firstConfig' => "path/to/firstConfig/entrypoints.json", 'secondConfig' => "path/to/secondConfig/entrypoints.json", ]; $twigEnvironment->addExtension(new EntryFilesTwigExtension($builds));
No need for yaml configuration file.
Usage
Check readme on the original repo.
Changes
Added two new twig functions for full URL or directory prefixing, you can have a full path or different paths configured in php not needing for code on your javascript configuration file.
{{ encore_entry_script_tags_with_baseurl('app', 'https://yoursite.com') }} {{ encore_entry_link_tags_with_baseurl('app', 'https://yoursite.com') }} {# or any directory prefix #} {{ encore_entry_script_tags_with_baseurl('app', '/a/different/path') }} {{ encore_entry_link_tags_with_baseurl('app', '/a/different/path') }}