[QUESTION] import HTML with JS

Hi every body,

I would like deepening my use with Meteor and his templating.

Currently, i use classic with a JS file that contains my helpers and my events. But, on the doc and tutorial, i see this :

import './body.html';
import { Template } from 'meteor/templating';

I do not understand the difference between classic and import with ES6 (only for HTML).

Do you have any links to the doc that explains this ?

Thak you community !

That’s there to enforce load order. In effect it’s saying “I need body.html loaded before the code in this file is executed”.

Meteor classic has a set of rules which control load order.

Thank you @robfallows :slight_smile:

I’ve latest question, about module meteor. How know what module must load ?

Example :

import { Template } from 'meteor/templating';

It’s for all helpers ? When i creat new collection, i must import mongo too ?

Thank you !

So, you can develop with Meteor in the “classic” way (no imports anywhere). However, that’s likely to change sometime after the next few releases.

If you want to develop using imports (ES6 standard), then yes - you must import everything which is “external” to the particular file you are working on. As far as collections are concerned, the currently recommended way is to first declare your collection as an export in its own file under imports/api. For example, in imports/api/MyCollection.js:

export const MyCollection = new Mongo.Collection('MyCollection');

Then, in every file where you need to use it, you do:

import { MyCollection } from '/imports/api/MyCollection';

Hi @robfallows

About the lib folder that contains collections, It is also moved in “import” ?

Yes - although the recommended location is imports/api/YourCollectionName.js.

1 Like

Thank you @robfallows for your kick reply.

I’ve last question about the naming file with meteor. I see your file name is CamelCase. This is a recommendation related to the import of meteor or just a good practice?

This is a Meteor Guide recommendation for collections.