在Meteor软件包中使用npm
我在想办法把npm软件包装进流星软件包。具体来说,我尝试了在Meteor软件包中使用npm,meteor,npm,Meteor,Npm,我在想办法把npm软件包装进流星软件包。具体来说,我尝试了future npm 我尝试过这样做: Package.describe({ summary: "Blah blah", version: '0.0.1' }); Npm.depends({future: "2.3.1"}); Package.onUse(function (api) { api.addFiles('lubert.js', 'server'); api.export('Lubert'); }); 不幸
future npm
我尝试过这样做:
Package.describe({
summary: "Blah blah",
version: '0.0.1'
});
Npm.depends({future: "2.3.1"});
Package.onUse(function (api) {
api.addFiles('lubert.js', 'server');
api.export('Lubert');
});
不幸的是,我得到了以下控制台错误
Uncaught ReferenceError: Npm is not defined
我已经阅读了,没有关于加载任何依赖项的内容
我做错了什么
更新2:My package.js看起来像
Package.describe({
name: 'trepafi:package',
summary: '',
version: '0.0.3',
git: 'https://github.com/trepafi/meteor-package.git'
});
Npm.depends({
"future": "2.3.1"
});
Package.onUse(function(api) {
api.versionsFrom('1.0');
api.use(['tracker', 'underscore'], ['client']);
api.addFiles(['package.js'], ['client']);
api.export('Package', ['client']);
});
{
"name": "trepafi-package",
"version": "0.0.3",
"description": "Package for Meteor",
"repository": {
"type": "git",
"url": "https://github.com/trepafi/meteor-package.git"
},
"author": "Lubert Palacios",
"license": "MIT",
"homepage": "https://github.com/trepafi/meteor-package",
"dependencies": {
"future": "^2.3.1"
}
}
更新1:My package.json看起来像
Package.describe({
name: 'trepafi:package',
summary: '',
version: '0.0.3',
git: 'https://github.com/trepafi/meteor-package.git'
});
Npm.depends({
"future": "2.3.1"
});
Package.onUse(function(api) {
api.versionsFrom('1.0');
api.use(['tracker', 'underscore'], ['client']);
api.addFiles(['package.js'], ['client']);
api.export('Package', ['client']);
});
{
"name": "trepafi-package",
"version": "0.0.3",
"description": "Package for Meteor",
"repository": {
"type": "git",
"url": "https://github.com/trepafi/meteor-package.git"
},
"author": "Lubert Palacios",
"license": "MIT",
"homepage": "https://github.com/trepafi/meteor-package",
"dependencies": {
"future": "^2.3.1"
}
}
我也尝试过流星黑客:npm没有成功。
如果我可以使用“本地”方式,那就太好了。您应该在
package.js
文件的末尾对所有Npm.require
s进行分组
对于未来的npm
。你不需要package.js
中的Npm.dependens
,傻瓜。它已经包含在流星中了。。只要Npm.require
某个地方,你就可以去了。为此:
package.js
名称模棱两可。改用trepafi:package.js
package.json
<代码>Npm.视情况而定已涵盖您api.addFiles(['package.js'],['client'])代码>因为它看起来像一个循环依赖项。。我在你的package.js中为你添加了liek package.js。。不酷,Xzibit
trepafi:package.js
作为服务器端。e、 g:
api.addFiles(['trepafi:package.js'],['server'])代码>
trepafi:package.js
应该如下所示:
Package.describe({
name: 'trepafi:package',
summary: '',
version: '0.0.3',
git: 'https://github.com/trepafi/meteor-package.git'
});
Package.onUse(function(api) {
api.versionsFrom('METEOR@1.0');
api.use(['tracker', 'underscore','meteor'], ['client']);
api.addFiles(['trepafi:package.js'], ['server']);
api.export('Package', ['client']);
});
//if you really need Npm.depends:
Npm.depends({
'prerender-node': '1.0.6',
'send' : '0.10.1'
});
// we don't need no package.json
var Future = Npm.require('future');
var future = new Future();
// use your future to make Doc Brown proud.
var useFuture = function(asyncFunc) { //expects function with callback somewhere
asyncFunc(function(err, result) {
if(err) future.throw("OMG something went wrong!");
else return future.return(result);
});
return future.wait();
};
Meteor.startup(function() {
//something
});
阅读:
package.js
中的显著变化是versionfrom
和api。use
现在添加了meteor
祝你好运 你的包文件结构是什么?我觉得你的语法不错。这应该是正确的trick@saimeunt刚刚加上it@Sindis我已经试过了,但没有成功。您不需要提供package.json,只需要提供一个package.js,它位于自己的包目录中。谢谢。我想知道为什么我的浏览器日志中出现了“Npm丢失”,指的是./myPackage/server中的一个文件。使用Meteor.isServer修复了它,但实际上不需要服务器目录中的文件。所以显然,api.addfiles()中的“client”和“server”声明具有优先权,因此在包中不需要这样的目录名。