Skip to content

Instantly share code, notes, and snippets.

@damienromito
Last active June 8, 2023 13:22
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save damienromito/e6b3930ffde4c7240f109d1de69febb5 to your computer and use it in GitHub Desktop.
Save damienromito/e6b3930ffde4c7240f109d1de69febb5 to your computer and use it in GitHub Desktop.
node script to rewrite capacitor.config.json for livereload
const ip = require('ip')
const fs = require('fs')
const path = require('path')
const configPath = path.resolve(__dirname, '../capacitor.config.json')
let rawdata = fs.readFileSync(configPath)
let capacitorConfig = JSON.parse(rawdata)
const arg = process.argv[2]
if(arg === 'dev'){
capacitorConfig.server = {
url: "http://" + ip.address() + ":3001",
cleartext: true
}
}else{
delete capacitorConfig.server
}
fs.writeFileSync(configPath, JSON.stringify(capacitorConfig, null, 2))
...
"scripts": {
...
"start": "HOST=0.0.0.0 PORT=3001 react-app-rewired start",
"live-ios": "yarn config-cap-dev && npx cap sync ios && npx cap open ios",
"config-cap-dev": "node generateCapacitorConfig.js dev",
"config-cap-prod": "node generateCapacitorConfig.js",
"build": "react-app-rewired build",
"build-all": "yarn config-cap-prod && yarn build && npx cap sync ",
...
}
...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment