Download the PHP package pieceofcake2/webpack-encore without Composer
On this page you can find all versions of the php package pieceofcake2/webpack-encore. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download pieceofcake2/webpack-encore
More information about pieceofcake2/webpack-encore
Files in pieceofcake2/webpack-encore
Package webpack-encore
Short Description View helper that loads Symfony Webpack Encore-built assets in CakePHP 2
License MIT
Informations about the package webpack-encore
CakePHP 2.x Webpack Encore Plugin
This helper allows you to integrate Symfony Webpack Encore–built assets (CSS, JS, images) into a CakePHP 2 application. It reads entrypoints.json and manifest.json to resolve fingerprinted asset filenames and output proper <link>, <script>, or <img> tags.
Installation
-
Install plugin:
-
Build your Encore assets (e.g., with Symfony Encore or webpack). From your project root, run:
This should generate:
webroot/build/entrypoints.jsonwebroot/build/manifest.json- The
webroot/build/directory containing compiled.js,.css, and image files.
-
Copy
EncoreHelper.phpinto your CakePHP app under: -
Load the helper in your controller (e.g.,
AppController):Now you can use
$this->Encorein your views.
Configuration (Configure)
By default, the helper expects:
entrypoints.jsonatwebroot/build/entrypoints.jsonmanifest.jsonatwebroot/build/manifest.json
If you store these files in different locations, add the following to app/Config/bootstrap.php:
Replace the paths accordingly if they differ.
Helper Methods
1. asset($assetPath)
Resolves a single logical asset path (as a key in manifest.json) to the final fingerprinted URL. Returns a web-accessible path (including leading slash).
2. image($assetPath, array $htmlAttributes = [])
Renders an <img> tag for a given image asset by resolving through manifest.json.
3. css($assetPaths, array $options = [])
Renders one or more <link> tags for CSS assets. The first argument can be a string or an array of strings. Each path is resolved via manifest.json, then passed to HtmlHelper::css().
4. script($assetPaths, array $options = [])
Renders one or more <script> tags for JavaScript assets. Accepts a string or an array of strings. Each is resolved via manifest.json, then passed to HtmlHelper::script().
5. entryLinkTags($entryName, array $options = [])
Reads entrypoints.json and renders <link> tags for all CSS files associated with the given entry (e.g., app, dashboard).
6. entryScriptTags($entryName, array $options = [])
Reads entrypoints.json and renders <script> tags for all JS files associated with the given entry.
Example Layout Integration
In app/View/Layouts/default.ctp:
<head>:entryLinkTags('app')outputs<link>tags for all CSS associated with theappentry.<body>:entryScriptTags('app')outputs<script>tags for all JS associated with theappentry.- The
image()method resolves and renders an<img>tag for an image asset.
Notes
- Always rebuild your assets (run
npm run encore devornpm run encore production) after changing frontend code to updateentrypoints.jsonandmanifest.json. - This helper expects the paths in both JSON files to start with
/build/.... If you use a different directory, adjust the JSON outputs or changeConfigure::write('Encore.entrypointsPath', ...)andConfigure::write('Encore.manifestPath', ...)accordingly. - The helper loads and caches both JSON files once in its constructor for performance. Subsequent calls will not re-read the files.
License
This plugin is released under the MIT License. You are free to adapt and redistribute it in compliance with the license.
All versions of webpack-encore with dependencies
composer/installers Version ^1.0 || ^2.0
pieceofcake2/cakephp Version ^2.12