Note: I am a mostly self-taught javascript amateur that has almost all of my experience on the Meteor platform. What lies below is an in-progess quest to properly write a 1.3 package.
When writing a package I would like to follow the Meteor 1.3 best practices. My specific goal is to import the Prosemirror NPM package. But I will try to generalize into the case of importing a client-side NPM package for use on the client side within a package.
In the guide it says NPM dependencies can be added with Npm.depends
but it only mentions that for server dependencies.
The guide shows the use of a client-side NPM package in React but they use tmeasday:check-npm-versions in that package which implies the dependency was installed directly.
Relevant FAQs:
- Should I use api.exports() or ES6 export?
- As per the migration notes it is suggested to use export from the mainModule
- Is there any way to debug incorrect usage of ‘import’ and ‘export’ in a package?
- After you’ve added your NPM.depends in package.json and added an import of that package in your mainModule check the import worked with console.log
- Same within you demo app
- I see my package variable in the console but it is not defined?
- If you are using the ecmascript package your .js files will each be a module. Stuff imported into a module will not be global.
So how does one properly integrate a NPM client side package into a Meteor 1.3 package?
- If you are using the ecmascript package your .js files will each be a module. Stuff imported into a module will not be global.
In the package.js I have:
Npm.depends({ prosemirror: '0.5.1'});
In my packages mainModule js file:
import { ProseMirror } from "prosemirror/dist/edit"
then
export const Prosemirror = 'ProseMirror';
I add the local package to my demo project.
meteor add prosemeteor:prosemirror
In my demo project I use
import { Prosemirror } from 'meteor/prosemeteor:prosemirror'
Problem is that when I run the demo I don’t see ProseMirror as a global.
If looking at code would be helpful, here’s the mess I created after trying a number of different things to add Prosemirror properly: https://github.com/prosemeteor/prosemirror To get things going I just want to create a wrapper package for Prosemirror NPM - then I will extend it to be more deeply integrated.
Edit1: added answer to export vs api.exports questions
Edit2: Fixing bugs mentioned below with using name