0

I need to include a library that is present on github, but is not well-packaged; using Duo.js

At the moment of writing I am using the following to achieve what I desire:

bower
gulp
main-bower-files

Bower just downloades the library.
Gulp, with main-bower-files are useful to override the single package options and setup a so-called "main file" that I can build.

Example:

gulp.task('copy-libs', function () {
  return gulp.src(bowerFiles({ env: 'development' }))
    .pipe(gulp.dest('build/libs/'));
});

bower.json file:

  "dependencies": {
    "cash": "sudo-js/cash",
    "bootstrap": "~3.3.2",
    "delorean": "~0.8.7",
    "react": "~0.12.2"
  },
  "overrides": {
    "cash": {
      "main": {
        "development": "build/debug/cash.js"
      }
    }
  }
}

How can i achieve this with duojs?
The documentation is quite thin regarding libraries that does not ship with a valid component.json

Valerio
  • 2,390
  • 3
  • 24
  • 34

1 Answers1

1

You can specify the path to an entry file for your lib. It won't be as clean as just specifying user/repo, but it'll get the job done.

For example, when including Twitter Bootstrap from twbs/bootstrap

require('twbs/bootstrap@v3.3.2:dist/js/bootstrap.js');
// repo:        twbs/bootstrap
// version/tag: v3.3.2
// path:        dist/js/bootstrap.js

Unfortunately, this doesn't work out-of-the-box since it assumes you have the jQuery global... so you need to add this above the previous line.

jQuery = require('components/jquery'); // leave out `var` so it becomes a global

This includes jQuery from the wonderful components project. (they package up popular libs so they can be consumed by various package managers.

Also, it turns out there is a components/bootstrap that is properly packaged with a component.json.

So, you can actually make bootstrap work with the following:

jQuery = require('components/jquery');
require('components/bootstrap');

For the other libraries that aren't as common, you can use the process mentioned first to specify the path to the right JS/CSS file. (ie: user/repo@version:path)

Dominic Barnes
  • 28,083
  • 8
  • 65
  • 90