Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Overriding package.json keys while running npm script command

I have an electron application.

My package.json has some app-specific settings like serverUrl, type_of_application etc. I am using these settings in the application.

When building an application with electron-builder I want to override these configs key values with different values.

I will be building same application with different serverUrl for different type_of_application. Also there is possibility that these will be installed on same machine so I also want to change package name and productName key values for different builds.

So my target is to have separate config files with all these settings to build application with different settings. And when building I will use one of the the config file and that should override default configs in package.json file.

One possibility is to have complete package.json for different kind of builds, but in that case dependencies etc. keys will also be duplicated which will be hard to manage when a new dependency is added.

Is there any way I can achieve this?

like image 575
Harshveer Singh Avatar asked Mar 09 '18 16:03

Harshveer Singh


1 Answers

One strategy would be to keep all app specific configuration in one or more separate config files which your app loads on startup.

I tend to keep such files under APP_HOMEDIR/etc (a nod to my Unix roots), named for each app environment you require.

Update

For Electron app development using electron-builder, a configuration key exists extraMetadata that allows you to inject values set in your package.json per build.

See electron-builder configuration for further info.

(Thanks to the OP Harshveer Singh for suggesting this update.)

like image 167
Rob Raisch Avatar answered Oct 18 '22 14:10

Rob Raisch