简体   繁体   English

如何将第三方软件包导入Meteor?

[英]How do I import a third-party package into Meteor?

I'm trying to repackage Gibberish.js for Meteor, and so far nothing is working. 我正在尝试将Gibberish.js重新打包为Meteor,到目前为止没有任何效果。 The package has its own npm dependencies. 该软件包具有其自己的npm依赖性。 I first tried to load it as a git submodule. 我首先尝试将其作为git子模块加载。 I had this in my package.js: 我在package.js中有这个:

Npm.depends({
    "connect": "2.25.7",
    "serve-static": "1.5.3",
    "uglify-js": "2.4.15"
});

Package.onUse(function(api) {
  api.versionsFrom('1.1.0.2');
  api.addFiles('build/gibberish.js', ['client','server']);
});

It complained that Gibberish.init() wasn't a function, so I'm guessing it didn't see the package. 它抱怨Gibberish.init()不是一个函数,所以我猜测它没有看到该包。 So then I realized gibberish-dsp is its own npm package, so I tried to include it via npm. 因此,我意识到gibberish-dsp是它自己的npm软件包,因此我尝试通过npm包含它。 I used this: 我用这个:

package.js package.js

Npm.depends({
    "connect": "2.25.7",
    "serve-static": "1.5.3",
    "uglify-js": "2.4.15",
    "gibberish-dsp": "2.3.2"
});

Package.onUse(function (api) {

  api.addFiles([
    'lib/gibberish.js',
  ], ['server']);

  api.export([
    'gibberish'
  ]);

lib/gibberish.js: LIB / gibberish.js:

juice = Npm.require('gibberish-dsp');

That gave it a callback error. 这给了它一个回调错误。 I guess Meteor can't do callbacks with third party packages?! 我猜Meteor无法使用第三方程序包进行回调?! So I tried meteorhacks:npm , which apparently fixes the callback error. 所以我尝试了meteorhacks:npm ,显然可以解决回调错误。 And I tried this: 我尝试了这个:

  if (Meteor.isServer) {

    console.log('server');
      var gibberish = new Gibberish();
      var init = Async.wrap(init);
      gibberish.init();

     }

});

And with my gibberish submodule in my /packages/ folder, I get a SyntaxError: Unexpected token Y . 在我的/ packages /文件夹中出现乱码子模块时,出现SyntaxError: Unexpected token Y

UPDATE: The SyntaxError is referring to "Bad HTML" in the gibberish package. 更新:SyntaxError引用乱码包中的“ Bad HTML”。 Apparently it's trying to read it as a Meteor HTML file (ie without DOCTYPE etc.) I don't want to change every single file in the package! 显然,它试图将其读取为Meteor HTML文件(即没有DOCTYPE等)。我不想更改软件包中的每个文件!

I've probably spent about 20 hours on this already. 我可能已经花了大约20个小时。 Why is it so hard to load an external library?!?! 为什么加载外部库如此困难?!?! What else can I do? 我还可以做些什么? I want to like Meteor but I'm ready to give up. 我想喜欢流星,但我准备放弃。

Have you added it to your Meteor build's active package list? 您是否已将其添加到Meteor构建的活动包列表中? The package won't be used unless it's listed there. 除非列出该软件包,否则不会使用该软件包。

$ meteor add user:gibberish

I don't want to change every single file in the package! 我不想更改软件包中的每个文件!

Why not? 为什么不?

  1. Fork the existing Node package. 分叉现有的Node软件包。
  2. Use a regex replace in all its HTML files to make them fit Meteor. 其所有HTML文件中使用正则表达式 替换使其适合Meteor。
  3. Only update the compatible parts to keep up with the Node package. 仅更新兼容部件以跟上Node软件包的发展。

Update: It appears you've accepted this answer : 更新:看来您已经接受了以下答案

The simplest (non-packaged) way to get this working is using client/compatibility . 实现此工作的最简单(非打包)方法是使用client/compatibility

  1. Remove any homebrew packages you are using to try to make this work (or start afresh with a new project). 删除您用来尝试进行此工作的所有自制程序包(或从一个新项目重新开始)。
  2. Build gibberish.js in the recommended way. 以推荐的方式构建gibberish.js
  3. Copy gibberish.js into client/compatibility . gibberish.js复制到client/compatibility

You now have access to the Gibberish object in your client code. 现在,您可以在客户端代码中访问Gibberish对象。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM