We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
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
Hi, thanks for the scripts. Just wondering where to use them? Wasn’t aware we could use npm modules on CF workers?
The text was updated successfully, but these errors were encountered:
Yes, you can use npm modules on a CF worker. Just use Webpack to bundle one final script.
If this was your worker script worker.js:
worker.js
import cloudflareEdgeProxy from "cloudflare-edge-proxy"; const config = { defaultBackend: "https://example.com" }; const proxy = cloudflareEdgeProxy(config); addEventListener("fetch", event => { event.respondWith(proxy(event)); });
Then you could build a single bundle for CF with a Webpack config something like this:
module.exports = { entry: { worker: "./worker" }, target: "webworker", module: { rules: [ { test: /\.js$/, exclude: /(node_modules)/, use: { loader: "babel-loader", options: { presets: [ [ "@babel/preset-env", { targets: { chrome: "70" } } ] ] } } } ] } };
Sorry, something went wrong.
No branches or pull requests
Hi, thanks for the scripts. Just wondering where to use them? Wasn’t aware we could use npm modules on CF workers?
The text was updated successfully, but these errors were encountered: