Skip to content

ENV vars in config #5204

Answered by angeloraso
JarrodMFlesch asked this question in Q&A
Nov 3, 2021 · 3 comments · 3 replies
Discussion options

You must be logged in to vote

Hi. You could create a script that replaces the environment variable with its value with "fs"

script.js

const environmentFile = require('../environments/environment.ts');
const fs = require('fs');

const REACT_APP_SITE_URL = /* Get variable value */

const capacitorConfigPath = 'capacitor.config.json';

fs.readFile(capacitorConfigPath, 'utf8', (err, file) => {
  if (err || !file) {
    console.log('CAPACITOR CONFIG FILE ERROR');
    return;
  }

  let capacitorConfigFile = JSON.parse(file);

  capacitorConfigFile.server.url = REACT_APP_SITE_URL;

  capacitorConfigFile = JSON.stringify(capacitorConfigFile, null, 2);

  fs.writeFile(capacitorConfigPath, capacitorConfigFile, err => {
    if …

Replies: 3 comments 3 replies

Comment options

You must be logged in to vote
1 reply
@JarrodMFlesch
Comment options

Answer selected by JarrodMFlesch
Comment options

You must be logged in to vote
2 replies
@mirko77
Comment options

@jcesarmobile
Comment options

Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
6 participants