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

feat: support @vercel/og (server wasm asset + font asset) (edge) #547

Closed
wants to merge 7 commits into from

Conversation

hi-ogawa
Copy link
Owner

@hi-ogawa hi-ogawa commented Jul 12, 2024

It's somehow working on dev, but build looks broken (as expected).


Hmm, they probably rely on Next.js specific build-time import.meta.url asset feature, so it's going to be hard (cf. #510).
Probably coming up with some ad-hoc transform to support index.edge.js is a best bet, namely:

  • plugin for xxx.wasm?module
  • plugin for new URL("xxx.ttf", import.meta.url)
//
// @vercel/og/dist/index.node.js
//
var fontData = fs.readFileSync(fileURLToPath(join(import.meta.url, "../noto-sans-v27-latin-regular.ttf")));
var yoga_wasm = fs.readFileSync(fileURLToPath(join(import.meta.url, "../yoga.wasm")));
var resvg_wasm = fs.readFileSync(fileURLToPath(join(import.meta.url, "../resvg.wasm")));
var initializedResvg = initWasm(resvg_wasm);
var initializedYoga = initYoga(yoga_wasm).then((yoga2) => Rl(yoga2));

//
// @vercel/og/dist/index.edge.js
//
import resvg_wasm from "./resvg.wasm?module";
import yoga_wasm from "./yoga.wasm?module";

var initializedResvg = initWasm(resvg_wasm);
var initializedYoga = initYoga(yoga_wasm).then((yoga2) => Rl(yoga2));
var fallbackFont = fetch(new URL("./noto-sans-v27-latin-regular.ttf", import.meta.url)).then((res) => res.arrayBuffer());

For actual cloudflare deployment, we need to figure out "server assets" to upload wasm:

For final bundling, we would probably need something like this:

Actually this part should be fixed first.

todo

  • dev
  • node build
  • edge build
  • test

@hi-ogawa hi-ogawa changed the title feat: support @vercel/og (wip) feat: support @vercel/og (server wasm asset + font asset) (wip) Jul 12, 2024
Copy link
Owner Author

This stack of pull requests is managed by Graphite. Learn more about stacking.

Join @hi-ogawa and the rest of your teammates on Graphite Graphite

@hi-ogawa hi-ogawa changed the title feat: support @vercel/og (server wasm asset + font asset) (wip) feat: support @vercel/og (server wasm asset + font asset) (edge) Jul 13, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant