Specify root of the app for imports?

Is it possible to specify the root of the app for imports? For instance with webpack I can set up resolve.root in the config. If I have in my webpack config:

{
  "resolve": { "root": "src" }
}

then

import 'client/someFile.js;

will look under ./src/client/someFile.js but Meteor will only look into ./node_modules and won’t find the file.

1 Like

There’s this babel plugin: https://github.com/mantrajs/babel-root-slash-import

Which lets you do

import '/client/someFile';
2 Likes

Thanks for sharing this module. Is babel included by default in Meteor ? I simply have to create a .babelrc file at the root ?

Importing by slash root is supported in Meteor out of the box.

You’ll want to keep most things in the /imports/ directory, because anything outside of there is “eagerly loaded” - which means it’ll get packaged up for both client and server (outside of the special meteor folders) by default.

There has been some talk about making it possible to configure the special directories, and make the default no longer “eager” but that hasn’t been delivered yet. For now you’ll want to keep things in /imports.