Giter Club home page Giter Club logo

Comments (15)

codekirei avatar codekirei commented on July 30, 2024

@tingGui

The default output of rev.manifest() is rev-manifest.json, so your rename() is unnecessary. Probably not the source of the issue, but still ;)

I'm not super familiar with RequireJS, but I'm thinking it might be acting up because of the way it's generating the source. Try using gulp-buffer as mentioned in the readme.

from gulp-rev.

bobthecow avatar bobthecow commented on July 30, 2024

It's (likely) not the bufferness, but that rjs doesn't emit a vinyl file, it just emits a buffer or stream. To get the stream turned into a vinyl file, use vinyl-source-stream:

var source = require('vinyl-source-stream');

gulp.task('rjs', function() {
  rjs({
    baseUrl: basePath,
    mainConfigFile: basePath + 'build.js',
    removeCombined: true,
    name: 'rjs.build.main',
    out: 'libs.min.js'
  })
    .pipe(source(basePath + 'libs.min.js'))
    .pipe(uglify())
    .pipe(rev())
    .pipe(gulp.dest('web/static/compiled/scripts'))
    .pipe(rev.manifest())
    .pipe(rename('rev-manifest.json'))
    .pipe(gulp.dest('web/static/compiled'));
});

from gulp-rev.

codekirei avatar codekirei commented on July 30, 2024

@bobthecow My bad. That makes more sense.

Slight tangent: according to its readme, vinyl-source-stream works well with browserify, too--is there an advantage to using gulp-buffer instead, as shown in the gulp-rev readme? If not and vinyl-source-stream covers a broader use-case, would it make sense to swap out the suggestion in the readme? I understand that both plugins do different things, but functionally they seem to overlap somewhat.

Would be happy to submit a PR if you think it's a good direction.

from gulp-rev.

bobthecow avatar bobthecow commented on July 30, 2024

gulp-buffer is only intended to transform something from a stream into a buffer. If you have a vinyl file already, and it's a stream, you'll need gulp-buffer in order to use it with gulp-rev. That said, mentioning vinyl-source-stream in conjunction with browserify and rjs would prolly be a good idea.

from gulp-rev.

tingGui avatar tingGui commented on July 30, 2024

I have used vinyl-source-stream before rev(),but it throws an errorStreaming not supported.

from gulp-rev.

bobthecow avatar bobthecow commented on July 30, 2024

Then you need buffer too

from gulp-rev.

tingGui avatar tingGui commented on July 30, 2024

Then used buffer() beforerev(),it also throws an error TypeError: Invalid non-string/buffer chunk.

from gulp-rev.

codekirei avatar codekirei commented on July 30, 2024

What order are you using buffer() and source() in? Try switching them.

from gulp-rev.

tingGui avatar tingGui commented on July 30, 2024

Switching them ,it also does not work.

gulp.task('rjs', function() {
  rjs({
    baseUrl: basePath,
    mainConfigFile: basePath + 'build.js',
    removeCombined: true,
    name: 'rjs.build.main',
    out: 'libs.min.js'
  })
    .pipe(source(basePath + 'libs.min.js'))
    .pipe(buffer())
    .pipe(uglify())
    .pipe(rev())
    .pipe(gulp.dest('web/static/compiled/scripts'))
    .pipe(rev.manifest())
    .pipe(rename('rev-manifest.json'))
    .pipe(gulp.dest('web/static/compiled'));
});

from gulp-rev.

bobthecow avatar bobthecow commented on July 30, 2024

Can you point us to a repo or test case so we can reproduce this?

from gulp-rev.

codekirei avatar codekirei commented on July 30, 2024

@tingGui This may not help, but here's another approach you could take--instead of trying to squish the rjs() output directly into a .pipe() with source() and/or buffer(), which seem to be giving you issues, you could just make another task. rjs() outputs libs.min.js to the filesystem, right? So you can just consume it with gulp.src() in a follow-up task and do whatever you want with it.

Of course, you'll need to make rjs() async so the follow-up task will wait for it to finish before consuming the output. Also, if you don't want that libs.min.js hanging around, you can delete it after you're done consuming it.

While it's admittedly somewhat hackish, I've cobbled together an example gulpfile.js that will hopefully illustrate the approach. It does the following:

  1. Create an array of source javascript files (I believe requirejs include: needs its source in an array)
  2. Concat and optimize with requirejs
  3. Consume the requirejs output in a follow-up task
  4. Delete original requirejs output
// gulpfile.js
// requires
var del  = require('del');
var fs   = require('fs');
var gulp = require('gulp');
var rjs  = require('requirejs').optimize;
var path = require('path');

// settings
var jsDir    = 'src/js';
var src      = fs.readdirSync(jsDir);
var dest     = 'dist';
var tempDir  = 'temp';
var tempFile = 'lib.js';
var rjsOut   = path.join(tempDir, tempFile);
var config   = {
    baseUrl: jsDir,
    include: src,
    out: rjsOut
};

// tasks
gulp.task('rjs1', function(cb){
    rjs(config, function(buildResponse){
        cb();
    }, cb);
});
gulp.task('rjs2', ['rjs1'], function(){
    return gulp.src(rjsOut)
        // do whatver here, e.g. rev(), uglify(), etc.
        .pipe(gulp.dest(dest));
});
gulp.task('rjs3', ['rjs2'], function(cb){
    del([tempDir],
    cb);
});
gulp.task('rjs', ['rjs1', 'rjs2', 'rjs3']);

Got some help with the callback structure here and here.

from gulp-rev.

codekirei avatar codekirei commented on July 30, 2024

Now that I think about it, I suppose one hiccup in that example is if there are so many js files that rjs1 starts before fs.readdirSync(jsDir) is done building the src array. So it would probably be safer to make a fourth rjs task that builds src using fs.readdir() instead, so it's async. The current rjs1 would then become rjs2 and depend on the new rjs1, and so on.

from gulp-rev.

tingGui avatar tingGui commented on July 30, 2024

Thank you for your help, I have found the reason is gulp-requirejs plugin, caused by the author of gulp-requirejs has fixed the async task support issue ,but not update the npm version.

from gulp-rev.

sindresorhus avatar sindresorhus commented on July 30, 2024

Try out 3.0.0. Note the API has changed. See #77.

from gulp-rev.

yangnuowei88 avatar yangnuowei88 commented on July 30, 2024

how to dell thiw ask? please tell me how

from gulp-rev.

Related Issues (20)

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.