party JavaScript libraries to a Meteor application?

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

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

Your app is crashing. Here's the latest log.

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.


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.

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

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:

meteor add jquery

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

See also how to repackage an existing library for Meteor .


把它放在client文件夹中,以便它只在客户端加载,不需要服务器上的jQuery。


One way to do this in MeterorJS 1.3.x

Add the JS files in the publicjs directory

在这里输入图像描述

Load it up from Meteor.startup method using $.getScript in client/main.js If you want to control script load sequence, control with multiple $.getScript for each js files.

在这里输入图像描述

Meteor.startup(function(){
    $.getScript('js/fhir-client.js', function(){
        // script should be loaded and do something with it. 

    });
});
链接地址: http://www.djcxy.com/p/73408.html

上一篇: 关闭特定线条的eslint规则

下一篇: 派对JavaScript库到Meteor应用程序?