Created by: jamescostian
Uses @babel/register
and moduleFileExtensions
so that you get just as much love and support in src/setupProxy
as you would in, say, src/index
.
Fixes #8046 and #6794 (closed)
Try it out by cloning this branch and then running this:
yarn run create-react-app --template file:packages/cra-template-typescript ../pr-10228
cd ../pr-10228
echo "export default function(a) {throw new Error('It worked!')}" > src/setupProxy.mjs; yarn start
rm src/setupProxy.mjs; echo "module.exports=a=>{throw new Error('It worked!')}" > src/setupProxy.cjs; yarn start
rm src/setupProxy.cjs; echo "export default function(a: any) {throw new Error('It worked!')}" > src/setupProxy.ts; yarn start
Notice how all three times that yarn start
are run, you get an error saying "It worked" - this shows that cra paid attention to all the files, parsed their syntax correctly, and ran them (if they weren't run, you wouldn't see that error, and if they weren't parsed properly, you'd get a syntax error).
Additionally, you can drop the --template file:packages/cra-template-typescript
bit in line 1, and lines 4 and 5 (cjs and mjs) will work.