forked from OleksiiBulba/webpack-encore-plugin
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from Micro-PHP/1.6.0
v1.6.0 implemented
- Loading branch information
Showing
2 changed files
with
9 additions
and
153 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,148 +1,5 @@ | ||
# Webpack-Encore plugin for Micro framework | ||
# Micro Framework | ||
|
||
[![Latest Version on Packagist][ico-version]][link-packagist] | ||
[![Software License][ico-license]](LICENSE.md) | ||
[![Total Downloads][ico-downloads]][link-downloads] | ||
[![Scrutinizer Code Quality][ico-scrutinizer-quality]][link-scrutinizer-quality] | ||
[![Code Coverage][ico-scrutinizer-coverage]][link-scrutinizer-coverage] | ||
[![Build Status][ico-scrutinizer-build]][link-scrutinizer-build] | ||
Documentation is available [here](https://micro-php.net/docs). If not, we will be grateful if you can become its author :) | ||
|
||
This plugin adds several twig functions that help to include script and style html tags to twig templates from webpack-encore entries. | ||
|
||
## Get started | ||
|
||
Before starting to work with the plugin, all you need is: | ||
* Project based on [Micro Framework][link-microframework]; | ||
* [@symfony/webpack-encore][link-symfony-webpack-encore] installed by npm or yarn; | ||
|
||
### Install | ||
|
||
You can install the plugin via composer: | ||
```bash | ||
composer require oleksiibulba/webpack-encore-plugin | ||
``` | ||
|
||
### Usage | ||
|
||
Add `OleksiiBulba\WebpackEncorePlugin\WebpackEncorePlugin` to your plugins list: | ||
```php | ||
<?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: | ||
```javascript | ||
/* ./webpack.config.js */ | ||
const Encore = require('@symfony/webpack-encore'); | ||
Encore | ||
/* ... */ | ||
.addEntry('your_entry_name', './path/to/your_entry_file.jsx') | ||
/* ... */ | ||
``` | ||
|
||
run build: | ||
```bash | ||
yarn dev | ||
// or | ||
npm dev | ||
``` | ||
|
||
and add one of the twig functions to a template: | ||
```html | ||
{# ./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; | ||
|
||
#### Extra attributes | ||
To add extra attribute to the tags, you can pass them in the array as a second argument, like this: | ||
```html | ||
<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'): | ||
```html | ||
<head> | ||
<script href="/js/app.js" type="application/javascript" defer></script> | ||
</head> | ||
``` | ||
|
||
## Change Log | ||
|
||
Please see [CHANGELOG](CHANGELOG.md) for more information on what has changed recently. | ||
|
||
## Testing | ||
|
||
```bash | ||
composer test | ||
``` | ||
|
||
## Contributing | ||
|
||
Please feel free to open pull request or create an issue, they are more than welcome! | ||
Please see [CONTRIBUTING](CONTRIBUTING.md) and [CODE_OF_CONDUCT](CODE_OF_CONDUCT.md) for details. | ||
|
||
## Security | ||
|
||
If you discover any security related issues, please email [email protected] instead of using the issue tracker. | ||
|
||
## Credits | ||
|
||
- [Oleksii Bulba][link-author] | ||
- [Fabien Potencier][email-fabien] | ||
- [All Contributors][link-contributors] | ||
|
||
The code was taken and adapted from `symfony/webpack-encore-bundle` that was created by [Symfony Community](https://symfony.com/contributors) and [Fabien Potencier](mailto:[email protected]) in particular. | ||
Adapted for Micro framework plugin by [Oleksii Bulba][link-author]. | ||
|
||
For the full copyright and license information, please see the [License File](LICENSE.md) that was distributed with this source code. | ||
|
||
## License | ||
|
||
[The MIT License (MIT)][link-license]. Please see [License File](LICENSE.md) for more information. | ||
|
||
[ico-version]: https://img.shields.io/packagist/v/oleksiibulba/webpack-encore-plugin.svg?style=flat-square | ||
[ico-license]: https://img.shields.io/badge/license-MIT-brightgreen.svg?style=flat-square | ||
[ico-scrutinizer]: https://img.shields.io/scrutinizer/coverage/g/oleksiibulba/webpack-encore-plugin.svg?style=flat-square | ||
[ico-code-quality]: https://img.shields.io/scrutinizer/g/oleksiibulba/webpack-encore-plugin.svg?style=flat-square | ||
[ico-downloads]: https://img.shields.io/packagist/dt/oleksiibulba/webpack-encore-plugin.svg?style=flat-square | ||
|
||
[ico-scrutinizer-quality]: https://img.shields.io/scrutinizer/quality/g/OleksiiBulba/webpack-encore-plugin/master?style=flat-square | ||
[ico-scrutinizer-coverage]: https://img.shields.io/scrutinizer/coverage/g/OleksiiBulba/webpack-encore-plugin/master?style=flat-square | ||
[ico-scrutinizer-build]: https://img.shields.io/scrutinizer/build/g/OleksiiBulba/webpack-encore-plugin/master?style=flat-square | ||
|
||
[link-scrutinizer-quality]: https://scrutinizer-ci.com/g/OleksiiBulba/webpack-encore-plugin/?branch=master | ||
[link-scrutinizer-coverage]: https://scrutinizer-ci.com/g/OleksiiBulba/webpack-encore-plugin/?branch=master | ||
[link-scrutinizer-build]: https://scrutinizer-ci.com/g/OleksiiBulba/webpack-encore-plugin/build-status/master | ||
|
||
[link-microframework]: https://github.com/Micro-PHP/skeleton | ||
[link-symfony-webpack-encore]: https://www.npmjs.com/package/@symfony/webpack-encore | ||
[link-packagist]: https://packagist.org/packages/oleksiibulba/webpack-encore-plugin | ||
[link-travis]: https://travis-ci.org/oleksiibulba/webpack-encore-plugin | ||
[link-scrutinizer]: https://scrutinizer-ci.com/g/oleksiibulba/webpack-encore-plugin/code-structure | ||
[link-code-quality]: https://scrutinizer-ci.com/g/oleksiibulba/webpack-encore-plugin | ||
[link-downloads]: https://packagist.org/packages/oleksiibulba/webpack-encore-plugin | ||
[link-author]: https://github.com/OleksiiBulba | ||
[link-contributors]: ../../contributors | ||
[link-license]: https://opensource.org/licenses/MIT | ||
[email-fabien]: mailto:[email protected] | ||
Thanks to [Oleksii Bulba](https://github.com/OleksiiBulba) for implementing this plugin. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters