Socket
Book a DemoInstallSign in
Socket

grunt-requiregrep

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

grunt-requiregrep

Grunt task that creates AMD modules by searching for dependencies on source files

latest
Source
npmnpm
Version
0.1.0
Version published
Weekly downloads
3
Maintainers
1
Weekly downloads
 
Created
Source

Grunt Require-Grep Task

Searchs for AMD modules required on your source code (eg. template files) and generates an AMD module from it.

Example:

<!-- a/path/to/page.html -->
<!-- require("jquery, widgets, twitter") -->

<!-- another/path/to/anotherpage.html -->
<!-- require("jquery, widgets, fx") -->

Running grunt-requiregrep can generate:

define(['jquery', 'widgets', 'twitter', 'fx'], function()){
	console.log('all modules loaded');
});

Now you can include this new module in your requirejs main config file. This way if you use a bundler like r.js (check grunt-contrib-requirejs) it will include all modules used on your source files automatically.

Installation

Install this grunt plugin with: npm install grunt-requiregrep

Then add this line to your grunt.js gruntfile:

grunt.loadNpmTasks('grunt-requiregrep');

Documentation

Supports the following options:

  • src/files: source files to grep for AMD dependencies (default: **/*.*html).
  • dest: output filename (eg all.js)
  • options:
    • requirePattern: regex to detect dependencies on source files, first capture group should be a comma-separated list of module names. default: /require\(\s*[\'\"]([^\'\"]*)[\'\"]/gi
    • moduleName: output module name. default: null, ie. anonymous module
    • onLoad: code to include on module load (eg. console.log('all modules loaded!');).
    • forEachFile: function that will be called for each parsed file with these arguments: file, contents, registerDependency (use this function add a dependency programmatically)

Example Usage

/*jslint node:true*/

module.exports = function (grunt) {

	'use strict';

	grunt.loadNpmTasks('grunt-requiregrep'); // load the task

	grunt.initConfig({
		watch: {
			files: '<config:requiregrep.files>',
			tasks: 'requiregrep'
		},

		requiregrep: { // configure the task
			all: {
				files: {
					'scripts/all.js': [
						'home.html',
						'view/**/*.html'
					]
				},
				options: {
					onLoad: 'if (window.console){window.console('all modules loaded');}', // run after all dependencies are loaded
				}
			}
		}
	});

	grunt.registerTask('default', 'watch');
};

Keywords

grunt

FAQs

Package last updated on 20 Mar 2013

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

About

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.

  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc

U.S. Patent No. 12,346,443 & 12,314,394. Other pending.