Import path tutorial

How to correct write paths when import some files? Any tutorial about this?

(example)
'../../../imports/client/components/TodoPagination' (why 2 dots? why 3 time? etc.???)

I believed, with'<base href="/">' in your head tag, You basically can refer any file start from ‘/’ which in the case of your example: ‘/imports/client/components/TodoPagination’

Take a look at https://nodejs.org/api/modules.html#modules_file_modules
and: http://bytearcher.com/articles/loading_modules_with_require/

Cheatsheet:

/* Directory structure:
 *   MyApp/
 *     .meteor/
 *     imports/
 *       a.js
 *       b.js
 *       child/
 *         c.js
 *         grandchild/
 *           great-grandchild/
 *             d.js
 *
 *     main.js
 */

// -Relative paths-
// a.js
import './b.js'; // ['/imports/b.js'] same folder as a.js

// c.js
import '../a.js'; // ['/imports/a.js'] a.js in parent folder (one level)

// d.js
import '../../../a.js'; // ['/imports/a.js'] a.js in parent folder (three levels)

// -Absolute paths-
// a.js
import '/imports/b.js'; // ['/imports/b.js'] uses root folder as starting point (MyApp/)

import 'meteor/meteor'; // loads meteor package named 'meteor'

import 'react'; // loads node package named 'react'

// main.js
import '/imports/child/grandchild/great-grandchild/d.js';
2 Likes