Registry / devops / grunt-contrib-concat

grunt-contrib-concat

JSON →
library2.1.0jsnpmunverified

Grunt plugin to concatenate files. Stable version 2.1.0 (latest), maintenance mode with infrequent updates. Key differentiator: native Grunt integration, supports source maps, banners, separators, and file processing templates. Minimal configuration compared to rollup or webpack for simple concatenation tasks.

npm install grunt-contrib-concat
INSTALL
IMPORT
SIG · GRUNT-CONTRIB-CONC
G
grunt-contrib-concat
devopsjavascriptv2.1.0
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

grunt-contrib-concat
npm install grunt-contrib-concat --save-dev
npm install grunt-contrib-concat --save
Install as devDependency. Load with grunt.loadNpmTasks('grunt-contrib-concat').
concat task
grunt.initConfig({ concat: { dist: { src: ['src/*.js'], dest: 'dist/bundle.js' } } });
grunt.initConfig({ 'grunt-contrib-concat': { ... } });
Task name is 'concat', not the plugin package name.
grunt.loadNpmTasks
grunt.loadNpmTasks('grunt-contrib-concat');
require('grunt-contrib-concat');
Must use grunt.loadNpmTasks, not require(), to register the task.

Gruntfile configuration for concatenating JavaScript files with separator and banner.

module.exports = function(grunt) { grunt.initConfig({ concat: { options: { separator: ';', banner: '/*! bundle */\n' }, dist: { src: ['src/file1.js', 'src/file2.js'], dest: 'dist/bundle.js' } } }); grunt.loadNpmTasks('grunt-contrib-concat'); grunt.registerTask('default', ['concat']); };
Debug
Known issues
gotchaWhen using source maps, ensure sourceMapName option is set if output file extension is not .js (e.g., .css).
fix
Explicitly set sourceMapName to the desired .map path.
affects: >=1.0.0
gotchaThe separator default is grunt.util.linefeed, which is '\n' on Unix and '\r\n' on Windows. This can cause cross-platform inconsistencies.
fix
Explicitly set separator: '\n' for consistent behavior.
affects: >=1.0.0
deprecatedThe 'process' option with a boolean true is deprecated in favor of using the 'process' function or template processing.
fix
Use process: function(src, filepath) { return grunt.template.process(src); } or similar.
affects: >=2.0.0
Errors
Common errors & fixes
Warning: Task "concat" not found. Use --force to continue.
grunt.loadNpmTasks('grunt-contrib-concat') is missing or misspelled.
fix
Add grunt.loadNpmTasks('grunt-contrib-concat'); to your Gruntfile.
Fatal error: Unable to read "src/file.js" file (Error code: ENOENT).
Source file path is incorrect or file does not exist.
fix
Check the src array paths relative to Gruntfile.js or use cwd option.
Invalid options object. Concat has been initialized using an options object that does not match the API schema.
Mistyped option name (e.g., 'separator' misspelled) or invalid value type.
fix
Verify options match the documented schema (string for separator, object for process, etc.).
Upgrade
Version history
2.1.0latest on npm
Audit
Dependencies
gruntrequiredPeer dependency: requires Grunt >=1.4.1 to load and run the task.
Agent activity
6 hits · last 30 days
node
6
Resources
grunt-contrib-concat — npm install grunt-contrib-concat · libregistry