Share your code. npm Orgs help your team discover, share, and reuse code. Create a free org »

    grunt-bower-require-wrapperpublic

    grunt-bower-require-wrapper

    Wraps files with requireJS define() statements for modules definition using bower installed dependencies or user specified ones.

    Getting Started

    This is a grunt task. Please refer to the Grunt documentation for more information on how to use this task.

    To install this particular plugin use:

    npm install grunt-bower-require-wrapper --save-dev

    Or register it as a dependency on your package.json and run npm install

    Basic dependency requirement header wrapping

    The following example read the content of originPath.js and wraps it in a typical requireJs header specifying each dependency.

    grunt.initConfig({
        bowerRequireWrapper: {
            target: {
              files : {
                  'destPath.js' : ['originPath.js']
              }
              modules: {
                  'jQuery' : '$',
                  'underscore' : '_'
              },
              exports: '$'
          } }
    });
     
    grunt.registerTask('default', ['bowerRequireWrapper']);

    The destPath.js file then contains:

    define(["jQuery", "underscore"], function ($, _){
     
    /* Original code from originPath.js */
     
    return $;
    });

    Example usage with bower

    grunt.initConfig({
        bowerRequireWrapper: {
            target: {
              files : {
                  'destPath.js' : ['originPath.js']
              }
              modules: {
                  'jQuery' : '$',
                  'underscore' : '_',
                  'angular' : 'angular'
              },
              exports: 'angular'
              bower: true,
              banner: '/* File generated */'
          } }
    });
     
    grunt.registerTask('default', ['bowerRequireWrapper']);

    This example loads all the bower installed dependencies names, then merges it with the modules array to specify the variable name exported for each dependency.

    The destPath.js file content:

    /* File generated */
    define(["jQuery", "underscore", "angular"], function ($, _, angular){
     
    /* Original code from originPath.js */
     
    return angular;
    });

    License

    MIT license

    Keywords

    none

    install

    npm i grunt-bower-require-wrapper

    Downloadsweekly downloads

    3

    version

    0.1.0

    license

    none

    repository

    github.com

    last publish

    collaborators

    • avatar