It is sometimes very useful to differentiate between resolution in different contexts (server, browser, worker and why not tests)
An example is a shared library that should work in node, client and workers but with some differences. A common thing is to put the differing parts in separate files for each platform.
Suggested solution
import core from './core'
# resolves based on environment and config
# core.server.js
# core.browser.js
# core.worker.js
Description
It is sometimes very useful to differentiate between resolution in different contexts (server, browser, worker and why not tests)
An example is a shared library that should work in node, client and workers but with some differences. A common thing is to put the differing parts in separate files for each platform.
Suggested solution
With the following configuration
Alternative
The alternative would be to explicitely check for the current environment and use dynamic imports which is quite a gymnastic.
Additional context
A part of this pattern (Platform-specific extensions) is quite common and useful in react-native https://reactnative.dev/docs/platform-specific-code#platform-specific-extensions
Validations