I have a meteor repo with server and client code imports which resolved in bundling time:
// src/models/messages
import { Meteor } from 'meteor/meteor';
if (Meteor.isClient) {
module.exports = require('./client/index.js');
}
if (Meteor.isServer) {
module.exports = require('./server/index.js');
}
As can be seen, I have a message model that imported in client code and server code, with the same path. When I develop with VSCode, IntelliSense couldn`t resolve such imports and I can use all power of the IDE.
Is there any way to configure IntelliSense to map source code with current environment? For instance, if I work in server code, when import { Messages } from '../../models/messages'
should be resolved as src/models/messages/server/index.js
?
After some research I have concluded that it is not possible. Best way is split server and client code with different imports. This should protect from unpredictable the code execution. However, if the code on server and client shares same contracts (interfaces) when it will be better to declare abstract classes and implement them in client code and server code. Then it will be possible to make such conditional import and protect yourself from runtime errors.