Conditional Module Loading
See original GitHub issueI’ve noticed that the components in this project seem to mirror each other between macOS and windows. I assume that this is to enable developers to write the same code for both platforms? What’s the suggested way of conditionally loading the correct component based upon the current platform? I don’t think that something like this is supported:
if (process.platform === 'win32') {
import { Window, TitleBar, Text } from 'react-desktop/windows'
} else {
import { Window, TitleBar, Text } from 'react-desktop/macOs'
}
Imports have to be top level statements.
I’ve also experimented with something like this:
const platform = (process.platform === 'win32') ? 'windows' : 'macOs';
import { Window, TitleBar, Text } from `react-desktop/${platform}`
This doesn’t work because import statements don’t support string templates (or variables for that matter).
Any other ideas? Do I need to switch to SystemJS or something?
Issue Analytics
- State:
- Created 7 years ago
- Reactions:1
- Comments:7 (2 by maintainers)
Top Results From Across the Web
Module::Load::Conditional - MetaCPAN
DESCRIPTION. Module::Load::Conditional provides simple ways to query and possibly load any of the modules you have installed on your system during runtime.
Read more >Loading Modules Conditionally in Angular
Loading Modules Conditionally in Angular. One of the very common features of Admin dashboard applications is Access Control. This is usually achieved ...
Read more >Global Variables - $Module::Load::Conditional::VERBOSE
Module ::Load::Conditional provides simple ways to query and possibly load any of the modules you have installed on your system during runtime. It...
Read more >Conditional Loading - StealJS
Conditional Loading is a way to conditionally load a module based on run-time conditions. Using a special syntax you can conditionally load code...
Read more >How can I conditionally import an ES6 module? - Stack Overflow
You can now call the import keyword as a function (i.e. import() ) to load a module at runtime. It returns a Promise...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
You can now import components based on the current OS like so:
It decides what to import. If you want to decide you can import using
react-desktop/macOs
orreact-desktop/windows