Reputation: 6019
This Meteor template code is the default generated when meteor create myApp
is invoked. In main.js
the first 3 lines are:
import { Template } from 'meteor/templating';
import { ReactiveVar } from 'meteor/reactive-var';
import './main.html';
But when I comment them out, the app still runs. Reading the docs could not answer my question, Why do we need the import
statement if the app still runs without them? Thanks
Upvotes: 0
Views: 33
Reputation: 1399
Earlier versions of Meteor relied heavily on using the global namespace for accessing shared libraries. As of Meteor 1.3, you can now use Meteor's ES2015 module support. This means you can use import/export functionality to expose access to various parts of your codebase, without having to rely on globals. Using imports/exports is now the preferred/recommended way of referencing parts of your application, so meteor create
functionality was updated to demonstrate this. As you mentioned, you can remove the import
statements above and you will still be able to access Template
and ReactiveVar
globally (for backwards compatibility). It's important to note however that this might change in the future - Meteor has fully embraced ES2015 module support, and could potentially drop the use of globals completely (well, to the extent possible).
One more thing to note - Meteor 1.3 also introduced new "lazy-loading" functionality, wherein application code stored under an /imports
directory will no longer by eagerly loaded when the application starts up. Code stored under an /imports
directory will only be loaded if it's referenced by an import
statement somewhere else in your codebase. See Special directories for more info.
Upvotes: 1