0

I have a custom .js file that I place inside the public folder in my NextJS app. I need to be able to use environment variables in that .js file, but environment variables don't seem to be available there.

I read that files in the public folder don't go through the webpack build process.

How do I customize my Next.js app so it builds an additional file inside the public folder? I found a suggestion (option 1 in the answer) on how to do it in a Vue.js app. Anyone know how to achieve something similar in Next.js?

artooras
  • 5,551
  • 7
  • 41
  • 67
  • Out of curiosity, what's the reason for having the env vars file in the `public` folder? – juliomalves Sep 20 '21 at 12:56
  • My script's functionality relies on the base path of the project. Currently I have two separate .js files in the public folder with identical code, but different base paths (localhost for dev, public url for production). I'd like to maintain just one file which compiles at build time accordingly. – artooras Sep 20 '21 at 13:22
  • 1
    Actually, I have just clarified the title of the question - it may have been a bit misleading... :) – artooras Sep 20 '21 at 13:45

0 Answers0