How to copy additional files e.g. config/config.yaml, to .next folder

Viewed 184

I have following folder structure for NextJS project:

_posts/ components/ hooks/ config/ <--- includes config.yaml file for server pages/ public/ .env.local ...

yarn build copies all dependencies correctly except config/ folder. It includes files that are needed to run server.

Is there any way to tell nextJS compiler/bundler to copy config/ folder inside .next folder?

Things that I tried:

  1. Updating 'build' step in package.json with cp -rf config/ .next/ && next build --- does not help. next build cleans .next folder. Disabling the auto-clean isn't useful.
  2. Going through documentation of next.config.js to see if there is a pre-build hook that can be used. --- there isn't any.
  3. Copying config/ folder after next build --- doesn't help as next build fails complaining about missing config/config.yaml file.
1 Answers

As suggested by @kyle, using ((process.env as any).POSTGRES_URL resolved the build issue.

I had another issue to run tests using mocha. I ended up using dotenv in the tests' execution flow (to load .env.test.local).

Related