ventojs / vento

🌬 A template engine for Deno & Node
https://vento.js.org/
MIT License
153 stars 9 forks source link

Feature request: Cloudflare Worker support #68

Open jvhellemond opened 2 weeks ago

jvhellemond commented 2 weeks ago

Hi, Are there any plans to make Vento compatible with Cloudflare Workers? I tried bundling the npm package (using esbuild), but ran into the dreaded Dynamic require of "node:fs" is not supported errors (et al.).

I know Vento is specifically a Deno project, but it would be awesome for my projects.

oscarotero commented 2 weeks ago

Vento has an NPM distribution. Did you try it?

jvhellemond commented 2 weeks ago

Yes, but that results in errors like Dynamic require of "node:fs" is not supported. Cloudflare Workers is a bit like node, but not enough :|

oscarotero commented 2 weeks ago

Do you know in which package/file this error occurs? I don't see any node:fs in Vento code (npm version). Maybe it's caused by a dependency.

jvhellemond commented 4 days ago

Yup, the dependency is @deno/shim-deno. The Cloudflare worker environment has no access to the filesystem, so node:fs is not available.

oscarotero commented 4 days ago

If Cloudflare has no access to file system, you have to replace the default loader with other with support for Cloudflare API. The default loader is this. You can do something like this:

class CloudflareLoader {
  async load(file) {
    return {
      source: "File content here"
    }
  }

  resolve(from, file) {
    return "Resolved file";
  }
}

const env = vento({
  includes: new CloudflareLoader()
});