twing-render-loader
Installation
yarn add --dev twing-render-loader
# or
npm install --save-dev twing-render-loader
Usage
Add this to your webpack config:
module: {
rules: [
// ...
{
test: /\.twig$/i,
loader: 'twing-render-loader',
options: {
environmentModule: new URL('twing.env.mjs', import.meta.url).pathname,
// environmentModule: require.resolve('./twing.env.mjs', import.meta.url),
},
},
// ...
],
// ...
plugins: [
new WebpackHtmlPlugin({
template: './src/index.twig',
}),
],
},
Create file named 'twing.env.mjs':
/** @type {import('twing').TwingEnvironmentOptions} */
export const options = {
debug: true,
};
/**
* @param {import('webpack').LoaderContext<{}>} loader
* @param {import('twing').TwingEnvironment} env
*/
export async function configure({ loader, env }) {
env.addGlobal('mode', loader.mode);
};