• This repository has been archived on 26/Mar/2018
  • Stars
    star
    198
  • Rank 196,898 (Top 4 %)
  • Language
    JavaScript
  • Created almost 11 years ago
  • Updated almost 8 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

[DEPRECATED] Grunt task - Automagically wire-up installed Bower components into your RequireJS config

grunt-bower-requirejs Build Status

Automagically wire-up installed Bower components into your RequireJS config

Grunt wrapper for the bower-requirejs module.

Getting Started

If you haven't used grunt before, be sure to check out the Getting Started guide, as it explains how to create a Gruntfile as well as install and use grunt plugins. Once you're familiar with that process, install this plugin with this command:

npm install grunt-bower-requirejs --save-dev

Once the plugin has been installed, it may be enabled inside your Gruntfile with this line of JavaScript:

grunt.loadNpmTasks('grunt-bower-requirejs');

Example usage

grunt.initConfig({
  bowerRequirejs: {
    target: {
      rjsConfig: 'app/config.js'
    }
  }
});

grunt.loadNpmTasks('grunt-bower-requirejs');

grunt.registerTask('default', ['bowerRequirejs']);

Documentation

When the bowerRequirejs task is run it merges the paths of installed Bower components into the paths property of your RequireJS config.

You trigger this task from another task in your Gruntfile or through the CLI: grunt bowerRequirejs

rjsConfig

Required
Type: String

Specify a relative path to your RequireJS config.

Make sure to specify the baseUrl property in your RequireJS config if you want to use relative paths.

Options

exclude

Default: []
Type: Array

Specify components to be excluded from being added to the RequireJS config.

bowerRequirejs: {
  all: {
    rjsConfig: '<%= yeoman.app %>/scripts/main.js',
    options: {
      exclude: ['modernizr', 'sass-bootstrap', 'qtip2']
    }
  }
}

baseUrl

Default: null
Type: String

Generate paths relative to a specific directory. This option is for anyone not using data-main who wishes to set their own base.

bowerRequirejs: {
  all: {
    rjsConfig: '<%= yeoman.app %>/path/to/main.js',
    options: {
      baseUrl: './'
    }
  }
}

transitive

Default: false
Type: Boolean

If the transitive option is set to true, then transitive dependencies will be also added to the require config.

For example, say we explicitly have an entry in our bower config for module myTotallyCoolModule, which depends on jQuery and underscore. If the transitive option is set to true, there will be config entries for myTotallyCoolModule, jQuery, and underscore. Otherwise, if the transitive option is set to false, there will only be a config entry for myTotallyCoolModule.

Each transitive dependency is only included once, even if the dependency is used multiple times.

bowerRequirejs: {
  all: {
    rjsConfig: '<%= yeoman.app %>/scripts/main.js',
    options: {
      transitive: true
    }
  }
}

excludeDev

Default: false Type: Boolean

If the excludeDev option is set to true, then dev-pendencies won't be added to the require config.

bowerRequirejs: {
  all: {
    rjsConfig: '<%= yeoman.app %>/scripts/main.js',
    options: {
      excludeDev: true
    }
  }
}

Using Bower Hooks

Bower >=v1.3.1 includes hooks for preinstall, postinstall and preuninstall actions. To run grunt-bower-requirejs after every bower install, add a scripts block to your .bowerrc.

{
  "scripts": {
    "postinstall": "grunt bowerRequirejs"
  }
}

Things to remember

Config file

If you do not already have a config.js file at the location specified by the --config option then one will be generated for you. A basic config.js file looks like this:

requirejs.config({
  shim: {},
  paths: {}
});

You still need to create a path for your js files. This tool will only create paths for third party libraries specified in bower.json.

requirejs.config({
  shim: {},
  paths: {
    myComponent: 'js/myComponent.js'  // make sure to add your components!
  }
});

The tool does not overwrite the config file, it just adds additional paths to it. So paths you add will be preserved. Keep in mind that if you change or remove one of your Bower dependencies after you've run the task, that path will still exist in the config file and you'll need to manually remove it.

RequireJS component

Although RequireJS does not provide a bower.json file, a path to require.js will still be created in your rjsConfig file. The path's name will be requirejs. If you are optimizing your scripts with r.js you can use this path to make sure RequireJS is included in your bundle.

Package Support

If a dependency's moduleType is set to node in bower.json it will be treated as a CommonJS Package.

The following bower.json file:

{
  "name": "node-module-type-stub",
  "version": "0.0.1",
  "moduleType": ["node"],
  "main": "myMain.js"
}

Will generate this entry in your config.js file:

require.config({
  shim: {},
  packages: [
    {
      name: 'node-module-type-stub',
      main: 'myMain.js',
      location: 'bower_components/node-module-type-stub'
    }
  ],
  paths: {}
});

Configuring location

