Skip to content
This repository has been archived by the owner on Aug 3, 2023. It is now read-only.

RFC: leverage Webpack as backend #69

Closed
xtuc opened this issue Apr 16, 2019 · 2 comments · Fixed by #94
Closed

RFC: leverage Webpack as backend #69

xtuc opened this issue Apr 16, 2019 · 2 comments · Fixed by #94
Labels
feature Feature requests and suggestions

Comments

@xtuc
Copy link
Member

xtuc commented Apr 16, 2019

Problem

Currently wrangler is coupled to wasm-pack, which makes it unpracticable for non-rust projects (especially JavaScript projects).

Proposal

Use Webpack as a backend to build any projects that use a Webpack configuration.

For prototyping, I made wranger-js and came up with a few demos https://github.com/xtuc/wrangler-js-demo to give you a better idea.

Note that we don't want to have multiple tools but rather add that support in wrangler to have a single tool.

Context about Webpack

With the integration of WebAssembly in Webpack, any loader can emit a wasm binary in Webpack that will be bundled along the JavaScript project.

That integration already implements the ECMAScript module integration, which make working with Wasm module easier in JavaScript.

Allows npm dependecies

Webpack is a bundler, npm dependecies are supported.

Optimize JavaScript

Webpack runs, in production mode, a JavaScript minifier. Also we could add Wasm optimization.

Auto generate the Worker's metadata.json

Webpack constructs the module graph of the project, we can look at it to find any wasm modules and generate the corresponding metadata.json.

@ashleygwilliams ashleygwilliams added the feature Feature requests and suggestions label Apr 18, 2019
@ashleygwilliams ashleygwilliams added this to the 0.3.0 milestone Apr 18, 2019
@ashleygwilliams
Copy link
Contributor

  1. what do we expect in the user's env (so we can install it and run it)
  2. what are the steps to run
  3. what are the templates we run the steps on

@xtuc
Copy link
Member Author

xtuc commented Apr 30, 2019

I made wrangler-js public: https://github.com/xtuc/wrangler-js/blob/master/index.js.

Here is what we use it for:

  • combine JavaScript packages: webpack
  • run Webpack
    • introspect Webpack's module graph for wasm binaries
    • concatenate JavaScript files
    • generate the bindings file
  • inject a prologue, that polyfills fetch + window

Here are the changes for moving the logic in wrangler:

I don't think it would be a good idea to send back to wrangler the entire Webpack graph because it can get pretty big; we should aggregate the information in wrangler-js and concatenate files I think.
The files could be written from wrangler.

The bindings file can be generated in wranger.

The prologue is just a string, it's easy to do in wrangler.

What do you think @ashleygwilliams ?

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
feature Feature requests and suggestions
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants