Open rmcsharry opened 6 years ago
Well I ran ts-node
with your code in a set-env.ts
file and this worked well.
To avoid conflicts with Angular's TS config I would advise to put your tool (with its own tsconfig.json
and package.json
) in a separate cli
directory sibling to src
(so that Angular CLI won't try to compile your tool when compiling its src
files).
As an extra step, you can ask your product package.json
target to call your tool cli/package.json
ones, like:
"scripts": {
"build:production": "cd cli && npm run build:production",`
}
Thanks thanks thanks for this, but... I have the same problem with 'fs' , I am not sure at all to try @Javarome 's idea because I have mi app deployed in heroku, Does somebody know another way to fix this... or if someone can explain me better the previous idea, plsss :(
@JrogeT this is so long ago for me that I have forgotten it (and no longer have access to the code). Sorry, cannot help. :(
Thanks for the great article on medium, which I used for Angular 2 to 5....but now in Angular 6, you can no longer import 'fs'. You can read more about that here.
Note there are many posts that say you can still import 'fs' in a typescript file by changing your tsconfig.ts compiler options to the module setting of 'commonjs':
So that does work, and if your use case is simple that is all you need to do.
However you might be doing other stuff that might not work - for me, I want to read the package.json and extract the app name and app version, which in theory should work since from Typescript v2.9 it now supports reading json files
I tried but could not get that to work.
However, you can just recode this idea using plain javascript. Here is my example (I have simplified so I am not using yargs here to process arguments).
Then you can use node, no need for ts-node, to execute it:
node set-env.js
More info in the answer from Rzassar here.
If you have to manage multiple environments, this is also worth reading.