Created by: jamescostian
Fixes #6794 (closed), with mo's prior work as a fantastic starting point. Relevant docs were also updated.
When you use cra-template-typescript
, this code will install @babel/register
. Any projects that have @babel/register
as a dependency (or devDependency) will cause @babel/register
to be imported before importing src/setupProxy
. Although I haven't tested it, this should also allow for other things like flow to work.
To verify my changes work, you may run the following:
git clone --single-branch --branch improve_ts_extension_support https://github.com/jamescostian/create-react-app.git
cd create-react-app
yarn
npm run create-react-app -- --use-npm --template typescript try-it-out
cd try-it-out
# Note that in the below line, it's a .ts file instead of a .js file
echo "module.exports = app => app.get('/proxied', (req, res) => res.send('IT WORKS!'))" > src/setupProxy.ts
# Make the changes immediately obvious
echo "location.pathname = '/proxied'" >> src/index.tsx
npm start
You will be brought to http://localhost:3000/proxied
and see that it's proxying the request successfully to src/setupProxy.ts
.