1

I have a component library made with create-react-app where I'm using nwb to serve a demo application to test the components. Right now the application is served by running the command nwb serve-react-demo which starts the demo app with no issues.

I want to simulate different applications using the library. Setting an environment variable directly when running the start up script would be really helpful since I could change the initial state of the application based on which host app was implementing the library. If I try to pass an environment variable like this nwb serve-react-demo REACT_APP_HOST_APPLICATION=AB the process.env.REACT_APP_HOST_APPLICATION variable is undefined.

The nwb documentation states that you can configure the configuration object by passing arguments with the command, but I'm unclear on how to add variables to process.env like that.

I'm running macOS 10.15.3

from package.js:

"nwb": "0.23.0",
"react": "16.9.0",
"react-dom": "16.9.0",
"react-scripts": "3.2.0",
"webpack": "4.41.0",
"webpack-dev-server": "3.2.1"
matsomo
  • 460
  • 1
  • 6
  • 16

1 Answers1

1

My solution ended up being creating one nwb.config.js file for each application, hardcoding the host application key with webpack define, and then with the --config flag pass the location of each file.

You can find a detailed explanation of my solution here.

matsomo
  • 460
  • 1
  • 6
  • 16