简体   繁体   中英

How define runtime for meteor development for IntelliSence in vscode

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM