-
-
Save damienromito/e6b3930ffde4c7240f109d1de69febb5 to your computer and use it in GitHub Desktop.
node script to rewrite capacitor.config.json for livereload
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
... | |
"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