workers-graphql-server icon indicating copy to clipboard operation
workers-graphql-server copied to clipboard

TypeScript support, build too large

Open vladinator1000 opened this issue 4 years ago • 6 comments

Hi Kris, I've been working on adding TypeScript support but I'm struggling with Wrangler not building correctly.

The only way I got it to build is by mocking modules in the webpack config like this to get the Apollo stuff to work

resolve: {
    extensions: ['.ts', '.tsx', '.js'],
    alias: {
      fs: path.resolve(__dirname, './src/utils/empty.ts'),
      busboy: path.resolve(__dirname, './src/utils/empty.ts'),
    },
  }

But this build is 2MiB so it can't get uploaded. Setting it to production mode also didn't help.

I also think that the way we're importing stuff from Apollo is a bit weird, I think Apollo should provide a nice interface that builds and compiles just fine instead of having to wrap the server in a function imported from dist. There's this issue for example that kinda leaves me scratching my head.

I have a simpler TypeScript repo that runs and deploys just fine.

If I get this to work, my plan is to convert a medium-sized codebase to Cloudflare workers. You got any pointers on where I can take this?

vladinator1000 avatar May 13 '20 00:05 vladinator1000

Hello @vladinator1000.

As I see your tsconfig.json, you have set "module": "commonjs" that not supported tree-shaking.

Could you try "module": "esnext" instead ?

Cerberus avatar May 23 '20 12:05 Cerberus

This is how my bundle looks like with "module": "esnext"` in the TS config. That's 1.5 MiB of dependencies.

image

When I use bundle optimize helper it says a bunch of deps are not tree shakeable because they're not using ES modules.

vladinator1000 avatar May 24 '20 13:05 vladinator1000

(Seem like this project really bundles a lot of dependencies.)

Anyway, with a quick looking. I have some suggestions.

  1. Could you try to change all importing from /dist to /esm instead (if possible) ? (As I see graphql-tools & apollo-engine-reporting-protobuf)

As I know the dist directory inside node_modules always be commonjs type. Changing importing might help to cut some unused codes off.

  1. Update to import directly (import test from 'lib/test') not (import { test } from 'lib')

If you have done already and it's size is still large, I have no idea for now : )

Cerberus avatar May 24 '20 15:05 Cerberus

By the way, I'm the one who start build a project with typescript that scratch from this boilerplate too.

With a few general dependencies, It take lower than 1 MB.

So, hope you found a root cause soon.

Cerberus avatar May 24 '20 15:05 Cerberus

Can anyone help me with TypeScript implementation of this template?

jayeshmann avatar Jul 01 '21 10:07 jayeshmann

Hey, can anyone tell me how to set up TypeScript for this library?

macmillen avatar Nov 08 '21 14:11 macmillen