Coder Social home page Coder Social logo

gulp-concat's Introduction

status

Installation

Install package with NPM and add it to your development dependencies:

npm install --save-dev gulp-concat

Information

Packagegulp-concat
Description Concatenates files
Node Version >= 0.10

Usage

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

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

This will concat files by your operating system's newLine. It will take the base directory from the first file that passes through it.

Files will be concatenated in the order that they are specified in the gulp.src function. For example, to concat ./lib/file3.js, ./lib/file1.js and ./lib/file2.js in that order, the following code will create a task to do that:

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

gulp.task('scripts', function() {
  return gulp.src(['./lib/file3.js', './lib/file1.js', './lib/file2.js'])
    .pipe(concat('all.js'))
    .pipe(gulp.dest('./dist/'));
});

To change the newLine simply pass an object as the second argument to concat with newLine being whatever (\r\n if you want to support any OS to look at it)

For instance:

.pipe(concat('main.js', {newLine: ';'}))

To specify cwd, path and other vinyl properties, gulp-concat accepts Object as first argument:

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

gulp.task('scripts', function() {
  return gulp.src(['./lib/file3.js', './lib/file1.js', './lib/file2.js'])
    .pipe(concat({ path: 'new.js', stat: { mode: 0666 }}))
    .pipe(gulp.dest('./dist'));
});

This will concat files into ./dist/new.js.

Source maps

Source maps can be generated by using gulp-sourcemaps:

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

gulp.task('javascript', function() {
  return gulp.src('src/**/*.js')
    .pipe(sourcemaps.init())
      .pipe(concat('all.js'))
    .pipe(sourcemaps.write())
    .pipe(gulp.dest('dist'));
});

gulp-concat's People

Contributors

c0 avatar caiotoon avatar callumacrae avatar colynb avatar dapetcu21 avatar erikkemperman avatar evansd avatar floatdrop avatar floridoo avatar fritx avatar glcheetham avatar heithemmoumni avatar hzlmn avatar igorklopov avatar jednano avatar jsdevel avatar kahwee avatar kenany avatar kirill-konshin avatar kud avatar pgilad avatar phated avatar shinnn avatar splaktar avatar stevelacy avatar t1st3 avatar thewarpaint avatar tracker1 avatar umaar avatar yocontra avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

gulp-concat's Issues

Error when closing if no file is inputted

When no file is inputted to the stream, it fails while closing with the message:

TypeError: Cannot read property 'base' of null
 at Stream.endStream (C:\Users\011776\Documents\GitHub\gulp-concat\index.js:30:43)
 at _end (C:\Users\011776\Documents\GitHub\gulp-concat\node_modules\through\index.js:65:9)
 at Stream.stream.end (C:\Users\011776\Documents\GitHub\gulp-concat\node_modules\through\index.js:74:5)
 at Context.<anonymous> (C:\Users\011776\Documents\GitHub\gulp-concat\test\main.js:65:14)
 at Test.Runnable.run (C:\Users\011776\AppData\Roaming\npm\node_modules\mocha\lib\runnable.js:196:15)
 at Runner.runTest (C:\Users\011776\AppData\Roaming\npm\node_modules\mocha\lib\runner.js:373:10)
 at C:\Users\011776\AppData\Roaming\npm\node_modules\mocha\lib\runner.js:451:12
 at next (C:\Users\011776\AppData\Roaming\npm\node_modules\mocha\lib\runner.js:298:14)
 at C:\Users\011776\AppData\Roaming\npm\node_modules\mocha\lib\runner.js:308:7
 at next (C:\Users\011776\AppData\Roaming\npm\node_modules\mocha\lib\runner.js:246:23)
 at Object._onImmediate (C:\Users\011776\AppData\Roaming\npm\node_modules\mocha\lib\runner.js:275:5)
 at processImmediate [as _immediateCallback] (timers.js:336:15)

In my specific case, I'm using gulp-if to concatenate files only for production tasks, so the gulp-concat stream would receive no files.

Not working properly when concat font-awesome css file

I use gulp-concat to build my css. Infont-awesome.css, it's font paths are:

src: url('../fonts/fontawesome-webfont.eot?v=4.3.0');
src: url('../fonts/fontawesome-webfont.eot?#iefix&v=4.3.0') format('embedded-opentype'), url('../fonts/fontawesome-webfont.woff2?v=4.3.0') format('woff2'), url('../fonts/fontawesome-webfont.woff?v=4.3.0') format('woff'), url('../fonts/fontawesome-webfont.ttf?v=4.3.0') format('truetype'), url('../fonts/fontawesome-webfont.svg?v=4.3.0#fontawesomeregular') format('svg');

My gulpfile.js

gulp.task('styles', function() {
    return gulp.src(['assets/css/*.css', 'assets/bower_components/fontawesome/css/font-awesome.css'])
        .pipe(concatCss('build.min.css'))
        .pipe(gulp.dest('dist/css'))
        .pipe(notify({message: 'Style task complete.'}));
});

But in my build.min.css, the font paths have been somehow changed to:

src: url("../bower_components/fontawesome/fonts/fontawesome-webfont.eot?v=4.3.0");
src: url("../bower_components/fontawesome/fonts/fontawesome-webfont.eot?#iefix&v=4.3.0") format('embedded-opentype'), url("../bower_components/fontawesome/fonts/fontawesome-webfont.woff2?v=4.3.0") format('woff2'), url("../bower_components/fontawesome/fonts/fontawesome-webfont.woff?v=4.3.0") format('woff'), url("../bower_components/fontawesome/fonts/fontawesome-webfont.ttf?v=4.3.0") format('truetype'), url("../bower_components/fontawesome/fonts/fontawesome-webfont.svg?v=4.3.0#fontawesomeregular") format('svg');

So why they're not the same with the original file?

Fails to concatenate the whole last file.

I'm using gulp-concat version 2.4.0 and gulp 3.8.7.

This plugin isn't concatenating the whole file in my list of js files. Specifically, it's ignoring a portion of the last JS file in the array.

Source map is not attached to concatenated file if config is provided as object

Source map is not attached to concatenated file if config is provided as object: concat({path: ...}). This happens because:

  if (typeof file !== 'string') {
    ...
    firstFile = new File(file);
  }

Will not have the property sourceMap and thus

if (!concat) concat = new Concat(!!firstFile.sourceMap, fileName, opt.newLine)

will not set proper flag for Concat.

Could be solved by adding || !!file.sourceMap:

if (!concat) concat = new Concat(!!firstFile.sourceMap || !!file.sourceMap, fileName, opt.newLine);

TypeError: Cannot convert null to object

Seeing the following error way down in the source-map package when using gulp-sourcemaps, gulp-less and gulp-concat together:

/Users/montgomeryc/Projects/test-sourcemap-fix/node_modules/gulp-concat/node_modules/concat-with-sourcemaps/node_modules/source-map/lib/source-map/source-map-generator.js:142
        delete this._sourcesContents[util.toSetString(source)];
                                          ^
TypeError: Cannot convert null to object
    at SourceMapGenerator_setSourceContent [as setSourceContent] (/Users/montgomeryc/Projects/test-sourcemap-fix/node_modules/gulp-concat/node_modules/concat-with-sourcemaps/node_modules/source-map/lib/source-map/source-map-generator.js:142:43)
    at /Users/montgomeryc/Projects/test-sourcemap-fix/node_modules/gulp-concat/node_modules/concat-with-sourcemaps/index.js:63:28
    at Array.forEach (native)
    at Concat.add (/Users/montgomeryc/Projects/test-sourcemap-fix/node_modules/gulp-concat/node_modules/concat-with-sourcemaps/index.js:62:35)
    at Stream.bufferContents (/Users/montgomeryc/Projects/test-sourcemap-fix/node_modules/gulp-concat/index.js:25:12)
    at Stream.stream.write (/Users/montgomeryc/Projects/test-sourcemap-fix/node_modules/gulp-concat/node_modules/through/index.js:26:11)
    at write (/Users/montgomeryc/Projects/test-sourcemap-fix/node_modules/gulp-less/node_modules/through2/node_modules/readable-stream/lib/_stream_readable.js:623:24)
    at flow (/Users/montgomeryc/Projects/test-sourcemap-fix/node_modules/gulp-less/node_modules/through2/node_modules/readable-stream/lib/_stream_readable.js:632:7)
    at Transform.pipeOnReadable (/Users/montgomeryc/Projects/test-sourcemap-fix/node_modules/gulp-less/node_modules/through2/node_modules/readable-stream/lib/_stream_readable.js:664:5)
    at Transform.emit (events.js:92:17)

