简体   繁体   中英

Meteor index.js is implied, how?

I have a pretty basic question and I've read through the Meteor Application Structure but this is still a little confusing:

In meteor chef's understanding the imports directory , it says that:

The index.js file is implied by not specifying a filename on the end. This is also known as an "entry point" file.

When I ran meteor create testproject --full to create a new project, in /client/main.js it writes import '/imports/startup/client';

Why doesn't main.js include the index.js file directly?
Why does import '/imports/startup/client' automatically include the index.js file only?

In Meteor's official documentation, index.js is not a reserved word.

  1. HTML template files are always loaded before everything else
  2. Files beginning with main. are loaded last
  3. Files inside any lib/ directory are loaded next
  4. Files with deeper paths are loaded next
  5. Files are then loaded in alphabetical order of the entire path

Quoted from another question.

As Styx's comment points to, importing the index.js file is a characteristic of the CommonJS module system, which Node uses a version of and Meteor uses under the hood on the client.

The scaffold elects to not specify the index.js file for brevity.

It's also worth noting that the load order you've quoted does not apply when using the imports directory and ES6 imports. Files will be loaded in the order that they are referenced by the code.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM