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

Make it easier to bundle @trpc/server #1375

Closed
esamattis opened this issue Jan 9, 2022 · 3 comments
Closed

Make it easier to bundle @trpc/server #1375

esamattis opened this issue Jan 9, 2022 · 3 comments

Comments

@esamattis
Copy link
Contributor

esamattis commented Jan 9, 2022

Currently it requires two workarounds

  1. The url module must be installed from npm since it is a Node.js build-in and cannot be bundled otherwise
  2. Imports to http module must be ignored manually

With these workarounds I was able to bundle it with esbuild using this script

const ignorePlugin = require("esbuild-plugin-ignore");
require("esbuild").build({
    entryPoints: ["src/worker.ts"],
    bundle: true,
    outfile: "dist/worker.js",
    target: "chrome96",
    plugins: [
        ignorePlugin([
            {
                resourceRegExp: /http$/,
                contextRegExp: /.*/,
            },
        ]),
    ],
});

Why?

Bundling allows to run it non-node.js environments such as Cloudflare Workers, browsers, Remix in without node.js and possibly in Deno too.

Here's a proof of concept running it in a Cloudflare Workers https://github.com/esamattis/trpc-cloudflare-worker

What could be done?

The url module installation is OKish workaround but it would better to just get rid of it and use URLSearchParams instead which is available as a global in all these environments including Node.js.

The import { router } from "@trpc/server" should not end importing the http module. Only the adapter file using it should import it.

@KATT
Copy link
Member

KATT commented Jan 10, 2022

Feel free to add your project to https://trpc.io/docs/awesome-trpc 🙃

@KATT
Copy link
Member

KATT commented Mar 6, 2022

Superseded by #1597. If you wanna work on it, I'll pay you. :)

@KATT KATT closed this as completed Mar 6, 2022
@github-actions
Copy link

github-actions bot commented Oct 4, 2022

This issue has been locked because it had no new activity for 14 days. If you are running into a similar issue, please create a new issue. Thank you.

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

No branches or pull requests

2 participants