本文介绍了如何将第三方 JavaScript 库添加到 Meteor 应用程序?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

限时删除!!

我想向 Meteor 应用添加一个 JavaScript 前端插件,例如 jquery.center.js.

I want to add a JavaScript front-end plugin, like jquery.center.js, to a Meteor app.

如果我将它放在我的 app/ 目录中并刷新页面,我会收到此错误:

If I put it in my app/ directory and refresh the page I get this error:

您的应用程序崩溃了.这是最新的日志.

node.js:201
扔e;//process.nextTick 错误,或第一个滴答时的错误"事件
^
参考错误:未定义 jQuery
在 app/jquery.center.js:43:1
在/Users/crapthings/Desktop/app/.meteor/local/build/server/server.js:111:21
在 Array.forEach(本机)
在功能.(/Users/crapthings/Desktop/app/.meteor/local/build/server/underscore.js:76:11)
在/Users/crapthings/Desktop/app/.meteor/local/build/server/server.js:97:7
退出代码:1
您的应用程序正在崩溃.等待文件更改.

node.js:201
throw e; // process.nextTick error, or 'error' event on first tick
^
ReferenceError: jQuery is not defined
at app/jquery.center.js:43:1
at /Users/crapthings/Desktop/app/.meteor/local/build/server/server.js:111:21
at Array.forEach (native)
at Function. (/Users/crapthings/Desktop/app/.meteor/local/build/server/underscore.js:76:11)
at /Users/crapthings/Desktop/app/.meteor/local/build/server/server.js:97:7
Exited with code: 1
Your application is crashing. Waiting for file change.

推荐答案

您将 jquery 插件 javascript 文件直接放在 app 文件夹中,以便为客户端和服务器加载 javascript 文件.

You are putting jquery plugin javascript file in app folder directly,so that javascript file will be be loaded for client as well as server.

根据 Meteor 文档:
客户端从以下位置加载 javascript:project/public 和 project/client
服务器从以下位置加载 javascript:project/public 和 project/server 文件夹.

As per Meteor documentation:
Client loads javascript from: project/public and project/client
Server loads javascript from: project/public and project/server folders.

从 v1.0 开始,Meteor 在客户端内部使用 jQuery,因此您可以直接使用您的库,而无需添加 jQuery.但是,建议您将 jQuery 显式添加到 Meteor 项目中:

As of v1.0, Meteor is using jQuery internally in the client, so you can use your library directly without adding jQuery. However, it's recommended that you add jQuery to your Meteor project explicitly:

流星添加jquery

Meteor 文档深入解释了JavaScript 文件是如何加载的以及静态资源应该放在何处(CSS,图像).

The Meteor docs explain in depth how JavaScript files are loaded and where static assets should go (CSS, images).

另请参阅如何为 Meteor 重新打包现有库.

See also how to repackage an existing library for Meteor.

这篇关于如何将第三方 JavaScript 库添加到 Meteor 应用程序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

1403页,肝出来的..

09-06 14:34