A Meteor package which co-ordinates the supply of Meteor dependencies to npm modules at runtime
This module is part of a suite:
This is a Meteor build plugin which provides your node modules with access to Meteor packages that they depend on. It works something like:
- Recursively scan all node modules
- If the package.json of a given node module has a "meteorDependencies" field, it will add these dependencies to a list of package names
- It will generate a Meteor package, which declares a dependency on all of the packages required by your node modules
- It will require the
@webantic/meteor-deps
module of each node module with a Meteor dependency and inject the dependencies to it
You can use things like Mongo
or FlowRouter
in your node modules.
First, either run meteor add webantic:loader
or clone this repo into your project's /packages
directory and add webantic:loader
to your package manifest in /.meteor/packages
Then, there are only three real hoops to jump through for this to work;
var wrapExports = require('@webantic/meteor-deps').wrapExports
var moduleExports = {
thing1: require('./thing1.js'),
thing2: require('./thing2.js')
}
module.exports = wrapExports(module, moduleExports)
import { inject } from '@webantic/meteor-deps'
import thing1 from './thing1.js'
import thing2 from './thing2.js'
export {
thing1,
thing2,
inject
}
var getDep = require('@webantic/meteor-deps').get
var Meteor = getDep('Meteor')
// In some cases, you may need to access the value asynchronously, like this:
getDep('Meteor').then(function (Meteor) {
// ...
})
{
"name": "my-cool-module",
"version": "1.0.0",
"dependencies": {
"@webantic/meteor-deps": "^1.1.9"
},
"meteorDependencies": {
"meteor": ["client", "server"],
"kadira:flow-router": "client"
}
}