steelydylan / gulp-generator

Easy gulp generator for web
http://steelydylan.github.io/gulp-generator/
135 stars 18 forks source link

Can't pipe to undefined #11

Open robbiemu opened 7 years ago

robbiemu commented 7 years ago

I'm trying to use this with the browserSync options, Im not sure if I am doing something wrong. I .. guess I must be. Honestly, this is not entirely a vanilla generated file — I edited it to added scss and sass extensions, and to use the root directory of dev as well as a subdirectory for sources for html. The complete gulpfile is at this gist. I get

[15:55:47] Starting 'html'...
[BS] Reloading Browsers...
[15:55:47] 'html' errored after 11 ms
[15:55:47] Error in plugin 'plumber'
Message:
    Can't pipe to undefined

I read that you can wrap the reload function is an outer function to call it, or pass {stream: true} I think it was, but these either failed or caused it to trigger that message over and over again.

My project structure is:

./build - build testing output directory/page root ./dev - source files

generated browseSync in default task:

    browserSync.init({
        server: "./build"
    });

I can see all my code is generated in build: the index.html is sitting right where it should at './build/index.html'... The browser fires up automatically. — but to a blank page that just says "Cannot GET /" (changing the url to point specifically to /index.html or /build/index.html also doesn't work).

The logs though, look like it should work just fine.

[15:36:48] Requiring external module babel-register
[15:36:49] Using gulpfile ~\OneDrive\Público\projects\Overwatch\gulpfile.babel.js
[15:36:49] Starting 'default'...
[15:36:53] Finished 'default' after 3.11 s
[BS] Access URLs:
 ------------------------------------
       Local: http://localhost:3000
    External: http://192.168.1.9:3000
 ------------------------------------
          UI: http://localhost:3001
 UI External: http://192.168.1.9:3001
 ------------------------------------
[BS] Serving files from: ./build

I also notice that you don't generate a hashcode for the configuration options that were chosen, so you can't recreate the initial file easily. You might consider adding that for your own benefit. ☺

robbiemu commented 7 years ago

So I got it working this morning.

Things I did.

  1. (unnecessary but you might consider ading this as a feature option): added gulp clean and made it part of default cycle:
var clean = require('gulp-clean');

gulp.task('clean', function () {
    return gulp.src('build/*', {read: false})
        .pipe(clean());
})
  1. (also unnecessary) Reset the build directory each cycle (otherwise repeated executions of gulp default won't rebuild build directory:
gulp.task('default', function () {
    gulp.start('clean', 'html', 'templates', 'css', 'sass', 'scripts')

Those two are unnecessary but it made it easy to see why it wasn't working.

  1. change all calls to browsersync's reload() to: reload({stream:true})

What I didn't do: follow the advise elsewhere in this issue tracker from a third party to change the server init. It works fine just like it is.

The gist I posted has a final version posted now, so you can see the changes all in one place.

steelydylan commented 7 years ago

Thank you for finding the bug and suggesting how to fix that I'll change all reload() to reload({stream:true}) first and after that, maybe I'll think of making task clean as you suggested https://gist.github.com/robbiemu/5deda56a87047e4348a45920fa48c1bd

And you can change the source code and make pull request, if you want. Actually it's really easy to change, maybe you can fix the problem only by updating index.html without rewriting some js codes. cuz, gulp-generator has been created by template engine called "aTemplate"