Giter Club home page Giter Club logo

Comments (15)

codekirei avatar codekirei commented on July 30, 2024

First, if you fence code blocks with ```, it will come out

nicely formatted.

Makes things easier to read, which is helpful. Full breakdown here.

As for your question, could you clarify a bit?

Are you changing a .js file in web/static/allLib/scripts/, running your task, and then app-hash.js is given a new hash to indicate an update, but the contents of app-hash.js haven't changed to match the updated source?

from gulp-rev.

tingGui avatar tingGui commented on July 30, 2024

Thank you for the advice.
File in web/static/allLib/scripts/are not changed. but runing task again,the app-hash.js has been given a new hash.

from gulp-rev.

codekirei avatar codekirei commented on July 30, 2024

You're welcome!

I'm having trouble reproducing this issue though. I recreated the gulp.task as you indicated, and I can run it multiple times without app-hash.js ever changing hashes. Are you absolutely certain you aren't touching anything in web/static/allLib/scripts/ with other tasks?

Since an isolated task isn't repro'ing, I'm thinking the culprit is most likely a conflict/interaction with something else in your gulpfile.js.

Code I used:

var gulp   = require('gulp');
var concat = require('gulp-concat');
var rename = require('gulp-rename');
var uglify = require('gulp-uglify');
var rev    = require('gulp-rev');

gulp.task('default', function(){
    return gulp.src('web/static/allLib/scripts/**/*.js')
        .pipe(concat('app.js'))
        .pipe(rename({
            suffix: '.min'
        }))
        .pipe(uglify({
            mangle: false,
            outSourceMap: false
        }))
        .pipe(rev())
        .pipe(gulp.dest('web/static/compiled/scripts'))
        .pipe(rev.manifest())
        .pipe(rename('revd-manifest.json'))
        .pipe(gulp.dest('web/static/rev'));
});

Folder structure after running gulp:

.
├── gulpfile.js
└── web
    └── static
        ├── allLib
        │   └── scripts
        │       ├── script1.js
        │       └── script2.js
        ├── compiled
        │   └── scripts
        │       └── app.min-8ca000ac.js
        └── rev
            └── revd-manifest.json

from gulp-rev.

bobthecow avatar bobthecow commented on July 30, 2024

Isn't directory order in node.js nondeterministic?

from gulp-rev.

codekirei avatar codekirei commented on July 30, 2024

@bobthecow I believe so, for concurrency/asynchronicity.

But you lost me on why that's significant here :)

from gulp-rev.

bobthecow avatar bobthecow commented on July 30, 2024

Because that gulp task is reading an entire directory, concatenating the contents together, then hashing the resulting file. If the files don't concatenate in the same order every time, the hash will be different every time.

from gulp-rev.

codekirei avatar codekirei commented on July 30, 2024

Brilliant, that makes perfect sense. In a real project with larger/more files, the odds of the src glob reading in a different order would be significantly increased, too.

So to fix, probably either test for changes pre-concat and trigger rev() based on that, or force a deterministic read?

Throwing gulp-newer in the first .pipe() might be an easy solution here. If anything in the src glob is newer than the target concatted file, the task runs as usual. If not, no source gets passed through so no unintended rev() occurs.

from gulp-rev.

tingGui avatar tingGui commented on July 30, 2024

@bobthecow You are right,the files don't concatenate in the same order every time, so the hash different every time.
Could you give me a solution to keep files in the same order every time?

from gulp-rev.

tingGui avatar tingGui commented on July 30, 2024

@codekirei I have tested gulp-newer in the first .pipe(),but it doesn't work.Do you have a better solution for this?

from gulp-rev.

bobthecow avatar bobthecow commented on July 30, 2024

@tingGui That seems like something you should ask the authors of gulp-concat about. Maybe an option for that to suck in the entire stream and sort it before concatenation?

from gulp-rev.

codekirei avatar codekirei commented on July 30, 2024

Yeah, another option is to circumvent the nondeterministic read using something like fs.readFileSync. You could populate an array with the files in 'web/static/allLib/scripts/, sort that array, then pass the sorted array to a task as src. That way, you can be sure you're getting your files in the same order every time.

If the order of your .js is inherently significant other than needing to be consistent, you'd have to account for that in your sort.

That's the nice thing about gulp--it's just javascript :)

from gulp-rev.

codekirei avatar codekirei commented on July 30, 2024

After a quick poke around npm, sort-stream or gulp-natural-sort might take care of this if you don't want to write it yourself. I haven't tried either before, so ymmv.

from gulp-rev.

bobthecow avatar bobthecow commented on July 30, 2024

One of those two sounds good :P

from gulp-rev.

tingGui avatar tingGui commented on July 30, 2024

@codekirei Thanks a lot ,gulp-natural-sort has solved my issue.
But I have encountered another problem , below is my code ,why it generates libs.min-3e314329.jsbut not generates rev-manifest.json?

gulp.task('rjs', function() {
  rjs({
    baseUrl: basePath,
    mainConfigFile: basePath + 'build.js',
    removeCombined: true,
    name: 'rjs.build.main',
    out: '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

@tingGui Great!

Since it appears that your original problem has been solved and we're discussing a new, unrelated problem, I'm closing this and opening a new issue here: #61.

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.