Reputation: 21
I'm working on an emberjs application that uses several other custom ember addons, one of which we're adding is a new dependency on mathjs (https://mathjs.org/) to do some expression parsing. It isn't clear though what is the correct way to keep the configuration of that dependency on mathjs with only the addon that uses it. Is there a "right" way to do this in ember?
What we ended up doing was just installing the mathjs package into our main app's node_modules, then exposing the library in the browser by doing an app.import('node_modules/mathjs/dist/math.min.js')
in our ember-cli-build.js file. This is obviously non-ideal because it means that any app using the custom addon must also do this extra setup to expose this dependency of the addon.
FWIW, we initially tried to just install the mathjs dependency into the addon's node_modules, then we imported it in the component of the addon where it's used. But then the browser said that the mathjs module couldn't be imported from the addon.
Upvotes: 2
Views: 175
Reputation: 18240
You should let ember-auto-import
manage this for you. For this:
math.js
to your dependencies
of your addon (not devDependencies
).import
syntax to import it in your addon.For the import
syntax you need to be aware that some modules only have a default export which is a object exporting properties while others have individual exports. So its either
import { pi, atan2 } from 'mathjs'
or import mathjs from 'mathjs'
.
your host app should then have your addon in devDependencies
.
Only use app.import
syntax if you use something that does not support modules at all.
Upvotes: 2