seanpmaxwell / express-generator-typescript

Create a new express app similar to express-generator but with TypeScript

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Is there a way to build the application in development mode so that dotenv files are copied to dist/pre-start?

umbe1987 opened this issue · comments

First of all, many thanks for this neat project! :)

I am trying to figure out how to create a script in the package.json file so that when building the application in a local environment the dotenv files in src/pre-start are automatically copied to the respective dist folder.

The reason is that my project has a frontend and a backend part.

The frontend is usually built into the dist/public folder of the express app, and then it is served by the backend.

However, I would like to access different environment variables defined in my development.env file, but I cannot do it right now since the only one present is apparently only production.env.

I guess it is normal behavior, but anyone knows how can I do it? copying manually or inserting a cp command into the package.json scripts?

Thanks in advance.

So you're trying to get various .env files into your production env (i.e. development.env). I wouldn't recommend that. You should really only have one .env per environment. You could create another .env file called shared.env and load that for every env. Although I usually just hardcode variables that are used for every env.

Thanks for the suggestion!

I thought they were there due to the express-generator itself.

If I look in https://github.com/seanpmaxwell/express-generator-typescript/tree/master/sample-output/express-gen-ts/src/pre-start/env for example, I can see them.

Also, I guess the build.ts is copying the production.env one inside the dist folder.

I might be wring though...

They are part of the project files that are copied when building. You can modify build.ts as your project needs change.

Ok, thanks for your time and the clarification. I really appreciate it!
I am closing this then.

thx please star if you haven't