0

package.json includes:

"scripts": {
  "build": "export MY_APP_GTAG=UA-123456-1 && node increment-build.js && npm run build-css && node scripts/build.js",
},

Index.html includes:

<script async src="https://www.googletagmanager.com/gtag/js?id=%MY_APP_GTAG%"></script>
<script>
  window.dataLayer = window.dataLayer || [];
  function gtag(){dataLayer.push(arguments);}
  gtag('js', new Date());

  gtag('config', '%MY_APP_GTAG%');
</script>

The value for MY_APP_GTAG also exists in my .env file:

MY_APP_GTAG=UA-123456-1

In the build script, is it possible to fetch the value for MY_APP_GTAG from the .env file? Instead of hard-coding the value in package.json.

I've tried

  "build": "export MY_APP_GTAG=${process.env.MY_APP_GTAG} && ...",

but that doesn't work.

Nick
  • 3,496
  • 7
  • 42
  • 96

1 Answers1

0

Refer to this solution about setting up your env to be read from the package.json file and post your items in the env.