GithubHelp home page GithubHelp logo

jwhitley / requirejs-plugin-bower Goto Github PK

View Code? Open in Web Editor NEW

This project forked from rodneyebanks/requirejs-plugin-bower

0.0 3.0 0.0 244 KB

Requirejs plugin for creating & loading Path/Shim configurations automatically from bower.json dependencies (InBrowser & InBuild).

License: Other

JavaScript 90.66% HTML 9.34%

requirejs-plugin-bower's Introduction

What if RequireJS could read bower.json files for module paths and dependencies?

This Bower plugin for RequireJS reads your root bower.json parsing your projects dependencies and their dependencies (TIAB). It then constructs a requirejs.config object ({"paths": {}, shim: {}}) with an auto load option.

This plugin works both InBrowser (dependencies reread each page load) & InBuild (config object saved to disk, so you can dump your bower.json files).

May also work on other AMD loaders (never tested it).

Install

You can use bower to install it easily:

bower install --save requirejs-plugin-bower

Plugins

  • bower : For creating requirejs.config({path:{},shim:{}}) settings automatically.

Documentation

check the examples folder. All the info you probably need will be inside comments or on the example code itself.

Basic usage

Put the plugins inside the baseUrl folder (usually same folder as the main.js file) or create an alias to the plugin location:

main.js

requirejs.config({
    baseUrl:'/js',
    paths : {
        //create alias to plugins (not needed if plugins are on the baseUrl)
        bower: '../bower_components/requirejs-plugin-bower/src/bower',
        json: '../bower_components/requirejs-plugins/src/json',
        text: '../bower_components/requirejs-text/text'
    },
    bower: {
        baseUrl: '../bower_components',
        extensions: 'js|css',
        ignore: 'requirejs|requirejs-domready|requirejs-text',
        auto: true
        deps: ['dependencies', 'devDependencies']
    }
});

// use plugin 
define(['bower!../bower.json'], function(bowerConfig) {

    //  requirejs.config(bowerConfig); // optional if bower: {auto: true}
    requirejs(['bootstrap']);

});

bootstrap.js

// use other modules using name without location path
define(['image'], function(image) {

    requirejs(['image!img/bower2requirejs.png'], function(requirejs2bower) {

        var wrapper = document.getElementById('wrapper');

        if (requirejs2bower) {
            wrapper.innerHTML = '<h2>Success</h2><br>';
            wrapper.appendChild(requirejs2bower);
        }

    });

});

Removing plugin code after build

r.js nowadays have the stubModules setting which can be used to remove the whole plugin code:

({
    // will remove whole source code of "json" and "text" plugins during build
    // JSON/text files that are bundled during build will still work fine but
    // you won't be able to load JSON/text files dynamically after build
    stubModules : ['json', 'text', 'requirejs-plugin-bower']
})

For more plugins check RequireJS Wiki.

Writing your own plugins

Check RequireJS documentation for a basic reference and use other plugins as reference. RequireJS official plugins are a good source for learning.

Also be sure to check RequireJS Wiki.

License

requirejs-plugin-bower is released under two licenses: new BSD, and MIT. You may pick the license that best suits your development needs.

Copyright (c) 2014 Rodney Robert Ebanks [email protected]

requirejs-plugin-bower's People

Contributors

rodneyebanks avatar swizec avatar

Watchers

John Whitley avatar James Cloos 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.