4.0.0 • Published 8 years ago

grunt-multibundle-requirejs v4.0.0

Weekly downloads
1
License
MIT
Repository
github
Last release
8 years ago

grunt-multibundle-requirejs

Grunt task for handling multi-bundle requirejs setup

Build Status bitHound Overall Score Join the chat at https://gitter.im/trulia/grunt-multibundle-requirejs

Getting Started

This plugin requires Grunt ^0.4.5

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, you may install this plugin with this command:

npm install grunt-multibundle-requirejs --save-dev

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

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

The "multibundle_requirejs" task

Overview

In your project's Gruntfile, add a section named multibundle_requirejs to the data object passed into grunt.initConfig().

grunt.initConfig({
  'multibundle-requirejs': {
    options: {
      _config: {
        // task "global" options
      },

      bundle_one: [
        // bundle specific config go here
      ],

      bundle_two: [
        // bundle specific config go here
      ]
    }
  },
});

Options

Example file with all the options could be found here Gruntfile.js.

options._config

Type: Object

"Global" config object for the task

options.bundle_name

Type: Array

List of modules to bundle into bundle_name.

_config object

_config.logLevel

Type: Number Default value: 1

Controls log level of the task and requirejs bundler, 4 being silent.

_config.destination

Type: String Default value: undefined

Output folder for the bundles.

_config.sharedBundles

Type: Array Default value: undefined

Defines list of the shared bundles (order matters), all the modules included in the shared bundles, will be excluded from other modules.

_config.hashFiles

Type: Boolean|Function Default value: undefined

If enabled adds md5 hash (over bundle's content) to the bundle's filename. Could be a function (hashFiles(output, componentOptions)), then it will be responsible for producing content hash.

_config.handleMapping

Type: Function

Accepts two arguments options - options object passed to the grunt task, and grunt - grunt instance itself.

Expected to return mapper instance, either WriteStream or a function, that will be called after each bundle creation with respective buildObject, to allow modules-bundle mapping. Will be called one extra time with no arguments after all the bundles processed. In case of WriteStream, bundler's ReadStream will piped into it. For example of the mapping write stream, see multibundle-mapper.

_config.baseUrl

Type: String Default value: undefined

The root path to use for all module lookups. Passed to r.js. Also used as destination if _config.destination is omitted.

_config.optimize

Type: String Default value: none

Minifier option, passed to r.js.

_config.paths

Type: Object Default value: undefined

Path mappings for module names not found directly under baseUrl. Passed to r.js.

_config.preserveLicenseComments

Type: Boolean Default value: false

Controls preseces of the license comments in the minified files. Passed to r.js.

bundle list

bundle.filepath

Type: String Example: 'app/lib/my_module.js'

Adds specified file to the parent bundle.

bundle.glob_mask

Type: String Example: 'app/lib/**/*.js'

Adds all the files matched the pattern to the parent bundle.

bundle.simple_object

Type: Object Example: {'main': 'assets/js/public/main'}

Adds named module from specified filepath to the parent bundle.

bundle.feature_object

Type: Object Example: {'backbone': {src: 'node_modules/backbone/backbone.js', deps: ['jquery', 'underscore'], exports: 'Backbone', insertRequire: true}}

Adds named module from specified source to the parent bundle, with explicitly set dependencies. and creates shim to make it AMD-compatible by exporting global object. Also adds require call to execute module in-place.

Contributing

In lieu of a formal styleguide, take care to maintain the existing coding style. Add unit tests for any new or changed functionality. Lint and test your code before committing.

4.0.0

8 years ago

3.2.0

9 years ago

3.1.1

9 years ago

3.1.0

9 years ago

3.0.0

9 years ago

2.2.0

9 years ago

2.1.1

9 years ago

2.1.0

9 years ago

2.0.0

9 years ago

1.0.1

9 years ago

1.0.0

9 years ago