0

In my Ember app I am trying to add the money.js external lib. I successfully achieved that by installing it with bower and then adding app.import('bower_components/money.js/money.js'); to my ember-cli-build.js.

money.js defines a global variable fx which is available all over my app. However I receive many JSHint Errors while building the app like:

components/purchase-form.js: line 41, col 29, 'fx' is not defined.

Ember docs states:

Typically, the application object is the only global variable. All other classes in your app should be properties on the Ember.Application instance, which highlights its first role: a global namespace.

I just wonder what is the proper way to import this kind of lib along with its global

masciugo
  • 1,113
  • 11
  • 19

2 Answers2

1

If you app.import a global you have to possibilities to make jsHint happy:

  1. Adding /* global fx */ before accessing the global per file.
  2. Adding it to predefs section in .jshintrc as @kumkanillam mentioned in his answer.

If you don't like to access dependency as a global you could shim it. Ember-cli provides a vendor-shim generator: ember generate vendor-shim money.js Afterward you could use import in your modules.

This topic is well-documented in ember-cli docs.

jelhan
  • 6,149
  • 1
  • 19
  • 35
0

To avoid jsHint error, you can mention fx global variable

{
  "predef": [
    "document",
    "window",
    "-Promise",
    "fx"
  ]
}
Ember Freak
  • 12,918
  • 4
  • 24
  • 54
  • good to know and I'll use it but my question need a more exhaustive answer. tnx – masciugo Dec 06 '16 at 09:07
  • 1
    @masciugo This answer is adequate. The only problem is a linting warning, because you're using a global (`fx`) that is not defined in the scope of the file. – locks Dec 07 '16 at 02:07
  • kumkanillam said something true and was helpful but I asked __what is the proper way to import this kind of lib along with its global__. I ended up using the shim. – masciugo Dec 12 '16 at 17:35