Create reusable library


#1

How I can make external lib so I could use it in other parts of meteor app? I tried creating .js file and importing it where needed but that doesnt work. Any ideas how I can achieve this?


#2

Can you show us how you’re declaring this and how you’re using it?


#3

As I said I just created .js file and then imported using ‘import ‘./file.js’;’. Variables in file.js is unreachable


#4

Before you can import a variable, you first need to export it.

// file.js
function foo() {
  // do stuff
}

export { foo }
// someOtherFile.js
import { foo } from './file';

foo()

More info on ES Modules

More info on Meteor’s implementation of ES Modules


#5

There are multiple places you can “just create a .js file”. Not all of them will behave as you want.