Gulp dependent tasks - browser and task in front of the browser

I have the following gulpfile

And I use emberate , which accepts a callback that is called when the generated file ( client/.index.jsin this case) was written. Now the task browserifydepends on this file, so it should not work until emberate ends. But I get different results, sometimes it works, and sometimes I get this:

Error: Cannot find the module. /client/.index.js' from '/ Users / myuser / workspace / myproject'

from the browser (and yes, the file does not exist yet). I'm not sure what I'm doing wrong, I have doneemberate as a callback in my task, and the view function depends on emberate. What am I missing?

Edit : found a small template, if I ran it, and this is not an error, the next time gulpI start, I get an error, but the next time I do not, so every time oO

If I run gulp emberate, this works fine. Then, if I run gulp browserify, it runs the following:

[gulp] Using file /Users/myuser/workspace/myproject/gulpfile.js
[gulp] Working directory changed to /Users/myuser/workspace/myproject
[gulp] Running 'clean'...
[gulp] Finished 'clean' in 3.11 ms
[gulp] Running 'emberate'...
[gulp] Finished 'emberate' in 22 ms
[gulp] Running 'browserify'...
[gulp] Live reload server listening on: 35729

events.js:72
        throw er; // Unhandled 'error' event
              ^
Error: Cannot find module './client/.index.js' from '/Users/myuser/workspace/myproject'
    at /Users/myuser/workspace/myproject/node_modules/browserify/node_modules/resolve/lib/async.js:36:25
    at load (/Users/myuser/workspace/myproject/node_modules/browserify/node_modules/resolve/lib/async.js:54:43)
    at /Users/myuser/workspace/myproject/node_modules/browserify/node_modules/resolve/lib/async.js:60:22
    at /Users/myuser/workspace/myproject/node_modules/browserify/node_modules/resolve/lib/async.js:16:47
    at Object.oncomplete (fs.js:107:15)

This latest version seems to work, but during viewing, if the files have been changed, it does not clear the file client/.index.jsbut continues to add oO to it (although starting gulp emberatewith or without dependencies cleanworks just fine.).

+4
source share
2 answers

, emberate, , gulp.watch.

gulpfile.js:

  var path = require('path');
  var gulp = require('gulp');
  var less = require('gulp-less');
  var refresh = require('gulp-livereload');
  var clean = require('gulp-clean');
  var source = require('vinyl-source-stream');
  var emberate = require('emberate');
  var browserify = require('browserify');

  gulp.task('less', function () {
    return gulp.src('./client/styles/*.less')
      .pipe(less({
        paths: [
          path.join(__dirname, 'client', 'styles')
        ]
      }))
      .pipe(gulp.dest('./dist/styles'))
      .pipe(refresh());
  });

  gulp.task('clean', function () {
    return gulp.src('./client/.index.js', { read: false })
      .pipe(clean());
  });

  gulp.task('emberate', ['clean'], function () {
    return emberate('./client', { pods: true })
      .pipe(source('.index.js'))
      .pipe(gulp.dest('./client'));
  });

  gulp.task('browserify', ['emberate'], function () {
    return browserify('./client/.index.js')
      .bundle()
      //Pass desired output filename to vinyl-source-stream
      .pipe(source('application.js'))
      // Start piping stream to tasks!
      .pipe(gulp.dest('./dist/scripts/'))
      .pipe(refresh());
  });

  gulp.task('watch', function () {
    gulp.watch('./client/styles/*.less', ['less']);
    gulp.watch('./client/**/*.{js,hbs}', ['browserify']);
  });

 gulp.task('default', ['less', 'browserify', 'watch']);

:)

+1

gulp , . . https://github.com/gulpjs/gulp/blob/master/docs/API.md#async-task-support

:

gulp.task('name', function () {
  gulp.src(glob)
    .pipe(stuff());
});

:

gulp.task('name', function () {
  return gulp.src(glob)
    .pipe(stuff());
});

, less emberate

+2

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


All Articles