0.1.0 • Published 13 years ago
grunt-bower-require-wrapper v0.1.0
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-devOr 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
0.1.0
13 years ago