How can I add third-party JavaScript libraries to a Meteor application?

后端 未结 4 1923
说谎
说谎 2020-12-01 00:40

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

4条回答
  •  生来不讨喜
    2020-12-01 01:10

    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.

提交回复
热议问题