Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[esbuild] expose the platform option to bundle code run on node #13136

Closed
razonyang opened this issue Dec 12, 2024 · 3 comments · Fixed by #13139
Closed

[esbuild] expose the platform option to bundle code run on node #13136

razonyang opened this issue Dec 12, 2024 · 3 comments · Fixed by #13139
Assignees
Milestone

Comments

@razonyang
Copy link
Contributor

Dear Hugo team, I'd like request a feature to specify the platform option of esbuild.

Backgrounds

There are many static site hosting platforms that support serverless functions (e.g. Cloudlfare Worker), it would be great if we could bundle JavaScript code that runs on node, which provides better integration capabilities.

With the esbuild platform option, Hugo can be a Node application packing tool.

Pros

  1. It's easy to manage, share, and reuse codes between sites through Hugo Modules.
  2. Manage configuration in the same place (hugo.yaml and the params option of js.Build).

I am willing to implement it (I have a working local branch) if this request is accepted.

@bep
Copy link
Member

bep commented Dec 12, 2024

Can you elaborate a little about how this ends up in e.g. a Cloudflare worker?

@razonyang
Copy link
Contributor Author

razonyang commented Dec 12, 2024

Sure, Cloudflare Pages offer an advanced mode for serverless functions, which the entry point is _worker.js in output directory (public).

However, currently js.Build can not bundle code that runs on node (or node compatible) if import node's built-in modules, for example,

import { platform } from 'process';

console.log(platform)

It will result in an error when importing Node built-in modules.

...Could not resolve "process"...

With the platform option, Hugo will have the ability to build Node app to integrate with serverless functions.

@bep bep self-assigned this Dec 12, 2024
bep added a commit to bep/hugo that referenced this issue Dec 12, 2024
@bep bep modified the milestones: Unscheduled, v0.140.0 Dec 12, 2024
@bep bep removed the Proposal label Dec 12, 2024
bep added a commit to bep/hugo that referenced this issue Dec 12, 2024
@bep bep closed this as completed in ec1933f Dec 12, 2024
Copy link

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jan 10, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants