hh54188
hh54188

Reputation: 15626

Gulp-concat can't concat file

Here is my directory structure:

- javascript
  |- file2.js
- output
- file1.js
- gulpfile.js

And I want to merge file1.js and file2.js. Here is my gulpfile.js content:

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

gulp.task('javascript', function () {
    return gulp.src('./javascript/*.js')
        .pipe(concat('file1.js'))
        .pipe(gulp.dest('./output/'));
});

however, the concat result is confusing me, the file in output directory is called file1.js, and the content in the file is only from origin file2, so I have some questions:

Upvotes: 0

Views: 461

Answers (1)

Dreamlord
Dreamlord

Reputation: 288

The concat pipe takes as a parameter the name of the output file. The following should work:

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

gulp.task('javascript', function () {
    return gulp.src(['./javascript/file2.js', './file1.js'])
        .pipe(concat('concatenatedFile.js'))
        .pipe(gulp.dest('./output/'));
});

EDIT: I updated the answer so that I explicitly show how to have the two files you want as the source files.

Upvotes: 1

Related Questions