score:1

Update: This fails when you run ionic build because it defaults back to using react-scripts build.

Not sure why I didn't see this before, but taking a closer look at the bootstrapped ionic project, it’s clearly using create-react-app/react-scripts.

Although CRA demands you do a one-time eject in order to configure anything relating to the build, I was able to use react-app-rewired and customizable-cra to customise the build and start scripts. As far as I can tell this works fine with ionic.

score:1

You can customize webpack using react-app-rewired

If you don't use ionic cli to build and run your app, you can use a normal install of react-app-rewired.

If you use the ionic cli, there is an additional step/trick:

Ionic uses react-scripts under the hood, so you need to trick it into using react-app-rewired instead of react-scripts.

Here is a simple and low-invasive way to have Ionic cli use react-app-rewired instead of react-scripts: add this package.json postinstall script:

{
  "scripts": {
    "postinstall": "cd node_modules/.bin && mv react-scripts react-scripts-real && ln -s ../react-app-rewired/bin/index.js react-scripts",
    ...
  }
}

Related Query

More Query from same tag