No, its not possible to read a ts file in script tag (atleast without first compiling it to js).
What you can do however, is to use environment variables instead, and let react-scripts compile it into your template as it already does everytime you start the dev server or run the build.
start here:
https://create-react-app.dev/docs/adding-custom-environment-variables
First, create an env file called .env
at the root of our project
Next, lets add our environment variable to this file:
REACT_APP_GOOGLE_MAPS_KEY=<your key>
Finally, lets modify index.html to reference our environment variable:
<script type="text/javascript" src="https://maps.googleapis.com/maps/api/js?key=%REACT_APP_GOOGLE_MAPS_KEY%"></script>
As a final thought, instead of going to all this trouble, you could instead include your google maps dependency where needed in the preferred react way: by using a react plugin. Check this out. it will take care of loading/unloading the api for you, and you can pass your key in from config when you load the api:
https://www.npmjs.com/package/@react-google-maps/api
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…