Ionic-cli: feat: Custom script for running React apps using Capacitor

Created on 3 Sep 2019  路  4Comments  路  Source: ionic-team/ionic-cli

_Original issue by @ch4rlesyeo on 2019-09-01T01:15:53Z_

Feature Request

Ionic version:
[x] 4.x

Describe the Feature Request
Allow Ionic/Capacitor to run custom scripts for running React app. (Capacitor runs react-scripts start by default)

Related Code
We could run something like node scripts/start.js to jump start our React apps in development mode and node scripts/build.js to production mode.

Additional Context
In cases we couldn't ideally build our React apps with CRA pre-configured settings and will need to eject CRA to customise Webpack in our project.

triage

Most helpful comment

Add "ionic:serve" to your package.json with the script you use to start your development server, like:

"scripts": {
    ...
    "ionic:serve": "react-app-rewired start" 
  }

Then you can run ionic cap run android -l --external to execute the development app in your device.

All 4 comments

@ch4rlesyeo I think this is already possible. See these docs. Let me know if there's an issue, though.

it's not clear, how I can build with Cordova after Create React App ejected.

I imagine this is a blocker for anyone using Ionic React in a Monorepo as CRA needs to either be extended (e.g. via react-app-rewired) or ejected entirely in order for the necessary customizations required of a Monorepo to be applied. Either way, if the CLI is hardcoded to invoke react-scripts than there appears to be no workaround or solution to this blocking limitation. I very much propose updating Capacitor to invoke the package scripts directly rather than assuming react scripts. Currently this is a huge blocker for my Team.

Add "ionic:serve" to your package.json with the script you use to start your development server, like:

"scripts": {
    ...
    "ionic:serve": "react-app-rewired start" 
  }

Then you can run ionic cap run android -l --external to execute the development app in your device.

Was this page helpful?
0 / 5 - 0 ratings