Webpack loader for natively compiling Twig templates via an external PHP rendering service. Based originally off of https://github.com/zimmo-be/twig-loader.
Extra huge shoutout to Evan Lovely for his help on a ton of the ideas behind this!
Installation
npm install twig-loader-php
Usage
const TwigPhpLoader = ; moduleexports = //... module: rules: test: /\.twig$/ loader: TwigPhpLoaderloader options: port: configport namespaces: twigNamespaces includeContext: false // false by default - this changes how / when the Twig template gets rendered so that HtmlWebpackPlugin's contextual data is available //... plugins: // <-- super important part! // For example, wiring this up to the HtmlWebpackPlugin to compile Pattern Lab's Workshop UI (as Twig templates) title: 'Custom template' filename: '../index.html' inject: true cache: false // Load a custom template (lodash by default see the FAQ for details) template: path ;
Note: in this early version, internally we're assuming the PHP service's API expects requests to be structured as http://localhost:${opts.port}/api/render-twig?templatePath=${querystringifiedTemplate}
-- with the body of the POST request containing the Twig data to be passed along.
This will eventually change to become much more customizable!