Adding a loader to pages worker

I have a worker witch is sharing a .geojson file with the UI, if the file is named .json everything is working.
But if I name the file .geojson wrangler throws an error:
✘ [ERROR] No loader is configured for “.geojson” files: src/config/places.geojson

How should I configure a loader for the page worker.

PS: my definition for the UI side Webpack5:

 rules: [
          test: /\.geojson$/,
          loader: 'json-loader' //external loader
          //type: 'json' //use internal loader

At this time you can not customise the way that Pages Functions are built by default (they use esbuild under the hood), so you can’t add custom loaders like in webpack unfortunately, sorry.

You could however build your own _worker.js using Advanced Mode of Functions, using webpack or any other bundler of your choice. The documentation for this isn’t fantastic yet, but if you really want to handle the build yourself, it’s the only real option today.

More customised standard builds is definitely something the team want to support in future though, so stay tuned. I’d recommend joining the Cloudflare developers discord at Cloudflare Developers to stay up to date there - many of the Pages team are active and provide sneak peaks at upcoming features and changes!

1 Like

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.