i have some confusion regarding the application structure guide. As far as i understand from the guide that, anything under import folder will be lazy loaded or you can say will load when called via import. and ouside of import folder will be loaded as soon as application starts running.
when i’m installing FlowRouter, my app need to have home ( / ) router.
My question is
what do i need to write in my main.js file and what exactly is entry point meaning.
will I import my route file and all layout, templates in main.js file?
do imports/startup/ directory files will be executed automatically after app starts to run? or do i need to enclose it within Meteor.startup function.
I’ll break down how the Guide’s todos reference app is handling this, as an example.
When the todos app starts up client/main.js is one of the eagerly loaded files (since it’s not under the imports directory). This means its contents are evaluated right away:
import '/imports/startup/client';
This import statement then loads the defined imports/startup/client/index.js file (since only the directory was specified in the import statement). The index.js file then includes an import statement to load the routes.js file from the same directory:
import './routes.js';
The routes.js file defines your FlowRouter routes, but also imports any templates referenced by the route config (such as your layouts, top level pages, etc.).
No they aren’t executed automatically - in the case of the todos app for example, you’re telling your app to load the startup files by referencing them when your app starts up, via the eagerly loaded client/main.js and server/main.js files.
No, not all of them. Just the ones that FlowRouter needs to know about to initialize properly. For example, in imports/startup/client/routes.js, the app-body.js layout is imported since it’s needed by the defined FlowRouter config directly. app-body.js itself imports the imports/ui/components/loading.js component; this file doesn’t need to be imported in the routes.js file directly.
I can no longer find any documentation on the default eager load order based on file names and structure. This used to be in Meteor docs, but was removed. In fact, it is still referenced in the docs in modules package with a redirect to this section of the Meteor Guide.
I think some of this info needs to be added back to this section of the guide as 1) not everyone will or wants to adopt 100% import structure, and 2) there are still some special directories such as /public, /private, and mobile /resources, etc.
Are the index.js files really necessary when all they contain are import statements that could instead be written in client/main.js and server/main.js?
i.e. could these be moved out of imports/startup/client/index.js
They could be, but if you’re then referencing routes.js and useraccounts-configuration.js in the same directory like your example shows, that means they’re in /client (outside of the imports directory), and will be eagerly loaded. If you wanted to update /client/main.js with something like:
The Guide/todos app are just suggesting a structure, and recommend keeping the contents of the default eagerly loaded files (like /client/main.js and /server/main.js) to a minimum, to help better control load order.