twig.js loader for Webpack
This package requires node.js 8 at least.
Install with npm:
$ npm i -D twigjs-loader
var indexView = require('./index.twig');
console.log(indexView({ variable1: 'value' });
webpack.config.js
module.exports = {
...
module: {
rules: [
{
test: /\.twig$/,
use: 'twigjs-loader',
},
...
},
...
}
$ npm i twigjs-loader
index.js:
import * as express from "express";
import { ExpressView } from "twigjs-loader";
import indexView from "./views/index.twig";
const app = express();
app.set("view", ExpressView);
app.get("/", (req, res) => {
res.render(indexView, {
url: `${req.protocol}://${req.get("host")}${req.originalUrl}`,
})
});
const port = process.env.NODE_PORT || 8080;
app.listen(port, () => {
console.log(`Example app listening on port ${port}.`);
});
Licensed under MIT.
Based on zimmo-be/twig-loader