1 | # grunt-rollup
|
2 | [![Build Status](https://travis-ci.org/chrisprice/grunt-rollup.svg)](https://travis-ci.org/chrisprice/grunt-rollup)
|
3 | [![dependencies](https://david-dm.org/chrisprice/grunt-rollup.svg)](https://david-dm.org/chrisprice/grunt-rollup)
|
4 |
|
5 | > Grunt plugin for [rollup](https://github.com/rollup/rollup) - next-generation ES6 module bundler
|
6 |
|
7 | ## Getting Started
|
8 | This plugin requires Grunt `>=0.4.0`
|
9 |
|
10 | If you haven't used [Grunt](http://gruntjs.com/) before, be sure to check out the [Getting Started](http://gruntjs.com/getting-started) guide, as it explains how to create a [Gruntfile](http://gruntjs.com/sample-gruntfile) as well as install and use Grunt plugins. Once you're familiar with that process, you may install this plugin with this command:
|
11 |
|
12 | ```shell
|
13 | npm install grunt-rollup --save-dev
|
14 | ```
|
15 |
|
16 | Once the plugin has been installed, it may be enabled inside your Gruntfile with this line of JavaScript:
|
17 |
|
18 | ```js
|
19 | grunt.loadNpmTasks('grunt-rollup');
|
20 | ```
|
21 |
|
22 | ## The "rollup" task
|
23 |
|
24 | ### Overview
|
25 | In your project's Gruntfile, add a section named `rollup` to the data object passed into `grunt.initConfig()`.
|
26 |
|
27 | ```js
|
28 | grunt.initConfig({
|
29 | rollup: {
|
30 | options: {
|
31 | // Task-specific options go here.
|
32 | },
|
33 | your_target: {
|
34 | // Target-specific file lists and/or options go here.
|
35 | },
|
36 | },
|
37 | });
|
38 | ```
|
39 |
|
40 | ### Options
|
41 |
|
42 | Supports all the options from [rollup's JavaScript API](https://github.com/rollup/rollup/wiki/JavaScript-API).
|
43 |
|
44 |
|
45 | ### Sourcemaps
|
46 | A value of `true` for `sourceMap` will output the map to a file with the same name as the JavaScript with `.map` appended. A value of `inline` for `sourceMap` will inline the sourcemap into the source file.
|
47 |
|
48 | To get relative paths, set `sourceMapRelativePaths` to `true`. This sets rollup `sourceMapFile` property, making the sourcemap relative to the output file.
|
49 |
|
50 | ### Usage Examples
|
51 |
|
52 | ```js
|
53 | grunt.initConfig({
|
54 | rollup: {
|
55 | options: {},
|
56 | files: {
|
57 | 'dest/bundle.js': ['src/entry.js'], // Only one source file is permitted
|
58 | },
|
59 | },
|
60 | });
|
61 | ```
|
62 |
|
63 | ### Usage with Plugins
|
64 |
|
65 | ```js
|
66 | var babel = require('rollup-plugin-babel');
|
67 |
|
68 | grunt.initConfig({
|
69 | rollup: {
|
70 | options: {
|
71 | plugins: [
|
72 | babel({
|
73 | exclude: './node_modules/**'
|
74 | })
|
75 | ]
|
76 | },
|
77 | files: {
|
78 | 'dest':'dest/bundle.js',
|
79 | 'src' : 'src/entry.js', // Only one source file is permitted
|
80 | },
|
81 | },
|
82 | });
|
83 | ```
|
84 |
|
85 | #### Plugin getter
|
86 |
|
87 | Some plugins are stateful and this doesn't play nice with multiple bundles. For example the `rollup-plugin-babel` plugin keeps a track of used `babel` helpers, and passing the configured plugin only once will cause the helpers to leak from one bundle to another. To prevent that, pass a function that returns an array of plugins, like this:
|
88 |
|
89 | ```js
|
90 | var babel = require('rollup-plugin-babel');
|
91 |
|
92 | grunt.initConfig({
|
93 | rollup: {
|
94 | options: {
|
95 | plugins: function() {
|
96 | return [
|
97 | babel({
|
98 | exclude: './node_modules/**'
|
99 | })
|
100 | ];
|
101 | }
|
102 | },
|
103 | files: {
|
104 | 'dest/bundle.js': 'src/entry.js',
|
105 | 'dest/bundle2.js': 'src/entry2.js',
|
106 | },
|
107 | },
|
108 | });
|
109 | ```
|
110 |
|
111 | This way the plugin will be refreshed for each bundle.
|
112 |
|
113 | ## Contributing
|
114 | 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 using [Grunt](http://gruntjs.com/).
|
115 |
|
116 | ## Releasing
|
117 |
|
118 | ```bash
|
119 | npm version minor && git push --tags origin master && npm publish
|
120 | ```
|
121 |
|