-2

I want to add scrollto plugin to my Meteor project

I created package.js like in this tutorial: enter link description here

http://codeshare.io/SeCCt

I don't know what I'm doing wrong.

Tomasz Lenarcik
  • 4,762
  • 17
  • 30
  • BTW, This question has been already asked several times, e.g. http://stackoverflow.com/questions/11009971/how-can-i-add-third-party-javascript-libraries-to-a-meteor-application – Tomasz Lenarcik Aug 19 '15 at 20:24

1 Answers1

0

You don't have to create package for that. It's enough if you put the plugin file inside /client/lib/ directory. Please not that in order for your plugin to work, the jquery built-in package must be added to your application, but it should be already there by default.

However, if you really want to create a package for that (sometimes it's useful) you will need to put the plugin source code (e.g. jquery.scrollTo.js) along with the package.js file in a separated subdirectory inside packages/ in your project root. Directory structure should look like this:

.meteor/
client/
packages/
  jquery-scrollto/
    package.js
    jquery.scrollTo.js

and the source of package.js:

Package.describe({
  summary: "A jquery.scrollTo plugin",
  version: "1.2.3", // best to use the version of plugin
  name: "jquery-scrollto",
});

Package.onUse(function (api) {
  api.versionsFrom("METEOR@1.0");
  api.use('jquery', 'client');
  api.addFiles('jquery.scrollTo.js', 'client');
});

Finally add your package name - so jquery-scrollto - to the list in .meteor/packages file.

Tomasz Lenarcik
  • 4,762
  • 17
  • 30
  • Thanks for answer, corect me if i am wrong. Command meteor publish --create should be add package to .meteor/packages but i get this message The package you are in appears to be inside a Meteor app but is not in its packages directory. You may only publish packages that are entirely outside of a project or that are loaded by the project that they are inside. – Łukasz Dramiski Ren Aug 19 '15 at 19:06
  • Nope. What you want is probably "meteor add my-package-name". – Tomasz Lenarcik Aug 19 '15 at 19:08
  • If you only want to use this package in your project there's now need to publish it. It's enough if it stays in the "packages" subdirectory. Publishing would put your package on the "atmosphere" and make it available to everyone. – Tomasz Lenarcik Aug 19 '15 at 19:10
  • Ok, so this is my directory structure http://codeshare.io/0STeb And packages in .meteor looks this http://codeshare.io/xeSRq But i getting error "While selecting package versions: error: unknown package in top-level dependencies: jquery-scrollto" – Łukasz Dramiski Ren Aug 19 '15 at 19:16
  • In "packages" you need to create another directory e.g. "jquery-scrollto" (but the name of the directory does not matter) and put your "package.js" inside that directory. – Tomasz Lenarcik Aug 19 '15 at 19:23
  • Oh now i see, but i have one more problem. I get error While selecting package versions: error: unknown package: jquery:jquery Required by: jquery-scrollto 2.1.1 And i don't know what i am setting wrong. In bower.json was "jquery": ">=1.8" so i set api.use('jquery:jquery@1.11.3', where); – Łukasz Dramiski Ren Aug 19 '15 at 19:32
  • I think it's just "jquery" and not "jquery:jquery". It's a built-in package. – Tomasz Lenarcik Aug 19 '15 at 19:37
  • I change like you said and now i get While building package jquery-scrollto: error: File not found: src/jquery.scrollTo.js It is very confused for me. I add new subdirectory src and put my js file jquery.scrollTo.js but nothing happend. They should not automatically download this file? – Łukasz Dramiski Ren Aug 19 '15 at 19:44
  • No, they don't do it. Meteor depends on you to provide all necessary source code. – Tomasz Lenarcik Aug 19 '15 at 19:52
  • So, wher should i put my js file? Now i have /src/jquery.scrollTo.js maybe i will move to .metor? I don't know... – Łukasz Dramiski Ren Aug 19 '15 at 19:56
  • I change name of file from jquery.scrollTo.js on just scrollTo.js but stil doesn't not found – Łukasz Dramiski Ren Aug 19 '15 at 20:08
  • I updated the answer and I described a more simple solution as well. You should figure it out on your own from this point. – Tomasz Lenarcik Aug 19 '15 at 20:14
  • Wow Amazing now is working :) I tryied both solution and both working thanks very much for help – Łukasz Dramiski Ren Aug 19 '15 at 20:27