Skip to content

Commit

Permalink
Merge pull request #1 from Micro-PHP/1.6.0
Browse files Browse the repository at this point in the history
v1.6.0 implemented
  • Loading branch information
Asisyas authored Jan 24, 2023
2 parents 08e4c17 + e177a5f commit 628d8b3
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 153 deletions.
149 changes: 3 additions & 146 deletions README.md
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.
13 changes: 6 additions & 7 deletions composer.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"name": "oleksiibulba/webpack-encore-plugin",
"name": "micro/plugin-twig-webpack-encore",
"description": "This is a Micro plugin for webpack-encore support",
"license": "MIT",
"type": "micro-plugin",
Expand All @@ -12,10 +12,9 @@
}
],
"require": {
"php": "^8.2",
"micro/kernel-boot-configuration": "^1",
"micro/kernel-boot-plugin-depended": "^1",
"micro/plugin-twig": "^1",
"micro/kernel-boot-configuration": "^1.6",
"micro/kernel-boot-plugin-depended": "^1.6",
"micro/plugin-twig": "^1.6",
"symfony/serializer": "^6.2"
},
"require-dev": {
Expand Down Expand Up @@ -49,8 +48,8 @@
},
"scripts": {
"coverage": "XDEBUG_MODE=coverage ./vendor/bin/phpunit --coverage-text",
"php-cs-fix": "./vendor/bin/php-cs-fixer fix --verbose --using-cache=no",
"php-cs-try": "./vendor/bin/php-cs-fixer fix --verbose --dry-run --using-cache=no",
"php-cs-fix": "PHP_CS_FIXER_IGNORE_ENV=1 ./vendor/bin/php-cs-fixer fix --verbose --using-cache=no",
"php-cs-try": "PHP_CS_FIXER_IGNORE_ENV=1 ./vendor/bin/php-cs-fixer fix --verbose --dry-run --using-cache=no",
"phpstan": "./vendor/bin/phpstan analyze --no-progress",
"phpunit": "./vendor/bin/phpunit",
"psalm": "./vendor/bin/psalm --no-progress --show-info=true",
Expand Down

0 comments on commit 628d8b3

Please sign in to comment.