- Notifications
You must be signed in to change notification settings - Fork4
This is a Micro-PHP plugin for webpack-encore support
License
OleksiiBulba/webpack-encore-plugin
Folders and files
Name | Name | Last commit message | Last commit date | |
---|---|---|---|---|
Repository files navigation
This plugin adds several twig functions that help to include script and style html tags to twig templates from webpack-encore entries.
Before starting to work with the plugin, all you need is:
- Project based onMicro Framework;
- @symfony/webpack-encore installed by npm or yarn;
You can install the plugin via composer:
composer require oleksiibulba/webpack-encore-plugin
AddOleksiiBulba\WebpackEncorePlugin\WebpackEncorePlugin
to your plugins list:
<?php/* ./etc/plugins.php */return [// List of plugins:// ...OleksiiBulba\WebpackEncorePlugin\WebpackEncorePlugin::class,// ...];
To use the plugin you need to create an entrypoint in your webpack.config.js:
/* ./webpack.config.js */constEncore=require('@symfony/webpack-encore');Encore/* ... */.addEntry('your_entry_name','./path/to/your_entry_file.jsx')/* ... */
run build:
yarn dev// ornpm dev
and add one of the twig functions to a template:
{# ./templates/base.html.twig #}{# ... #}<head> {{ encore_entry_script_tags('your_entry_name') }} {{ encore_entry_link_tags('your_entry_name') }}</head>{# ... #}
Here is the signature of the twig functions:
- encore_entry_script_tags | encore_entry_link_tags:
- entryName, type: string, required;
- extraAttributes, type: array, optional, default value: empty array;
- getJavaScriptFiles | getCssFiles | entryExists:
- entryName, type: string, required;
If two or more entries contain common files, then they will be printed only once;
To add extra attribute to the tags, you can pass them in the array as a second argument, like this:
<head> {{ encore_entry_script_tags('your_entry_name', {'defer':true}) }}</head>
and as a result, it will print next html (assuming your entrypoint 'app' contains only one file './js/app.js'):
<head><scripthref="/js/app.js"type="application/javascript"defer></script></head>
Please seeCHANGELOG for more information on what has changed recently.
composertest
Please feel free to open pull request or create an issue, they are more than welcome!Please seeCONTRIBUTING andCODE_OF_CONDUCT for details.
If you discover any security related issues, please emailoleksii_bulba@epam.com instead of using the issue tracker.
The code was taken and adapted fromsymfony/webpack-encore-bundle
that was created bySymfony Community andFabien Potencier in particular.Adapted for Micro framework plugin byOleksii Bulba.
For the full copyright and license information, please see theLicense File that was distributed with this source code.
The MIT License (MIT). Please seeLicense File for more information.
About
This is a Micro-PHP plugin for webpack-encore support
Topics
Resources
License
Code of conduct
Uh oh!
There was an error while loading.Please reload this page.
Stars
Watchers
Forks
Packages0
Uh oh!
There was an error while loading.Please reload this page.