Trying to create a Meteor Package

2019-08-24 18:40发布

问题:

I've been trying to create a Smart Package for the SkelJS framework. The file is being loaded by the browser but when I try and access the object it exports it says its undefined. I'm using the following code in package.js:

Package.describe({
  summary: "SkelJS for Meteor"
});

Package.on_use(function (api) {
  api.use('jquery', 'client');
  api.add_files(['skel.js'], 'client');

  api.export('skel', 'client');
});

Also trying to access Package.skeljs.skel returns undefined as well.

In smart.json I'm using:

{
  "name": "skeljs",
  "description": "SkelJS for Meteor",
  "homepage": "",
  "author": "Giles Butler  (http://giles.io)",
  "version": "0.1.0",
  "git": ""
}

I know SkelJS has been loaded because it logs to the console no configuration detected, waiting for manual init but then when I try and run skel.init() it returns undefined.

Any help or tips would be really appreciated.

Thanks

Giles

回答1:

You also need to modify the first line of skel.min.js/skel.js

Within packages variable scoping still applies so you have to remove the var keyword if you want the file to let other files (such as package.js for api.export) access its variables.

The fix would be to change:

var skel=function() ....

to

skel=function() ....