OfficeDev / generator-office

Yeoman generator for building Microsoft Office related projects.
https://www.npmjs.com/package/generator-office
MIT License
819 stars 207 forks source link

Different .env files in an Excel add-in project (React) #754

Closed stefan-bozic-quantox closed 1 year ago

stefan-bozic-quantox commented 1 year ago

Hello, I'm working on an Excel add-in, and it's written in React. I followed Microsoft docs (https://learn.microsoft.com/en-us/office/dev/add-ins/quickstarts/excel-quickstart-react). I have different .env files for different environments: .env.development, .env.qa, .env.staging, and .env.production. My question is: how can I dynamically pass the environment I want to use (so something like webpack --env environment=staging) to webpack.config.js? When I run npm start (office-addin-debugging start manifest.xml) everything that I try to pass to webpack.config.js is overwritten with { env: { WEBPACK_SERVE: true } }.

millerds commented 1 year ago

The webpack command is controlled by the "dev-server" script in package.json. The debugging cli uses that script entry to start the dev server.

From what I see in the webpack documentation . . . adding those arguments to the webpack command sets env variable values and I don't see anything that suggests being able to specify an env file on the cli. You'd have to do some digging into webpack solutions for importing an env file and then adjust the dev-server command accordingly.