Offering React templates in a package

Hi all,

I maintain a Meteor package for which I’d like to add support for React alongside the Blaze templates that are already included.

To do this I need to create a dependency on the React package so that the .jsx file is compiled. However, I really don’t want to force the user to include the React package if they’re not actually using React in their project,

I don’t want to create another version of the package done most of it’s the same, although I support it’s a possibility.

This is an issue that many packages are going to start having if they wish to provide React/Angular support. Can anyone suggest how this can best be handled?

1 Like

Look to Meteor packages API.

api.use(packageNames, [architecture], [options])
Options

weak Boolean

Establish a weak dependency on a package. If package A has a weak dependency on package B, it means that including A in an app does not force B to be included too 

You can add react package as weak dependency, that mean you don’t force your users to install react package. Just be sure your package works correctly in case if react doesn’t installed.

Is that what you need?

There is a simple answer to this question: add a dependency on the jsx package.

See the section of the guide here: http://react-in-meteor.readthedocs.org/en/latest/#whats-in-the-box

The react meta-package comes with everything you need to build your Meteor app with React. You can also add any of the parts individually:

  1. react-runtime: The React library itself
  2. jsx: A compiler that automatically transforms .jsx files into JavaScript, and lets you use some ES6 features
  3. react-meteor-data: A React mixin called ReactMeteorData that lets you easily use data from Meteor collections and other reactive sources in your components
1 Like

Unfortunately not.

As soon as I turn the dependency on react into a weak one my .jsx files are no longer compiled.

Ah, that works :slight_smile:

api.use('jsx');
api.use('react', { weak: true });

Thanks.

2 Likes