My gulpfile.js that shows the error:

// gulpfile.js
var gulp = require('gulp');
var less = require('gulp-less');
var concat = require('gulp-concat');
var sourcemaps = require('gulp-sourcemaps');

gulp.task('less', function () {
  gulp.src('./less/**/*.less')
    .pipe(sourcemaps.init())
    .pipe(less())
    .pipe(concat('all.css'))
    .pipe(sourcemaps.write())
    .pipe(gulp.dest('./public/css'));
});

I've submitted a PR against sourcemap and just need the version bumped here when it's merged.

Ordering of the files

Is there a recommend way to make sure the concated files have a specific order?
Sorry, I'm new to gulp.

Ordering concatenations

I know this has been brought up before, having looked through the issues; but I have a new use-case here, and thought it might deserve another look:

When I need to add more files further into a stream, I don't have an option about their position in the stream's list of files. For instance, when acquiring a set of files, preforming some operation on those, and then acquiring other files I don't want to preform that operation on โ€ฆ now, I'm stuck with gulp-concat putting whatever files I don't process, last.

Specific example:

gulp.task 'build-css', ->
   return gulp
      .src [ './Resources/*.less' ]
      .pipe plugin('if') /[.]less$/, plugin('less') paths: './Resources'
      .pipe plugin('myth')()
      .pipe plugin('minify-css') keepBreaks: yes
      .pipe gulp.src './bower_components/normalize.css/normalize.css'
      .pipe plugin('concat')()
      .pipe gulp.dest './Resources'

There's no way of doing this without either A) some complex backflips to manipulate the streams themselves, or B) ending up with the contents of normalize.css at the end of my concatenated CSS file.

So, my thought: if you accept #36; it will become possible to deterministically order streams by reversing, concatenating, and then re-reversing. Or something like that. Doesn't seem great, but I can't think of any easier ways to do this. /=

CSS concat - Charset

Would be possible to add functionality to strip charset from the concatenated stylesheets / leave only the first one? As far as i know stylesheets can have charset declared only as a first characters in the file (not even a space or comment before it) and everything else is considered invalid. When i concatenate stylesheets (for example mine generated by sass and from some packages) i get charset declarations in the middle of the file which is invalid. And as far as i know sass always puts it there you can only tell it to use different charset.

I was thinking about some boolean option to the package that would add this functionality. Since this is always in the beginning of the file and has specific format it could be easily matched with regex and overwritten with empty string.

Any chance I can exclude sourcemap files from the concatenation task

I have a task that will compile Coffeescript files and then outputs the Javascript into a single JS file using gulp-concat.

My only problem with this is that the sourcemap is also getting concatenated into the output file:

gulp.task('coffee', function () {
  gulp.src( options.COFFEE_SOURCE )
    .pipe(coffee({
        // bare: true
        sourceMap: true
    })
    .on('error', gutil.log))
    .pipe(concat("app.js"))
    .pipe(uglify())
    .pipe(gulp.dest( options.COFFEE_DEST ))
    .pipe(livereload(server));
});

Is there any way I can avoid this, still having all Coffeescript built into a single JS file but still having the sourcemap as a separated file?

Corrupts binary files (non-unicode files)

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

gulp.task('default', function() {
  return gulp.src('gulpfile.js')
    .pipe(zip('gulpfile.zip'))
    .pipe(concat('gulpfile.zip'))
    .pipe(gulp.dest('.'));
});

Resulting gulpfile.zip is corrupted. With concat line commented out everything works as expected.

gulp-concat v2.4.2, gulp v3.8.10, node v0.10.31

File reference in sourcemap mismatches file.path

Concatenation of three files inside ./src/ creates the following source map:

 { version: 3,
  sources: [ 'a.css', 'b.css', 'c.css' ],
  names: [],
  mappings: 'AAAA;AACA;AACA;AACA;ACHA;AACA;AACA;AACA;ACHA;AACA;AACA;AACA',
  file: 'result-postcss.css',
  sourcesContent: 
   [ '.a {\n\ttext-align: center;\n}\n',
     '.b {\n\ttext-align: center;\n}\n',
     '.c {\n\ttext-align: center;\n}\n' ] }

The result vinyl file object has path similar to this: /Users/username/path/to/gulp-postcss-sourcemaps-test/src/result-postcss.css (note that it includes src/).

I think that all file references in sourcemaps should include src/ because otherwise you cannot combine this sourcemap with further modifications.

Please find more details here: postcss/gulp-postcss#18

names array not populated when creating sourcemaps using gulp-concat.

What I'm experiencing

I was working through this issue and noticed that when I use gulp-concat, the names array is always empty.

This is true even during trivial cases (one file being source-mapped).
@floridoo mentioned it was probably gulp-rev causing my issue, but so far that's not what I've found.
btw, thanks to @floridoo for responding expediently.

Snippet

  return gulp.src('source/some-dir/another-dir/one-file-to-be-sourcemapped.js')
    .pipe(sourcemaps.init())
//    .pipe(concat('built.js')) // If I uncomment this line, the names array is empty.
     .pipe(uglify())
    .pipe(rev())
    .pipe(transformFooter())
    .pipe(sourcemaps.write('./', { addComment: false}))
    .pipe(gulp.dest(destination));

My true intention

I want to un-minify the source maps (due to an exception being thrown) at runtime.
so far using mozilla source-map I can still get the line number and column, but not the name.

Changelog.md

Knowing what changed in terms of API, bug fixes, performance, and new features is really useful.

Sourcemaps support

Is there a way to output sourcemaps for concatted files?
Or is there a workaround?
For now without sourcemaps it is difficult to debug concatted files. Besides, it might be useful for uglifyโ€™s inSourceMap.

TypeError: Arguments to path.join must be strings

Hey guys, when updating to v3.0.0 of Gulp I'm getting this issue with concat:

stream.js:94
      throw er; // Unhandled stream error in pipe.
            ^
TypeError: Arguments to path.join must be strings
    at path.js:360:15
    at Array.filter (native)
    at Object.exports.join (path.js:358:36)
    at saveFile (/node_modules/gulp/lib/createOutputStream/index.js:13:26)
    at wrappedMapper (/node_modules/gulp/node_modules/event-stream/node_modules/map-stream/index.js:76:19)
    at Stream.stream.write (/node_modules/gulp/node_modules/event-stream/node_modules/map-stream/index.js:88:21)
    at Stream.ondata (stream.js:51:26)
    at Stream.EventEmitter.emit (events.js:95:17)
    at Stream.endStream (/node_modules/gulp-concat/index.js:28:10)
    at _end (/node_modules/event-stream/node_modules/through/index.js:65:9)

Any ideas?
Cheers!

Missing fileName option for gulp-concat

Hi!

I can't seem to get concat working and considering how simple it should be, I can't understand where I could have gone wrong? As you'll see from my gulp task, I have specified the filename.

screen shot 2014-04-30 at 10 46 02

screen shot 2014-04-30 at 10 47 00

Empty files break sourcemap

Occasionally you have a step (in my case, typescript compilation) that generates an empty file. This causes concat to fail.

