eta
eta copied to clipboard
Webpack Loader
It would be great to have a Webpack loader for .eta templates. It should have .eta files export the compiled function. Once the initial version with that is completed, we can add support for plugins and configuration for the loader.
I have implemented my own naive Rollup plugin (https://github.com/foisonocean/cf-download-proxy/tree/4131d12bd7a6df03a02e3ab71607674889fc28d0/build/rollup-plugins/eta), to compile templates to JavaScript source code at build time, since some JavaScript engine (like Cloudflare Workers) don't allow eval(...) or new Function(...). And the eta compiler won't be bundled to the built file, so it can help reduce bundle size.
The biggest pain for me is the defaultConfig from eta contains node.js fs API calls, which blocks rollup bundle those codes, so I have to maintain a modified config removed fs API calls, and handle the includeFile logic in the plugin. I really hope eta could ship a config without any Node.js API calls, so there would no need for me to maintain a config file anymore.
@foisonocean
The biggest pain for me is the defaultConfig from eta contains node.js fs API calls, which blocks rollup bundle those codes, so I have to maintain a modified config removed fs API calls, and handle the includeFile logic in the plugin. I really hope eta could ship a config without any Node.js API calls, so there would no need for me to maintain a config file anymore.
The v2 restructure, #70 will allow you to explicitly use the code for different environments, meaning you could do
const { compile } = require("eta/dist/browser/eta.umd.min");
compile("<%~ includeFile('./a') %>")() // throws error with fs not being supported
Would that work for your rollup plugin? You could try using the v1 browser UMD build, it may not work the best way.
Any update on this? would love to have an eta-loader for Webpack
We made a plugin with unplugin https://github.com/storipress/unplugin-eta