How to Include Files in the api Dist folder when running "yarn rw dev"

image

i would like to include other files in the dist folder when running “yarn rw dev”. How can i do so ?

I don’t think the current build process supports copying over files like json, unless there has been a change to the build process in recent months. Please correct me if I’m wrong @dom @danny

We had a similar requirement in one of the PR in past, since it was just one file, we just decided to convert that to js file. Would something like this work for your usecase?

Can they not use the CopyWebpackPlugin? – GitHub - webpack-contrib/copy-webpack-plugin: Copy files and directories with webpack

It can be an option for me at the moment. Thanks

I’m running into the same issue. Any tips for getting CopyWebpackPlugin with the API side?

1 Like

@kdsketch, sorry for no one responding here yet. I don’t know a good answer right now so I’ll try to get some information from the wider core team and reply here when I have something from them.

Hi @kdsketch , when I’ve needed to have some local data deployed so my service can read it, I’ve just made the file an actual js/ts file as seen here: redwoodjs-streaming-realtime-demos/api/src/lib/data/movies.ts at main · redwoodjs/redwoodjs-streaming-realtime-demos · GitHub

While not done here, in some there projects I have kept:

  • data (the raw json files) in a data directory (same level as web and api)
  • write a script that read the data/*.json file and wrote the .js or .ts file into somewhere in the api directory.
  • that script would run on build or deploy (manually or by making a new script action in package json and using that script for deploy). Or, if using something like Netlify, there are pre and post build task hooks that can do that.

This way the file gets bundled easily, the data can be updated, and a service can access it,

Of course adding this data to your api does increase the size of your deploy.

Some alternatives might be to store the data:

  • in S3
  • in a JSON field in your db
  • cache the fetch of this data

Very helpful, thanks!

1 Like