Open ThaNarie opened 2 years ago
Approach (WIP)
In the MubanWebpackConfig
> finalDevServer
, make the setupMiddlewares
allow for different types of template engines (or abstract it away as "plugins").
Example for handlebars:
devServer.app.engine('.hbs', engine({ extname: '.hbs'}));
devServer.app.set('view engine', '.hbs');
devServer.app.set('views', './views');
middlewares.unshift({
name: 'pages',
path: '/',
middleware: ((req, res, next) => {
res.render('home');
}),
});
Update the MubanPagePlugin
> generatePageAssets
to (also) output the raw "page data" instead of (only) the rendered HTML, so the middleware above can make use of this data to render the page based on chosen template engine.
Currently running into issues also setting this in compilation.hooks.processAssets.tapPromise
assets[page.replace('.html', '.json')] = JSON.stringify(pageData);
TypeError: Invalid value used as weak map key
"transfered" to https://github.com/mediamonks/pota/issues/30
Currently, the skeleton can only render TS templates – which will stay the preferred way of working.
However, certain projects might benefit from other template languages – like Twig or Handlebars – that better connect with the CMS used in a project.
Since we're using
express
already to render templates "on the server", and@muban/storybook
does support server-side template rendering, we could leverage that to basically support any template engine that express supports – and potentially more.Goals