<root>/applications/gulp-tools/node_modules/gulp-concat/node_modules/concat-with-sourcemaps/node_modules/source-map/lib/source-map/source-map-generator.js:273
        throw new Error('Invalid mapping: ' + JSON.stringify({
              ^
Error: Invalid mapping: {"generated":{"line":1,"column":0},"original":{"line":1,"column":0},"name":null}
    at SourceMapGenerator_validateMapping [as _validateMapping] (<root>/applications/gulp-tools/node_modules/gulp-concat/node_modules/concat-with-sourcemaps/node_modules/source-map/lib/source-map/source-map-generator.js:273:15)
    at SourceMapGenerator_addMapping [as addMapping] (<root>/applications/gulp-tools/node_modules/gulp-concat/node_modules/concat-with-sourcemaps/node_modules/source-map/lib/source-map/source-map-generator.js:102:12)
    at Concat.add (<root>/applications/gulp-tools/node_modules/gulp-concat/node_modules/concat-with-sourcemaps/index.js:75:25)
    at Stream.bufferContents (<root>/applications/gulp-tools/node_modules/gulp-concat/index.js:35:12)
    at Stream.stream.write (<root>/applications/gulp-tools/node_modules/gulp-concat/node_modules/through/index.js:26:11)
    at write (_stream_readable.js:583:24)
    at flow (_stream_readable.js:592:7)
    at CompileStream.pipeOnReadable (_stream_readable.js:624:5)
    at CompileStream.EventEmitter.emit (events.js:92:17)
    at emitReadable_ (_stream_readable.js:408:10)
    at emitReadable (_stream_readable.js:404:5)
    at readableAddChunk (_stream_readable.js:165:9)
    at CompileStream.Readable.push (_stream_readable.js:127:10)
    at emit (<root>/applications/gulp-tools/node_modules/gulp-typescript/release/project.js:245:22)
    at sortedEmit (<root>/applications/gulp-tools/node_modules/gulp-typescript/release/project.js:267:17)
    at Project.compile (<root>/applications/gulp-tools/node_modules/gulp-typescript/release/project.js:273:17)
    at CompileStream.compile (<root>/applications/gulp-tools/node_modules/gulp-typescript/release/main.js:53:23)
    at CompileStream.end (<root>/applications/gulp-tools/node_modules/gulp-typescript/release/main.js:63:14)
    at DestroyableTransform.onend (<root>/applications/gulp-tools/node_modules/gulp-sourcemaps/node_modules/through2/node_modules/readable-stream/lib/_stream_readable.js:523:10)
    at DestroyableTransform.g (events.js:180:16)
    at DestroyableTransform.EventEmitter.emit (events.js:117:20)
    at <root>/applications/gulp-tools/node_modules/gulp-sourcemaps/node_modules/through2/node_modules/readable-stream/lib/_stream_readable.js:965:16
    at process._tickDomainCallback (node.js:459:13)

Here is an example of the task that causes this failure.

var ts = require('gulp-typescript');
var concat = require('gulp-concat');
var sourcemaps = require('gulp-sourcemaps');

gulp.task('compile-ts', function () {
    var compile = gulp.src(conf.tscSources)
        .pipe(sourcemaps.init())
        .pipe(ts({
            declarationFiles: true,
            noExternalResolve: true,
            sortOutput: true,
            target: 'ES5'
        }));

    return compile.js
        .pipe(concat('app.js'))
        .pipe(sourcemaps.write('./maps'))
        .pipe(gulp.dest(conf.distDir));
});

While it's relatively trivial to filter empty files from a stream I believe not doing so shouldn't cause concat to tank.

multiple gulp concat - not supported ?

Hi,

using

gulp.src("file.js")
.pipe(concat("file2.js"))
.pipe(concat("file3.js"))
.pipe(gulp.dest("file4.js"));

will not put all files into dest.
Is this expected ?
If true, why does it makes a difference when operating on streams ?

I know using gulp.src(["file.js", "file2.js", "file3.js", "file4.js"]) will fix it.

Files not being concatenated in deterministic order

I'm running the following gulp task:

var outputFiles = {
    compiledStyles: '/styles/app-compiled.css'
};

var sourcePaths = {
    styles: ['/styles/*.css']
};

gulp.task('compile-styles', function() {
    var concatOutputPath = path.dirname(outputFiles.compiledStyles), 
        concatOutputFileName = path.basename(outputFiles.compiledStyles),
        styleFiles = [].concat(
            sourcePaths.styles,
            notpath(outputFiles.compiledStyles)
        );

    del(outputFiles.compiledStyles);

    return gulp
        .src(styleFiles)
        .pipe(buildTools.concat(concatOutputFileName))
        .pipe(gulp.dest(concatOutputPath));
});

Sometimes when I run compile-styles, the order of a couple files toward the end of outputFileName is different. In other words, inside outputFileName, I always see the [content] of each file this:

[file1.css]
[file2.css]
[file3.css]
[file4.css]
[file5.css]

...except sometimes, maybe every other time or every third time I run compile-styles I'll see this:

[file1.css]
[file2.css]
[file3.css]
[file5.css]
[file4.css]

...where the order of file5.css and file4.css has swapped.

The function notpath() simply takes a string or array of strings and prepends ! before them, then returns that array. (If notpath receives a string argument, it returns it wrapped in an array.)

Not sure if this is an issue with concat or gulp.src or npm's globbing maybe?

Not working on windows

Hi there,

Can't seem to make it work on windows.

Not getting any errors, though.

gulpfile looks like:

    gulp.src(['js/shims.js', 'js/main.js'])
        .pipe(
            watch()
        )
        .pipe(
            concat("all.js")
        )
        .pipe(
            gulp.dest('js')
        );

Allow no argument?

Sometimes the name of the concatenated file doesn't matter. Like:

var gulp = require("gulp");
var dox = require("gulp-dox");
var doxme = require("gulp-doxme");
var concat = require("gulp-concat");
var rename = require("gulp-rename");

gulp.src("**.js")
  .pipe(concat("anything"))
  .pipe(dox())
  .pipe(doxme())
  .pipe(rename("Readme.md"))
  .pipe(gulp.dest("."))
  ;

I understand "" can't ever be a valid filename. But undefined casts to "undefined", same with null. Why not allow them?

It shouldn't do any harm. When someone sees a file named undefined output to his gulp.dest, it's quite obvious what happened. Without throwing any error.

concat() not removing files from through stream

concat() takes an input file name and creates a buffer containing all the contents of the stream, but it doesn't modify the file list of the incoming stream.

For instance:

// var tap = require('gulp-tap');
gulp.src(['file1.js', 'file2.js'])
  .pipe(concat('output.js')
  .pipe(tap, function (file, t) {
    console.log('file', file.relative);
  })
  .pipe(gulp.dest('./dest')

The console will output:

output.js
output.js

If the process is piped to something like gulp-rev, the output will look like this:

output-abcd1234.js
output-abcd1234-abcd1234.js

What's worse is gulp.dest output both files to the file system

I've gotten around this by using a gulp-filter which modifies the through stream and I remove all but the first file input:

// var gFilter = require('gulp-filter');
var firstFile = true
gulp.src(['file1.js', 'file2.js'])
  .pipe(concat('output.js')
  .pipe(gFilter(function (file) {
    if (firstTime) {
      firstTime = false;
      return true;
    }
    return false;
  }))
  .pipe(rev())
  .pipe(tap, function (file, t) {
    console.log('file', file.relative);
  })
  .pipe(gulp.dest('./dest')

This will only make 1 file and 1 console.log output.

Discussion: Default mode is 0777

I noticed when concatting some js files into one, the default file mode on the result is 0777. I believe this is set here.

Would it be reasonable to copy the stat object from the first file found here to override vinyl-fs's 0777 default?

Accept vinyl-file options as argument

I've stumbled upon this in issue, that related with gulp-jade.

Jade calculates relative path's from extend and include based on filename which is taken from path of the incoming vinyl file. Problem is - I have bunch of files with mixins that goes before actual file with extend in it. So concat takes path from first file (that contain mixins) and jade calculating extend from mixin file and not from last file, that contains extend instruction.

May be it is worth to create option cloneLast - that will tell gulp-concat to clone last file?

Concat appends to a file instead of overwriting it.

I can't remember ever having this issue before, but with the latest release concat appends to my file instead of overwriting it.

I use the following task:

gulp.task('js:dist', function() {

    return gulp.src([
            dirs.main + '/' + name + '/js/*.js',
            dirs.main + '/' + name + '/js/plugins/**/*.js'
        ])
        .pipe(plugins.concat('scripts.all.js'))
        .pipe(gulp.dest(dirs.main + '/' + name + '/js/'));

});

I would expect it to overwrite scripts.all.js, but instead it keeps appending to this file.
Is this a bug or am I overlooking something?

Optionally concat in reverse order

Would you like a pull request for an optional argument to concat that concatenates the input in reverse order? I have a need for such a usage but would rather not make a brand new plugin to accomplish this.

Gulp-concat with sourcemaps

The last update of gulp-concat, which supports sourcemaps isn't working properly. Below you have the output:

./node_modules/.bin/gulp
[13:07:59] Using gulpfile ~/boards-ui/gulpfile.js
[13:07:59] Starting 'buildScripts'...
[13:07:59] Starting 'buildStyles'...
[13:07:59] Starting 'watch'...
[13:07:59] Finished 'watch' after 14 ms
gulp-sourcemap: source file not found:/Users/catalinm/boards-ui/src/styles/clearfix.less
gulp-sourcemap: source file not found:/Users/catalinm/boards-ui/src/styles/headings.less
gulp-sourcemap: source file not found:/Users/catalinm/boards-ui/src/styles/hello-world.less
gulp-sourcemap: source file not found:/Users/catalinm/boards-ui/src/styles/box-shadow.less
gulp-sourcemap: source file not found:/Users/catalinm/boards-ui/src/styles/typography.less

gulpfile.js snippet:

gulp.task('buildStyles', function(){
  return gulp.src(paths.build.styles)
    .pipe(plumber())
    .pipe(sourcemaps.init())
    .pipe(concat('boards.less'))
    .pipe(less())
    .pipe(sourcemaps.write('./maps'))
    .pipe(gulp.dest(paths.build.outputPath));
});

The fix is quite easy, file.path wasn't mentioned right

filter strings

  1. Is it possible to filter certain strings like use strict
  2. And add use strict on top of the concatenated file?

Add a debounce option

It would be cool if it was somehow possible to reintegrate the job that was done in the gulp-continuous-concat fork (https://github.com/Kinvey/gulp-continuous-concat).

I believe this should not be the "standard" behaviour but it would be great to have a debounce option right away in gulp concat. That would make sense in conjunction with gulp-watch.

If I were to make a PR for that, would you be likely to accept it or would it be impossible?

Gulp version in peerDependencies causes conflict on install

After installing gulp and gulp-jshint:

npm install --save-dev gulp gulp-jshint

My package.json has:

  "devDependencies": {
    "gulp-jshint": "~1.3.0",
    "gulp": "~3.1.1"
  }

Attempting to install gulp-concat:

npm install --save-dev gulp-concat

Yields the following error:

npm ERR! peerinvalid The package gulp does not satisfy its siblings' peerDependencies requirements!
npm ERR! peerinvalid Peer [email protected] wants gulp@~3.0.0

npm ERR! System Darwin 12.4.0
npm ERR! command "node" "/usr/local/bin/npm" "install" "--save-dev" "gulp-concat"
npm ERR! cwd /Users/lazd/repos/gulp-test
npm ERR! node -v v0.10.17
npm ERR! npm -v 1.3.8
npm ERR! code EPEERINVALID
npm ERR! 
npm ERR! Additional logging details can be found in:
npm ERR!     /Users/lazd/repos/gulp-test/npm-debug.log
npm ERR! not ok code 0

gulp-jshint doesn't specify peer dependencies, maybe gulp-concat should do the same.

Add support for streams

stream.js:94
      throw er; // Unhandled stream error in pipe.
            ^
[gulp] Error in plugin 'gulp-concat': Streaming not supported
    at Stream.bufferContents (/home/michael.heuberger/binarykitchen/code/videomail.io/node_modules/gulp-concat/index.js:21:52)
    at Stream.stream.write (/home/michael.heuberger/binarykitchen/code/videomail.io/node_modules/gulp-concat/node_modules/through/index.js:26:11)
    at write (/home/michael.heuberger/binarykitchen/code/videomail.io/node_modules/vinyl-source-stream/node_modules/through2/node_modules/readable-stream/lib/_stream_readable.js:605:24)
    at flow (/home/michael.heuberger/binarykitchen/code/videomail.io/node_modules/vinyl-source-stream/node_modules/through2/node_modules/readable-stream/lib/_stream_readable.js:614:7)
    at Transform.pipeOnReadable (/home/michael.heuberger/binarykitchen/code/videomail.io/node_modules/vinyl-source-stream/node_modules/through2/node_modules/readable-stream/lib/_stream_readable.js:646:5)
    at Transform.EventEmitter.emit (events.js:92:17)
    at emitReadable_ (/home/michael.heuberger/binarykitchen/code/videomail.io/node_modules/vinyl-source-stream/node_modules/through2/node_modules/readable-stream/lib/_stream_readable.js:430:10)
    at emitReadable (/home/michael.heuberger/binarykitchen/code/videomail.io/node_modules/vinyl-source-stream/node_modules/through2/node_modules/readable-stream/lib/_stream_readable.js:426:5)
    at readableAddChunk (/home/michael.heuberger/binarykitchen/code/videomail.io/node_modules/vinyl-source-stream/node_modules/through2/node_modules/readable-stream/lib/_stream_readable.js:187:9)
    at Transform.Readable.push (/home/michael.heuberger/binarykitchen/code/videomail.io/node_modules/vinyl-source-stream/node_modules/through2/node_modules/readable-stream/lib/_stream_readable.js:149:10)

I have to wrap your plugin with streamify to make it work :(

gulp-concat seems to sallow errors

Thank you for a very useful project!

I have an issue regarding errors not being propagated. Please consider the following snippet from my gulpfile:

    ...
    .on('error', function(err) {
        console.log("A!");
    })
    .pipe(concat('Sample.js'))
    .on('error', function (err) {
        console.log("B!");
    })
    ...

When there are any errors I see "A!" in the output. However, I do not see "B!" in the output (even if the first error handling section is omitted).

This means the exit code ends up being incorrect and this messes up my build integration.

Won't concat files in certain order

(On latest version)

I'm seeing an odd issue where files declared in one order will be concatenated successfully, but not in a different order. Annoyingly the order that works in this case is the wrong order for my needs.

This works:

gulp.task('plugins', function() {
    return gulp.src(['js/compiled/scripts.min.js','plugins/*.js'])
        .pipe(concat('all.min.js'))
        .pipe(gulp.dest('dist'));
});

This doesn't:

gulp.task('plugins', function() {
    return gulp.src(['plugins/*.js','js/compiled/scripts.min.js'])
        .pipe(concat('all.min.js'))
        .pipe(gulp.dest('dist'));
});

No errors.

scripts.min.js lints just fine, but does have a long sourcemap added to the end of it after linting.

Edit: Updating to add that removing the sourcemap doesn't have any effect.

Editing to clarify: 'Doesn't work', by this I actually mean that the second example will result in all.min.js only containing the single file currently in plugins/. i.e. it doesn't combine the files from those two locations. In the first example, it successfully concat's the files as you'd expect.

incorrect work with merge streams plugins

Windows, node.js v 0.12.2

File structure:

test1
|- script1.js
|- script2.js
|- ...
test2
...
test5

gulpfile.js:

gulp.task('test', function() {
    var streamsArr = [];

    for (var stream, i = 1; i < 5; i++) {
        stream = gulp.src(path.join(__dirname, 'test' + i, '**/*'))
            .pipe(through.obj(function(file, enc, callback) {
                setTimeout(function() {
                    callback(null, file);

                }, Math.ceil(Math.random()*100));
            }))
            .pipe(require('gulp-concat')('script.js'))
            .on('end', (function(i) {
                console.log('end of the stream ' + i);
            }).bind(null, i));

        streamsArr.push(stream);
    }

    require('gulp-merge')(streamsArr) //or stream-series, or merge-stream, etc.
        .pipe(through.obj(function(file, enc, callback){
            console.log('merged stream transform:', path.relative(__dirname, file.path));

            callback(null, file);

        }, function(callback) {
            console.log('merged stream flush');

            callback();
        }))
        .on('end', function() {
            console.log('end of the merged stream');
        });
});

console:

end of the stream 4
end of the stream 3
merged stream transform: test1\script.js
end of the stream 1
merged stream transform: test2\script.js
end of the stream 2

Somehow, part of a stream is lost. Also did not work flush and end event of merged stream.

watch .coffee to concat but only run once in windows

var coffee, coffeeSrc, coffeeWatch, concat, directory, exec, gulp, plugins, watch;

gulp = require('gulp');

plugins = (require('gulp-load-plugins'))();

exec = require('child_process').exec;

directory = 'lib-coffee/';

coffeeSrc = [directory + 'settings.coffee', directory + 'utility.coffee', directory + 'player.coffee', directory + 'main.coffee'];

concat = plugins.concat;

coffee = plugins.coffee;

watch = plugins.watch;

coffeeWatch = function() {
return gulp.src(coffeeSrc).pipe(concat('main.js')).pipe(gulp.dest('bin/')).on('error', function(err) {
return console.log(err);
});
};

gulp.task('coffeeWatch', coffeeWatch);

gulp.task('watch', function() {
return gulp.watch('lib-coffee/*.coffee', ['coffeeWatch']);
});

my code only concat when the watch task init run
why ?may the code is wrong?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.