Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to configure react-script so that it doesn't override tsconfig.json on 'start'

I'm currently using create-react-app to bootstrap one of my projects. Basically, I'm trying to set up paths in tsconfig.json by adding these to the default tsconfig.json generated by create-react-app:

"baseUrl": "./src", "paths": {   "interfaces/*": [     "common/interfaces/*",   ],   "components/*": [     "common/components/*",   ], }, 

However, every time I run yarn start which basically runs react-scripts start, it deletes my changes and generates the default configurations again.

How can I tell create-react-app to use my custom configs?

like image 996
CodeIntern Avatar asked Dec 15 '18 16:12

CodeIntern


Video Answer


1 Answers

I was able to do this by using advice from this issue.

Put the configuration options react scripts likes to remove in a separate file (e.g. paths.json) and reference it from tsconfig.json via the extends directive.

paths.json:

{   "compilerOptions": {   "baseUrl": "./src",   "paths": {     "interfaces/*": [ "common/interfaces/*"],     "components/*": [ "common/components/*"],     }   } } 

tsconfig.json

{   "extends": "./paths.json"    ...rest of tsconfig.json } 
like image 62
Glenn Avatar answered Sep 20 '22 18:09

Glenn