Faster Meteor Reloads

Ok, that would make sense. I’m running my dev database in an MLab dev environment. So it appears to be that combined with putting certain folders within a client folder. Thanks for the help guys.

1 Like

Glad I was able to help!

1 Like

I couldn’t find where this is mentioned in the meteor guide. Is this new? Every tutorial/article says something like “imports/ui/…”. But I was wondering the same thing as @bp123. Why would a change to files in imports/ui cause a server restart. So, maybe the official guide’s file structure section just needs an update?

2 Likes

It would be good to get @sashko to comment on this.

1 Like

If you look at the Guide’s GitHub activity, you’ll find @hwillson and @abernix are your “go to” contacts.

1 Like

Yes, this should have been documented. See issue 7434 for more of the backstory. That being said however, there are changes coming in Meteor 1.7 that will greatly impact the imports sections of the Guide, so several updates will need to be made. Meteor 1.7 introduces a way to get rid of the imports directory completely, while still retaining non-eager loading. From the upcoming 1.7 release notes:

  • Applications may now specify client and server entry point modules in a
    newly-supported "meteor" section of package.json:

    "meteor": {
      "mainModule": {
        "client": "client/main.js",
        "server": "server/main.js"
      }
    }
    

    When specified, these entry points override Meteor’s default module
    loading semantics, rendering imports directories unnecessary. If
    mainModule is left unspecified for either client or server, the
    default rules will apply for that architecture, as before. To disable
    eager loading of modules on a given architecture, simply provide a
    mainModule value of false:

    "meteor": {
      "mainModule": {
        "client": false,
        "server": "server/main.js"
      }
    }
    

    Feature #135
    PR #9690

5 Likes

Ah, yes - might have been a lil’ bit misguiding. What I was implying is that you import your client-related stuff in main.js.
In essence, I always put everything client-related into root\imports\client\ and thus naturally all the files there and beyond tend to be imported via \root\client\main.js.
Anyway, a rule of thumb remains: if you change server-side code or code imported both on client and server - your meteor server will restart; which takes much more time.

2 Likes

I never realised that! This will save some serious reload time

1 Like

Just had a tinker with 1.7. Noice! Totally going this route. For any one interested, you can now put all your code in /src. Just add the mainModule bit in package.json to specifiy your entry points. Then run

meteor npm i --save-dev babel-plugin-module-resolver

and add this bit to .babelrc:

{
  "plugins": [
    [
      "module-resolver",
      {
        "root": ["./src"]
      }
    ]
  ]
}

Then you can import modules like

// src/api/someApi.js
console.log('hi')

// src/server/main.js
import 'api/someApi' // hi

On top of that, if you’re using VS Code, you would want to do this:

// jsconfig.json
{
  "compilerOptions": {
    "baseUrl": "src",
...

And VS Code will understand.

2 Likes