By default, the task will set the package location to the root directory of the dependency. If the dependency includes a location property in its bower.json, then the location will be a combination of the root directory and the location dir.

For example, a bower.json like this:

{
  "name": "node-module-type-stub",
  "version": "0.0.1",
  "moduleType": ["node"],
  "main": "myMain.js",
  "location": "src"
}

Will generate this entry in your config.js file:

require.config({
  shim: {},
  packages: [
    {
      name: 'node-module-type-stub',
      main: 'myMain.js',
      location: 'bower_components/node-module-type-stub/src'
    }
  ],
  paths: {}
});

License

BSD license and copyright Google

More Repositories

1

yeoman

Yeoman - a set of tools for automating development workflow
10,081
star
2

generator-angular

Yeoman generator for AngularJS
JavaScript
5,729
star
3

yo

CLI tool for running Yeoman generators
JavaScript
3,835
star
4

generator-webapp

A gulp.js generator for modern webapps
JavaScript
3,770
star
5

generator-chrome-extension

Scaffold out a Chrome extension
JavaScript
2,617
star
6

update-notifier

Update notifications for your CLI app
JavaScript
1,762
star
7

generator-generator

Generate a Yeoman generator
JavaScript
1,223
star
8

grunt-usemin

[UNMAINTAINED] Replaces references to non-optimized scripts or stylesheets into a set of HTML files (or any templates/views)
JavaScript
1,219
star
9

generator

Rails-inspired generator system that provides scaffolding for your apps
TypeScript
1,204
star
10

yeoman-app

A desktop app that scaffolds projects using Yeoman
JavaScript
988
star
11

generator-webapp_DEPRECATED

Yeoman generator that scaffolds out a front-end web app
JavaScript
974
star
12

generator-polymer

Scaffold out a Polymer project
JavaScript
926
star
13

generator-mobile

Scaffold out a mobile project based on Web Starter Kit
JavaScript
918
star
14

configstore

Easily load and persist config without having to think about where and how
JavaScript
866
star
15

yeoman.io

Yeoman website
CSS
790
star
16

generator-backbone

Scaffold out a Backbone.js project
JavaScript
638
star
17

generator-node

Create a Node.js module
JavaScript
577
star
18

insight

Node.js module to help you understand how your tool is being used by anonymously reporting usage metrics to Google Analytics
JavaScript
557
star
19

bower-requirejs

[DEPRECATED] Automagically wire-up installed Bower components into your RequireJS config
JavaScript
375
star
20

generator-chromeapp

Scaffold out a Chrome app
JavaScript
310
star
21

stringify-object

Stringify an object/array like JSON.stringify just without all the double-quotes
JavaScript
307
star
22

grunt-filerev

[DEPRECATED] File revving
JavaScript
260
star
23

yosay

Tell Yeoman what to say
JavaScript
206
star
24

generator-bootstrap

Yeoman generator for Bootstrap
JavaScript
186
star
25

generator-karma

Yeoman generator for Karma
JavaScript
172
star
26

environment

Yeoman runtime environment
JavaScript
127
star
27

generator-jquery

Generate a jQuery plugin
JavaScript
85
star
28

generator-gruntfile

Create a basic Gruntfile with yo.
JavaScript
74
star
29

doctor

Detect potential issues with users system that could prevent Yeoman from working correctly
JavaScript
61
star
30

yeoman-assert

Assert utility from yeoman
JavaScript
53
star
31

yeoman-generator-list

JavaScript
52
star
32

yeoman-test

Test utilities for Yeoman generators
TypeScript
44
star
33

generator-mocha

Yeoman generator for Mocha
JavaScript
41
star
34

generator-gruntplugin

Create a gruntplugin module with yo, including Nodeunit unit tests.
JavaScript
35
star
35

generator-jasmine

Yeoman generator for Jasmine
JavaScript
34
star
36

yeoman-character

The Yeoman character in your CLI. Like wat.
JavaScript
21
star
37

yeoman-welcome

Yeoman welcome message used in generators
JavaScript
19
star
38

media

Yeoman logo and artwork
16
star
39

generator-commonjs

Generate a CommonJS module
JavaScript
16
star
40

insight-dashboard

[DEPRECATED] Insight into Yeoman
CSS
11
star
41

Hackathons

Running a Yeoman hackathon? Start here for ideas, tips, and goals
10
star
42

html-wiring

[DEPRECATED] Set of utilities to update HTML files
JavaScript
10
star
43

cli-list

Parse comma-separated argument lists.
JavaScript
9
star
44

yeoman-remote

Fetch packages and archives from remote resources with cache support
JavaScript
8
star
45

generator-dummytest

JavaScript
3
star
46

generator-dummy

Dummy generator used for unit testing purpose
JavaScript
2
star
47

yeoman-api

TypeScript
1
star