@@ -104,24 +104,24 @@ export async function bundleServer(buildOpts: BuildOptions): Promise<void> {
104104 ] as Plugin [ ] ,
105105 external : [ "./middleware/handler.mjs" ] ,
106106 alias : {
107- // Note: it looks like node-fetch is actually not necessary for us, so we could replace it with an empty shim
108- // but just to be safe we replace it with a module that re-exports the native fetch
109- // we do this to both save on bundle size (there isn't really any benefit in us shipping the node-fetch code)
110- // and also get rid of a warning in the terminal caused by the package (because it performs an === comparison with -0)
107+ // Workers have `fetch` so the `node-fetch` polyfill is not needed
111108 "next/dist/compiled/node-fetch" : path . join ( buildOpts . outputDir , "cloudflare-templates/shims/fetch.js" ) ,
112- // Note: we apply an empty shim to next/dist/compiled/ws because it generates two `eval`s:
113- // eval("require")("bufferutil");
114- // eval("require")("utf-8-validate");
109+ // Workers have builtin Web Sockets
115110 "next/dist/compiled/ws" : path . join ( buildOpts . outputDir , "cloudflare-templates/shims/empty.js" ) ,
116- // Note: we apply an empty shim to next/dist/compiled/edge-runtime since (amongst others) it generated the following `eval`:
117- // eval(getModuleCode)(module, module.exports, throwingRequire, params.context, ...Object.values(params.scopedContext));
118- // which comes from https://github.com/vercel/edge-runtime/blob/6e96b55f/packages/primitives/src/primitives/load.js#L57-L63
111+ // The toolbox optimizer pulls severals MB of dependencies (`caniuse-lite`, `terser`, `acorn`, ...)
112+ // Drop it to optimize the code size
113+ // See https://github.com/vercel/next.js/blob/6eb235c/packages/next/src/server/optimize-amp.ts
114+ "next/dist/compiled/@ampproject/toolbox-optimizer" : path . join (
115+ buildOpts . outputDir ,
116+ "cloudflare-templates/shims/throw.js"
117+ ) ,
118+ // The edge runtime is not supported
119119 "next/dist/compiled/edge-runtime" : path . join (
120120 buildOpts . outputDir ,
121121 "cloudflare-templates/shims/empty.js"
122122 ) ,
123- // `@next/env` is a library Next.js uses for loading dotenv files, for obvious reasons we need to stub it here
124- // source: https://github.com/vercel/next.js/tree/0ac10d79720/packages/next-env
123+ // `@next/env` is used by Next to load environment variables from files.
124+ // OpenNext inlines the values at build time so this is not needed.
125125 "@next/env" : path . join ( buildOpts . outputDir , "cloudflare-templates/shims/env.js" ) ,
126126 } ,
127127 define : {
0 commit comments