Distributing an AngularJS module which uses external Javascript/jQuery libraries

549 views Asked by At

I am developing a reusable component (module) for AngularJS which can be used to enable offline features of applications built with AngularJS.

To achieve client side storage features without re-inventing the wheel, I decided to use this good library provided by Google called Lovefield, which works as,

A cross-browser, SQL-like, relational query engine for Web in pure JavaScript.

I know how to wrap this library with angularjs by creating custom directives, services etc. inside my module. But my question is,

When distributing my module, do I need to include the Javascript code for lovefiled inside my own module code Or Should I ask the developer to include it by himself using <script> tags inside his html? What is the recommended way to do this? (It is apparent that both methods can be used)

I went through some of the 3rd party angular modules here, but cannot figure out what is the recommended way of doing this.

2

There are 2 answers

0
Ran Sasportas On

you should ask the developer to add the <script> tag you should have a package.json file which indicates what depenedencies you have like that -

{
  "name": "angular-lovefield",
  "version": "1.0.0",  
  "main": "index.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "author": "youre-name",
  "license": "ISC",
  "dependencies": {
    "lovefield": 1.0.0.1 
  }

}

you can create this file using the npm init command

good luck.

2
kutomer On

I know that this is not exactly what you've meant, but.. I've already done the same thing "wrap this library with angularjs by creating custom directives, services etc."

I used bower to distribute the module (called ng-lovefield) and added lovefield as a dependency in the bower.json file, I suggest that if you wish to create a new module you do the same (no matter what kind of package manager you choose - npm \ bower)

Including the actual <script> in the html is the task runner responsibility such as grunt or gulp, you can use grunt-wiredep to inject all your bower dependencies automaticly to your html. If you do not wish to use task runner for some reason I guess that you have to do it manually.