Replace text with JSON formatI bundle SPA application (CRA, for example) to artifact and want to use same artifact for multiple environment (e.g. Dev, Staging, Prod). Since environment variable for most SPA is injected while building, We can't inject any environment variable after bundle is built. As CRA suggest that you can inject environment as runtime by using server to replace placeholer with JSON before sending response. But for simple storage hosting our SPA (e.g. AWS S3) we can't do that. So I got this idea to inject variable to artifact before deploy to server. So we don't need to have multple artifact per environment. UsageThis task work as title say, it replace text with JSON. It can use for inject variable in artifact or what ever you want. Let's assume we want to inject variable from Azure devops to our SPA. We want to change API URL and GG analytic UA code based on environment(Dev, Staging, Prod)
Development in local, how we handle ?You can use environment variable for development. You can write simple check like this
You can go further by create utility function for getting value.
|