hurnell / cakephp-webpack-encore-view-helper
CakePhp view helper plugin to load webpack-encore assets. Reads entrypoints.json and manifest.json and loads the assets referenced herein when requested.
Installs: 10
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 1
Forks: 0
Open Issues: 0
Type:cakephp-view-helper
Requires
- php: ^7.1
- galbar/jsonpath: dev-master
Requires (Dev)
- cakephp/cakephp: ^3.7
This package is auto-updated.
Last update: 2025-03-11 22:04:12 UTC
README
Installation
You can install this plugin into your CakePHP application using composer.
The recommended way to install composer packages is:
composer require hurnell/cakephp-webpack-encore-view-helper
Make sure that composer.json of your CakePHP installation contains:
"minimum-stability": "dev",
"prefer-stable": true
Initialize
In App/View/AppView add use statement and update initialize method:
use Hurnell\WebpackEncoreViewHelper\View\Helper\EncoreHelper
$this->loadHelper('Encore', [
'className'=> EncoreHelper::class
]);
Usage
In your .ctp files just add:
<?= $this->Encore->load('build/js/entry.js') ?>
<?= $this->Encore->load('build/js/entry.css') ?>
<?= $this->Encore->load('build/css/main.css') ?>
These entrypoints are defined in your webpack.config.js file (see dist directory).
I have also included my package.json file in the dist directory to shows the packages I have installed to support this version of webpack.config.js.
Note that the only way that I was able to get hot module replacement (auto reload web-page when you update asset files) to work was with:
yarn encore dev-server --port 8080 --disableHostCheck=true
There is a shortcut defined under scripts in package.json:
yarn dev-server
Check out webpack-visualizer to help optimise your imports. Just run yarn stats
and upload the resulting stats.json file to this website.