https://github.com/bpolaszek/webpack-encore-resolver
Port of Webpack Encore's Twig functions in vanilla PHP.
https://github.com/bpolaszek/webpack-encore-resolver
Last synced: 4 months ago
JSON representation
Port of Webpack Encore's Twig functions in vanilla PHP.
- Host: GitHub
- URL: https://github.com/bpolaszek/webpack-encore-resolver
- Owner: bpolaszek
- Created: 2019-12-10T15:59:44.000Z (about 6 years ago)
- Default Branch: master
- Last Pushed: 2024-09-04T06:02:29.000Z (over 1 year ago)
- Last Synced: 2025-09-08T18:20:39.539Z (4 months ago)
- Language: PHP
- Size: 14.6 KB
- Stars: 5
- Watchers: 2
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
[](https://packagist.org/packages/bentools/webpack-encore-resolver)
[](https://packagist.org/packages/bentools/webpack-encore-resolver)
[](https://travis-ci.org/bpolaszek/webpack-encore-resolver)
[](https://codecov.io/gh/bpolaszek/webpack-encore-resolver)
[](https://scrutinizer-ci.com/g/bpolaszek/webpack-encore-resolver)
[](https://packagist.org/packages/bentools/webpack-encore-resolver)
# Webpack Encore Resolver
[Webpack Encore](https://symfony.com/doc/current/frontend.html) can work as a standalone Javascript library with `yarn add @symfony/webpack-encore`.
However, to dynamically load assets (runtime, vendors, versioned assets, ...),
you still need Symfony/Twig on the back-end part along with the [webpack-encore-bundle](https://github.com/symfony/webpack-encore-bundle).
So, here is a standalone PHP package to port `asset()`, `encore_entry_js_files()`, `encore_entry_css_files()`, `encore_entry_script_tags()`, `encore_entry_link_tags()` functions
of [Webpack Encore](https://symfony.com/doc/current/frontend.html) outside of Twig's scope, in a vanilla PHP project.
## Installation
```bash
composer require bentools/webpack-encore-resolver
```
## Example Usage
Consider this `webpack.config.js` file:
```js
const Encore = require('@symfony/webpack-encore');
Encore
.setOutputPath('public/build/')
.setPublicPath('/build')
.addEntry('main', './assets/js/main.js')
.enableVersioning(true)
// ...
;
module.exports = Encore.getWebpackConfig();
```
You can generate versioned assets tags the following way:
```php
```
Alternative (for more control on your markup):
```php
```
## Caveats
Multiple webpack configurations / multiple manifests aren't supported at the moment. PRs welcome!
## Tests
```bash
./vendor/bin/phpunit
```
## License
MIT.