Handing dependencies for React components in meteor packages


#1

So, I’ve written a pretty extensive component library using as a result of working on several react + meteor applications and I’ve recently started implementing a new project with them using a package only approach. My problem is that I can’t seem to get the package dependencies to work as I would expect.

I imagined I would have a ‘core’ package that would ‘use’ all of the component libraries I wanted and just do a meteor add components:core instead of having to add each component package separately. I then wanted to create a package called ‘lib’ which would handle shared dependencies for each component (namely the new ‘react’ package) so I wouldn’t have to add dependencies for each component package. I figured this would be pretty straight forward, but I can’t seem to get any of the .jsx files to compile unless I ‘use’ the ‘react’ package in each component library.

Here is how I’ve set up my package.js files for each package using the Nav component as an example. I think I’m doing something wrong here because I don’t get the Nav component to render. When I add the ‘react’ dependency in the Nav package it does work though. Thoughts?

Core:

  Package.onUse(function(api) {
  api.versionsFrom('1.1.0.2');

  var packages = [
    'pushquotes:pushquotes-dependencies@0.0.1',
    'pushquotes:pushquotes-nav@0.0.1',
    'pushquotes:pushquotes-header@0.0.1'
  ];

  api.use(packages, 'client');
  api.imply(packages);

  api.addFiles('pushquotes-core.js');
});

Dependencies

Package.onUse(function(api) {
  api.versionsFrom('1.1.0.2');

  var packages = [
    'react',
    'percolate:velocityjs@1.2.1_1'
  ]

  api.use(packages, 'client');
  api.imply(packages);

  api.addFiles('pushquotes-dependencies.js');
});

Nav

Package.onUse(function(api) {
  api.versionsFrom('1.1.0.2');
    
  api.addFiles('pushquotes-nav.jsx', 'client');

  api.export(['NavList', 'SubNavList', 'NavItem', 'Navs'], 'client');
});