question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

How to use different codebase for different build targets?

See original GitHub issue

Hi guys,

Is it possible for electron-builder to build app with different codebase based on specific target?

For specific OS platforms we can use it the following way:

if (os.platform == 'linux') { console.log('Hello Linux') }
else if (os.platform == 'win32') { console.log ('Hello Windows') }
else if (os.platform == 'darwin') { console.log('Hello macOS') }

Can we accomplish something similar with electron-builder:

if (target == 'appx') { removeUpdates() }
else if (target == 'appimage') { console.log('I love Linux') }  

I believe there should be the way. Just kindly ask you for the direction.

Thanks!

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:5 (4 by maintainers)

github_iconTop GitHub Comments

2reactions
black-snowcommented, Oct 7, 2017

@vasyl-shumskyi I guess you mean within the application code, not in the build process, right? I guess we could add some env var telling which target was used but I’m not sure if we should.

A rather easy way would be to have some separate file that’ll be copied for certain targets. You could have a .target file containing the target as a string. Or you could, prior to building, write some const TARGET='whatever' right in your application code. There might also be a way to just detect whether the app was installed via store or not. The windows apps dir mimics the native directory structure but maybe you can get the full (real) path to your application and see whether it’s within a special directory or not. There could also be some win API or store helper functionality. I think any of these possible solutions would be better than having electron-builde fiddle with the runtime or vars.

If I were you first thing I’d do is play around with fs and see what’s the installation path. Or take a look at something like this: https://www.npmjs.com/package/@nodert-win10/windows.applicationmodel.store.preview

Hope that helps.

1reaction
develarcommented, Oct 7, 2017

The another issue — is that you cannot build more than 1 target, because app is packed only once during build per platform, and then targets applies. This issue will be fixed only when some user will ask us to fix it and provide details 😃 For example, if it will be required for webpack — it is a little bit different story due to internal reasons than generic case.

Read more comments on GitHub >

github_iconTop Results From Across the Web

How do I use CMake to build my codebase for different ...
Just create multiple targets, one target per component: # Setup three "components" add_library(first source1.cpp source2.cpp) ...
Read more >
Multiple apps from one code base - multiple projects or targets ...
I think you have at least 3 options here: Separate projects. It is more difficult to share code across projects, but with Xcode...
Read more >
SETTING UP XCODE TARGETS. How to create multiple iOS ...
To easily differentiate between the builds, you can use a different display name and app icon, as shown below. Development and Production builds...
Read more >
The Build of a project depends on different targets and the ...
The issue is that we have a codebase which we build a number of times with different #defines(multiple #ifdefs within C files).
Read more >
One Code Base, Multiple Targets - YouTube
Yes, Zephyr makes it super easy to use the same base code on different devices. Here's the full talk from 6.9.22.Code use in...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found