question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Include a `worktop build` command

See original GitHub issue

I’ve been going back on forth on this for a while… Basically, it’s a debate between:

  1. Include a worktop CLI that builds a Worker for you
  2. Offer a series of bundler plugins that you can import/attach to your existing toolkit

I suppose it’s possible to do both, but the array of plugins would be second-class in that scenario, especially since it’s (probably) unlikely that each integration could offer the same level of output refinement.


PROs

It’d be nice to have a ready-to-go build system for you, allowing (most) users to avoid the webpack that wrangler includes. This would solve low-hanging issues (eg #62, #73, #81). There’s already very little reason to use webpack anyway, but really, this is the only unmatched benefit to offering a build-in CLI solution. In other words, even with a worktop/webpack plugin, there’s still the "exports" and ESM resolving issue that I (as the plugin) can’t fix without risking other resolutions breaking.

That said, just to reiterate, any esbuild/swc/Rollup configuration works out of the box. Webpack is purposefully counter-compliant here. 👎

Either as a worktop CLI or as a series of plugins, I’m going to want to do AST transformations. For long before worktop’s first public release, I’ve had a PoC that compiles away the worktop Router in production. Even though the Router is already fast and lightweight, this removes all doubt and produces the most optimized form of the equivalent routing logic.

If I ship a CLI, it’s easier to defend including an entire @swc/core installation. It also means that worktop could lean into other compile-time optimizations/rewrites. Going the plugins route, I’d have to sheepishly include all of @swc/core anyway, which is kinda like embedding a bundler within your existing bundler, or rewrite all the same AST operations using the target system’s offerings –– i’ve explored this for another project… it’s not fun.

CONs

  • Becomes an extra config file to learn/manage (can offer good defaults, but still)
  • Having a worktop build sorta implies the existence/inevitably of a worktop dev command Can always attach miniflare/equivalent, but the expectation will be there and creates far more scope.
  • Project scope grows significantly, especially trying to accomodate all existing user config
  • Worktop is actually really easy/simple to build now. It doesn’t need any of the special sauce I’m talking about here.

Current Stance

Right now, I’m thinking that if I do this, it’d all take place under another package. That would mean that your package.json looks something like this:

{
  "scripts": {
    "build": "worktop build"
  },
  "dependencies": {
    "worktop": "latest"
  },
  "devDependencies": {
    "worktop-builder": "latest"
  }
}

This way, you only buy into all of the build-time optimizations if you decide to actually use/install worktop-builder (name tbd). If you don’t install and use the toolkit, then you use worktop as you/we already do today.

Two quick polls to (anonymously) weigh in on the points raised here. Thank you~! 🙇

Plugins vs CLI

Single vs Separate Packages

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Reactions:2
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
lukeedcommented, Sep 26, 2021

Closing in favor of #95, which tracks the optimization work specifically. Already merged #94 which added the worktop.build package for a fast, simple-to-use bundler.

This will serve as an easy-yet-configurable solution for building a worktop Worker (or any Worker) instead of the default webpack nightmare that ships with wrangler by default.

1reaction
e0commented, Sep 15, 2021

Initially it sounds like this would be nice for the dev experience but the point about the project scope seems like it could be a lot of work for relatively little gain. I don’t know much about these different build systems (webpack vs rollup vs esbuild) but I do know that I have never liked webpack.

After a quick look, it looks like esbuild and swc are really interesting alternatives. I would try to get one of these to work with my current project and see if there is a noticeable difference compared to webpack when it comes to re-building the project during development. I think for me, and maybe other developers, it would be ideal to have a starter template with worktop and esbuild/swc.

Looking back now, I guess I didn’t think of exploring other options since webpack is default for wrangler. Even with webpack though, there hasn’t been any real problems since the initial hiccup with #62 and I could entirely focus on developing without thinking about the framework.

I can’t really comment on the other technical points since I don’t understand them enough. Just wanted to provide some thoughts on the onboarding experience. If that (onboarding) is a main motivation for considering this issue I personally feel like some effort in documentation/examples would be enough.

Read more comments on GitHub >

github_iconTop Results From Across the Web

12-How to use the command "Special Worktop" - YouTube
12-How to use the command "Special Worktop ". Watch later. Share. Copy link ... Include playlist. An error occurred while retrieving sharing ...
Read more >
Build Menu - No Man's Sky Wiki - Fandom
The Build Menu allows access to base building products. The Build Menu allows access to base building products and it can be opened...
Read more >
Create a serverless, globally distributed REST API with Fauna
Worktop solves common needs such as routing, path parameters, and HTTP methods. Edit package.json and add the build script:.
Read more >
Getting started with Fauna and Cloudflare Workers
The first step to creating a Cloudflare Worker, is to initialize the project by using the wrangler generate command:.
Read more >
Vanlife: Stunning DIY Wooden Countertop For Under $100
It commands so much visual power in determining the look of a kitchen. ... To build a countertop that is beautiful and light-weight, ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found