eta icon indicating copy to clipboard operation
eta copied to clipboard

Webpack Loader

Open shadowtime2000 opened this issue 4 years ago • 3 comments

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.

shadowtime2000 avatar Dec 17 '20 17:12 shadowtime2000

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.

hronro avatar Dec 24 '20 10:12 hronro

@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.

shadowtime2000 avatar Dec 26 '20 04:12 shadowtime2000

Any update on this? would love to have an eta-loader for Webpack

NickKelly1 avatar Aug 13 '21 11:08 NickKelly1

We made a plugin with unplugin https://github.com/storipress/unplugin-eta

DanSnow avatar Jan 22 '23 09:01 DanSnow