Coder Social home page Coder Social logo

smh / debowerify Goto Github PK

View Code? Open in Web Editor NEW

This project forked from eugeneware/debowerify

0.0 3.0 0.0 65 KB

A browserify transform to enable the easy use of bower components in browserify client javascript projects. This can be used in conjunction with deamdify to require AMD components from bower as well.

JavaScript 100.00%

debowerify's Introduction

debowerify

A browserify transform to enable the easy use of bower components in browserify client javascript projects.

This can be used in conjunction with deamdify to require AMD components from bower as well.

Installation

Installation is via npm:

$ npm install debowerify

How to use.

Install some bower components:

# creates files in components/screenfull/
$ bower install screenfull

Require the bower file by it's bower identifier (ie. in this case "screenfull"):

// public/scripts/app.js
var _screenfull = require('screenfull'); // the bower component
var domready = require('domready'); // a regular browserify npm component

domready(function () {
  var button = document.getElementById('fullscreen');
  button.addEventListener('click', function (evt) {
    // screenfull adds itself to window.screenfull - but we can get to it
    if (screenfull.enabled) {
      screenfull.toggle(this);
    }
  });
});

Build out your browserify bundle using the debowerify transform:

$ browserify -t debowerify  public/scripts/app.js -o public/scripts/build/bundle.js

Then include your bundle.js in your HTML file and you're done!

How to use with AMD components

If your bower components are amd and they don't support commonjs modules than simply use debowerify with the excellent deamdify browserify transform. For example, the following AMD bower import:

# creates files in components/myamdcomponent/
$ bower install myamdcomponent
// public/scripts/amdapp.js
var myamdcomponent = require('myamdcomponent'); // the AMD bower component
var domready = require('domready'); // a regular browserify npm component

domready(function () {
  // call the amd component
  myamdcomponent.doStuff();
});

To make this all magically work and use the short-form bower name of "amdcomponent" chain both debowerify and deamdify together like this:

$ browserify -t debowerify -t deamdify public/scripts/amdapp.js -o public/scripts/build/bundle.js

Too easy!

Notes

The transform depends on the "main" entry in bower.json to be correct.

Some bower components may not have this set, or have it set incorrectly. In this case, either manually update the bower.json file yourself, of just do a require to the relevant full path of the bower javascript file - and then complain to the bower component repo owner! :-)

debowerify's People

Contributors

00dani avatar eugeneware avatar maxnordlund avatar

Watchers

 avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.