PHP code example of pieceofcake2 / webpack-encore

1. Go to this page and download the library: Download pieceofcake2/webpack-encore library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

pieceofcake2 / webpack-encore example snippets


   // app/Controller/AppController.php
   App::uses('Controller', 'Controller');

   class AppController extends Controller {
       public $helpers = ['Html', 'WebpackEncore.Encore'];
   }
   

// app/Config/bootstrap.php

// Full filesystem path to entrypoints.json
Configure::write('WebpackEncore.entrypointsPath', WWW_ROOT . 'build/entrypoints.json');
// Full filesystem path to manifest.json
Configure::write('WebpackEncore.manifestPath',    WWW_ROOT . 'build/manifest.json');

// Given manifest.json contains:
// {
//   "build/images/logo.png": "/build/images/logo.3eed42.png"
// }

echo $this->Encore->asset('build/images/logo.png');
// Outputs: /build/images/logo.3eed42.png

// Outputs: <img src="/build/images/cake_logo.3eed42.png" alt="CakePHP" />
echo $this->Encore->image('build/images/cake_logo.png', ['alt' => 'CakePHP']);

// Single CSS file
echo $this->Encore->css('build/app.css', ['inline' => false]);

// Multiple CSS files
echo $this->Encore->css([
    'build/vendors.3d4e5f.css',
    'build/app.abc123.css'
], ['inline' => false]);

// Single JS file
echo $this->Encore->script('build/app.js', ['block' => true]);

// Multiple JS files
echo $this->Encore->script([
    'build/runtime.0a1b2c.js',
    'build/vendors.3d4e5f.js',
    'build/app.123abc.js'
], ['block' => true]);

// entrypoints.json example:
// {
//   "entrypoints": {
//     "app": {
//       "css": ["/build/vendors.3d4e5f.css","/build/app.abc123.css"],
//       "js": ["/build/runtime.0a1b2c.js","/build/vendors.3d4e5f.js","/build/app.123abc.js"]
//     }
//   }
// }

echo $this->Encore->entryLinkTags('app', ['inline' => false]);
// Outputs two <link> tags for the app entry's CSS files

echo $this->Encore->entryScriptTags('app', ['block' => true]);
// Outputs three <script> tags for the app entry's JS files

<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title> echo $this->fetch('title'); 
text
   app/View/Helper/EncoreHelper.php