Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 73 lines (51 sloc) 3.001 kB
af4afd2 @cowboy Readme, docs and description "tagline" tweaks.
authored
1 [Grunt homepage](https://github.com/cowboy/grunt) | [Documentation table of contents](toc.md)
2
495dbaa @cowboy More concat docs tweaks.
authored
3 # concat (built-in task)
8d332e2 @cowboy More concat docs tweaks.
authored
4 Concatenate one or more input files (and/or [directives](helpers_directives.md) output, like `<banner>`) into an output file.
af4afd2 @cowboy Readme, docs and description "tagline" tweaks.
authored
5
33d890c @cowboy More concat docs tweaks.
authored
6 ## About
7
8d332e2 @cowboy More concat docs tweaks.
authored
8 This task is a [basic task](tasks_creating.md), meaning that grunt will automatically iterate over all `concat` targets if no specific target is specified.
af4afd2 @cowboy Readme, docs and description "tagline" tweaks.
authored
9
b81594a @cowboy More concat task doc tweaks.
authored
10 For more information on general configuration options, see the [configuring grunt](configuring.md) page.
11
33d890c @cowboy More concat docs tweaks.
authored
12 ## Usage examples
b81594a @cowboy More concat task doc tweaks.
authored
13
1ab56c0 @cowboy Updating concat docs.
authored
14 ### Concatenating multiple files
15
b81594a @cowboy More concat task doc tweaks.
authored
16 In this example, `grunt concat` will simply concatenate three source files, in order, writing the output to `dist/built.js`.
af4afd2 @cowboy Readme, docs and description "tagline" tweaks.
authored
17
18 ```javascript
19 /*global config:true, task:true*/
20 config.init({
21 concat: {
22 'dist/built.js': ['src/intro.js', 'src/project.js', 'src/outro.js']
23 }
24 });
25 ```
26
1ab56c0 @cowboy Updating concat docs.
authored
27 ### Banner comments
28
b81594a @cowboy More concat task doc tweaks.
authored
29 In this example, `grunt concat` will first strip any pre-existing banner comment from the `src/project.js` file, then concatenate that with a newly-generated banner comment, writing the output to `dist/built.js`.
30
1930507 @cowboy More concat docs tweaks.
authored
31 This generated banner will be the contents of the `meta.banner` mustache template string interpolated (in this case) with values imported from the `package.json` file (which are available via the `pkg` config property) plus today's date.
af4afd2 @cowboy Readme, docs and description "tagline" tweaks.
authored
32
7f6a52b @cowboy More concat docs tweaks.
authored
33 _Note: you don't have to use an external `.json` file. You could just have additional `meta` sub-properties that are referenced in the banner template like `meta.foo`. Also, you can specify the config property that `<banner>` uses. See the [directives](helpers_directives.md) page for more information on directives and their options._
34
af4afd2 @cowboy Readme, docs and description "tagline" tweaks.
authored
35 ```javascript
36 /*global config:true, task:true*/
37 config.init({
38 pkg: '<json:package.json>',
39 meta: {
890aa86 @cowboy Fixing typo in concat docs.
authored
40 banner: '/*! <%= pkg.name %> - v<%= pkg.version %> - <%= template.today("m/d/yyyy") %> */'
af4afd2 @cowboy Readme, docs and description "tagline" tweaks.
authored
41 },
42 concat: {
43 'dist/built.js': ['<banner>', '<file_strip_banner:src/project.js>']
44 }
45 });
46 ```
47
1ab56c0 @cowboy Updating concat docs.
authored
48 ### Multiple build targets
49
b81594a @cowboy More concat task doc tweaks.
authored
50 In this example, `grunt concat` will build two separate files. One "basic" version, with the main file essentially just copied to `dist/basic.js`, and another "with_extras" concatenated version written to `dist/with_extras.js`.
af4afd2 @cowboy Readme, docs and description "tagline" tweaks.
authored
51
b81594a @cowboy More concat task doc tweaks.
authored
52 While each concat target can be built individually by running `grunt concat:dist/basic.js` or `grunt concat:dist/with_extras.js`, running `grunt concat` will build all concat targets. This is because concat is a [basic task](tasks_creating.md).
af4afd2 @cowboy Readme, docs and description "tagline" tweaks.
authored
53
54 ```javascript
55 /*global config:true, task:true*/
56 config.init({
57 concat: {
58 'dist/basic.js': ['src/main.js'],
59 'dist/with_extras.js': ['src/main.js', 'src/extras.js']
60 }
61 });
62 ```
33d890c @cowboy More concat docs tweaks.
authored
63
64 ## Helpers
65
66 A generic `concat` helper is available for use in any other task where file and/or directive concatenation might be useful. For example:
67
68 ```javascript
69 var fooPlusBar = task.helper('concat', ['foo.txt', 'bar.txt']);
70 ```
1416d5b @cowboy Adding links to task source at the bottom of tasks docs.
authored
71
72 See the [concat task source](https://github.com/cowboy/grunt/blob/master/tasks/concat.js) for more information.
Something went wrong with that request. Please try again.