How do you use the browser in the gulp task?

I am new to Gulp, but following this tutorial, I set up the Gulp task, which is designed to view javascript files in a specific directory and transfer them to another directory - quite simply. I looked at several other lessons, but this method seemed to me the most concise. Here is my code:

var gulp = require('gulp');
var browserify = require('browserify');
var transform = require('vinyl-transform');

gulp.task('js', function() {
  var browserified = transform(function(filename) {
    return browserify(filename).bundle();
  });

  return gulp.src(['./public/js/src/**/*.js'])
    .pipe(browserified)
    .pipe(gulp.dest('./public/js/dist'));
});

The above code is very similar to many other implementations of this kind that I have seen, but when I try to run it with gulp js, it gives the following error:

[15:47:13] Using gulp file
~/development/launchpad/workshop/gulpfile.js
[15:47:13] Starting 'js'...
_stream_readable.js:540
     var ret = dest.write(chunk);

               ^
TypeError: undefined is not a function
    at Producer.ondata (_stream_readable.js:540:20)
    at Producer.emit (events.js:107:17)
    at Producer.Readable.read (_stream_readable.js:373:10)
    at flow (_stream_readable.js:750:26)
    at resume_ (_stream_readable.js:730:3)
    at _stream_readable.js:717:7
    at process._tickCallback (node.js:355:11)

- , ?
( , , , _stream_readable.js Spotlight 20 , , -, Node ?)

+5
2
var browserify = require('browserify');
var gulp = require('gulp');
var source = require('vinyl-source-stream');

gulp.task('browserify', function() {
  return browserify('lib/front/app.js')
    .bundle()
    //Pass desired output filename to vinyl-source-stream
    .pipe(source('bundle.js'))
    // Start piping stream to tasks!
    .pipe(gulp.dest('public/build/'));
});
+2

, browserify/gulp, . , vinyl-source-stream vinyl-buffer:

var gulp = require('gulp');
var browserify = require('browserify');
var source = require('vinyl-source-stream');
var glob = require('node-glob');

gulp.task('browserify', function (cb) {

  glob('./src/**/*.js', {}, function (err, files) {

    var b = browserify();
    files.forEach(function (file) {
        b.add(file);
    });

    b.bundle().
      .pipe(source('output.js'))
      .pipe(gulp.dest('./dist'));

    cb();
  })  
});

.

0

Source: https://habr.com/ru/post/1612849/


All Articles