or run

npx @tessl/cli init
Log in

Version

Tile

Overview

Evals

Files

docs

index.md
tile.json

index.mddocs/

Gulp Concat

Gulp Concat is a Gulp plugin that concatenates files with source map support and configurable separators. It processes vinyl file objects through a streaming interface, combining multiple files into a single output file while preserving metadata and source maps.

Package Information

  • Package Name: gulp-concat
  • Package Type: npm
  • Language: JavaScript
  • Installation: npm install --save-dev gulp-concat

Core Imports

const concat = require('gulp-concat');

Basic Usage

const gulp = require('gulp');
const concat = require('gulp-concat');

gulp.task('scripts', function() {
  return gulp.src('./lib/*.js')
    .pipe(concat('all.js'))
    .pipe(gulp.dest('./dist/'));
});

Capabilities

File Concatenation

Concatenates files using a streaming interface with configurable separators and source map support.

/**
 * Creates a transform stream that concatenates files
 * @param {string|Object} file - Output filename or file options object
 * @param {Object} [options] - Configuration options
 * @param {string} [options.newLine='\n'] - Separator between concatenated files
 * @returns {Transform} Transform stream for file concatenation
 */
function concat(file, options)

Parameters

  • file (string | Object): Output file specification
    • If string: Output filename (e.g., 'bundle.js')
    • If object: Vinyl file properties including path, cwd, stat, etc.
  • options (Object, optional): Configuration options
    • newLine (string): Separator between files (default: '\n')

Returns

Transform stream (through2.obj) that processes vinyl files and emits a single concatenated file.

Usage Examples

Basic concatenation:

gulp.src(['lib/file1.js', 'lib/file2.js', 'lib/file3.js'])
  .pipe(concat('combined.js'))
  .pipe(gulp.dest('dist/'));

Custom separator:

gulp.src('src/*.js')
  .pipe(concat('main.js', {newLine: ';'}))
  .pipe(gulp.dest('build/'));

File object with properties:

gulp.src('src/*.js')
  .pipe(concat({
    path: 'new.js',
    stat: { mode: 0666 }
  }))
  .pipe(gulp.dest('dist/'));

With source maps:

const sourcemaps = require('gulp-sourcemaps');

gulp.src('src/**/*.js')
  .pipe(sourcemaps.init())
  .pipe(concat('all.js'))
  .pipe(sourcemaps.write())
  .pipe(gulp.dest('dist/'));

Behavior

  • File Processing: Processes buffered vinyl files, ignores null files
  • Source Maps: Automatically detects and preserves source maps when available
  • Metadata: Inherits properties from the most recently modified input file
  • Path Resolution: Uses base directory from latest file for string file parameter
  • Error Handling: Emits errors for streaming files (not supported)

Error Conditions

The function throws or emits errors in these cases:

// Thrown synchronously when file parameter is missing
throw new Error('gulp-concat: Missing file option');

// Thrown when file object lacks path property
throw new Error('gulp-concat: Missing path in file options');

// Emitted when encountering streaming files
emit('error', new Error('gulp-concat: Streaming not supported'));

Types

// File parameter can be a string or vinyl file object
type FileParam = string | {
  path: string;
  cwd?: string;
  base?: string;
  stat?: fs.Stats;
  [key: string]: any;
};

// Options object for configuration
interface ConcatOptions {
  newLine?: string; // Default: '\n'
}

// Return type is a Transform stream
interface ConcatStream extends Transform {
  // Inherits all Transform stream methods
}

Dependencies

This package depends on:

  • through2: ^2.0.0 - Streaming interface
  • vinyl: ^2.0.0 - File object handling
  • concat-with-sourcemaps: ^1.0.0 - Source map aware concatenation