Alias usage in ES6 'import'?

Viewed 567

This is one form from many others for import statement:

var promise = import("module-name");

but my question is about this form of the statement. This import can be used both in browsers and in nodejs apps.

Does module-name always one of:

  • URL (browsers apps)
  • path in filesystem (nodejs apps)
  • npm module name (nodejs apps)

Can we setup JS module loader to use aliases? For example, set mapping of aliases to URLs or to paths then import modules using aliases:

import.mapping({
    "utils": "http://server.com/js/lib/utils.js"
});

or

import.mapping({
    "utils": "/home/project/js/lib/utils.js"
});

then:

import("utils").then(mod=>{...});
0 Answers
Related