Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Inconsistent direction in using modules directly or using gulp wrappers #2027

Closed
benjaminapetersen opened this issue Oct 5, 2017 · 5 comments

Comments

@benjaminapetersen
Copy link

This is a bit new since I last setup a gulp project, but:

var browserify = require('browserify');
var gulp = require('gulp');
var source = require('vinyl-source-stream');
var buffer = require('vinyl-buffer');
var gutil = require('gulp-util');
var uglify = require('gulp-uglify');
var sourcemaps = require('gulp-sourcemaps');
var reactify = require('reactify');

Mixes & matches gulp- wrappers & plain ol' node modules. This becomes a bit problematic when altering scripts to your own use and you run into incompatibilities. For example, I'm tweaking:

const gulp = require('gulp'),
      sass = require('gulp-sass'),
      del = require('del'),
      browserify = require('browserify'),
      source = require('vinyl-source-stream'),
      uglify = require('gulp-uglify');

gulp.task('scripts', ['clean-dist'], () => {
  return browserify('src/scripts/main.js')
          .bundle()
          .pipe(source('app.js'))
          .pipe(uglify())
          .pipe(
            gulp.dest('./dist')
          );
});

And getting this kind of error:

$ gulp scripts
[11:36:51] Using gulpfile ~/Dropbox/Development/github/lunch-and-learn-js/projects/gulp-yarn/gulpfile.js
[11:36:51] Starting 'clean-dist'...
[11:36:51] Finished 'clean-dist' after 5.15 ms
[11:36:51] Starting 'scripts'...

events.js:160
      throw er; // Unhandled 'error' event
      ^
GulpUglifyError: Streaming not supported
    at createError (~/projects/gulp-yarn/node_modules/gulp-uglify/lib/create-error.js:6:14)
    at apply (~/projects/gulp-yarn/node_modules/lodash/_apply.js:16:25)
    at wrapper (~/projects/gulp-yarn/node_modules/lodash/_createCurry.js:41:12)
    at ~/projects/gulp-yarn/node_modules/gulp-uglify/lib/minify.js:32:15
    at DestroyableTransform._transform (~/projects/gulp-yarn/node_modules/gulp-uglify/composer.js:10:23)
    at DestroyableTransform.Transform._read (~/projects/gulp-yarn/node_modules/readable-stream/lib/_stream_transform.js:182:10)
    at DestroyableTransform.Transform._write (~/projects/gulp-yarn/node_modules/readable-stream/lib/_stream_transform.js:170:83)
    at doWrite (~/projects/gulp-yarn/node_modules/readable-stream/lib/_stream_writable.js:406:64)
    at writeOrBuffer (~/projects/gulp-yarn/node_modules/readable-stream/lib/_stream_writable.js:395:5)
    at DestroyableTransform.Writable.write (~/projects/gulp-yarn/node_modules/readable-stream/lib/_stream_writable.js:322:11)

Being confused, I swap gulp-uglify for just uglify and get a different error:

const gulp = require('gulp'),
      sass = require('gulp-sass'),
      del = require('del'),
      browserify = require('browserify'),
      source = require('vinyl-source-stream'),
      uglify = require('uglify');

// but use the same task, uglify requirement is the only change

I did do:

yarn add uglify -dev

before running gulp scripts, which gives me a different error:

$ gulp scripts
module.js:471
    throw err;
    ^

Error: Cannot find module 'uglify'
    at Function.Module._resolveFilename (module.js:469:15)
    at Function.Module._load (module.js:417:25)
    at Module.require (module.js:497:17)
    at require (internal/module.js:20:19)
    at Object.<anonymous> (~/projects/gulp-yarn/gulpfile.js:7:16)
    at Module._compile (module.js:570:32)
    at Object.Module._extensions..js (module.js:579:10)
    at Module.load (module.js:487:32)
    at tryModuleLoad (module.js:446:12)
    at Function.Module._load (module.js:438:3)

Similar to the other issue I just created, #2026, errors are much less friendly than they used to be. Is it preferable to use modules directly? To use the wrappers? Its not clear why the example with the .pipe to the source map plugin would work but when I drop that and just .pipe to uglify I get errors.

Thanks!

@phated
Copy link
Member

phated commented Oct 6, 2017

The errors have not changed. This is a deficiency in nodejs streams. I'll address your other issue separately because there's something we can improve there.

P.S. - You need to research your modules more thoroughly before installing because uglify is not the module you are looking for.

@phated phated closed this as completed Oct 6, 2017
@benjaminapetersen
Copy link
Author

Thanks, I tried a couple uglify options before posting this.

This issue is more about consistency with using wrappers, or not, however. This is open mostly for doc purposes. It seems like there is encouragement to just use the node modules themselves, but the recipes definitely mix-and-match, so its not quite clear.

@phated
Copy link
Member

phated commented Oct 9, 2017

Recipes are made to be used verbatim. They are a starting point for people that want to copy-paste. I get the sense that you are much further down the learning path if you are trying to be minimalist and should probably dig into some blog posts about node streams.

That being said, I think what you're asking about would make for a good Sip (bite-sized blog posts on advanced topics) so I've opened an issue at gulpjs/gulpjs.github.io#145

@benjaminapetersen
Copy link
Author

Sounds good! Yeah, I'm coming back to gulp after a long while away in a grunt based project (oi), still refreshing, even if I'm rusty.

@phated
Copy link
Member

phated commented Oct 31, 2017

Thanks for the idea, @janiceilene has written the Sip for this at https://medium.com/gulpjs/gulp-sips-how-we-use-streams-d7790b22bf1a

@gulpjs gulpjs locked and limited conversation to collaborators Oct 31, 2017
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants