mehrkanal/twig-encore-extension
最新稳定版本:4.0.2
Composer 安装命令:
composer require mehrkanal/twig-encore-extension
包简介
Twig Extension to use entrypoints.json in Twig Templates
README 文档
README
To use with twig/twig and symfony/webpack-encore-bundle
Created for: Laminas/Mezzio Applications without native Symfony Kernel.
Warning: If Symfony is available, just use the symfony/webpack-encore-bundle bundle as is.
How to use and configure Encore
composer require symfony/webpack-encore-bundle- npm i @symfony/webpack-encore
- webpack.config.js
setOutputPath()should be in the public folder- i.e.
.setOutputPath('public/assets')
- i.e.
setPublicPath()should be in the folder where the assets are in- i.e.
setPublicPath('/assets')
- i.e.
- Set
['twig']['asset_url']to the absulute Path, for example in your twig.global.php- Best be set to:
/app/public/assets/ - Note: A Forward Slash is appended after asset_url in case the preceding path does not end on a forward slash
- i.e. asset_path is
/assetsthe url will be<document_root>/assets/entrypoints.json
- i.e. asset_path is
- Best be set to:
- Include
Mehrkanal\EncoreTwigExtension\ConfigProvider::classinto your global config - Include
Mehrkanal\EncoreTwigExtension\Extensions\GetCssSourceTwigExtension:classto your['twig']['extensions']config. - Include
\Symfony\Bridge\Twig\Extension\AssetExtension::classto your['twig']['extensions']config. - Include
Symfony\WebpackEncoreBundle\Twig\EntryFilesTwigExtension:classto your['twig']['extensions']config.
use Mehrkanal\EncoreTwigExtension\Extensions\GetCssSourceTwigExtension; use Symfony\WebpackEncoreBundle\Twig\EntryFilesTwigExtension; use Twig\Environment; use Twig\Loader\FilesystemLoader; require_once 'vendor/autoload.php'; $container = require __DIR__ . '/container.php'; $loader = new FilesystemLoader('./templates'); $twig = new Environment($loader, [ 'debug' => true ]); $twig->addExtension($container->get(EntryFilesTwigExtension::class)); $twig->addExtension($container->get(GetCssSourceTwigExtension::class));
What can I do now?
- Use Encore NodeJS Scripts to automatically generate assets
- Use
encore_entry_link_tags(<entrypoint>)function in Twig to get all required stylesheet link tags - Use
encore_entry_script_tags(<entrypoint>)function in Twig to get all required script tags - Use
encore_get_css_source(<entrypoint>)function in Twig to get all CSS Code from this entrypoint
Use in combination with setEntry of Encore Webpack Config.
Stan
docker run -it -v $PWD:/app -v $SSH_AUTH_SOCK:$SSH_AUTH_SOCK -w /app -e SSH_AUTH_SOCK=$SSH_AUTH_SOCK -e SSH_AGENT_PID=$SSH_AGENT_PID registry.mehrkanal.com/docker/phpx/cli:8.1-build bash composer up composer run stan composer run cf
Useful links:
- Original Code
- https://symfony.com/doc/current/frontend/encore/installation.html
- https://gitlab.mehrkanal.com/mehrkanal/skeleton.git
Team
统计信息
- 总下载量: 4.2k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 4
- 点击次数: 1
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: GPL-3.0-or-later
- 更新时间: 2020-09-15