React-app-rewired: How to pass argument to config-override?

Created on 23 Dec 2017  路  3Comments  路  Source: timarney/react-app-rewired

Hi, I want to pass argument to rewire for webpack-bundle-analyzer, is it possible?

react-app-rewired build --bundle-report
if (env === "production") { // && arg === "--bundle-report"?
   config.plugins.push(new BundleAnalyzerPlugin());
}

Most helpful comment

In the override:

const bundleReportIndex = process.argv.indexOf('--bundle-report');
if (env === 'production' && bundleReportIndex !== -1) {
  config.plugins.push(new BundleAnalyzerPlugin());
}

Then when you actually do the command line: npm run build --bundle-report or yarn build --bundle-report.

If you want a script target in package.json:

"scripts": {
  "build": "react-app-rewired build",
  "build:bundle": "react-app-rewired build --bundle-report"
}

and then run it with npm run build:bundle or yarn build:bundle.

All 3 comments

In the override:

const bundleReportIndex = process.argv.indexOf('--bundle-report');
if (env === 'production' && bundleReportIndex !== -1) {
  config.plugins.push(new BundleAnalyzerPlugin());
}

Then when you actually do the command line: npm run build --bundle-report or yarn build --bundle-report.

If you want a script target in package.json:

"scripts": {
  "build": "react-app-rewired build",
  "build:bundle": "react-app-rewired build --bundle-report"
}

and then run it with npm run build:bundle or yarn build:bundle.

Thanks! 馃憤

I would use just environment variables set directly in cli or with help of .env* files, if I were you. Then you just check it with process.env.MY_VAR

Was this page helpful?
0 / 5 - 0 ratings

Related issues

brendonco picture brendonco  路  3Comments

srhise picture srhise  路  5Comments

lyudad picture lyudad  路  6Comments

IEfucker picture IEfucker  路  5Comments

lcyuhe picture lcyuhe  路  5Comments