Comments (15)
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.
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.
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.
Isn't directory order in node.js nondeterministic?
from gulp-rev.
@bobthecow I believe so, for concurrency/asynchronicity.
But you lost me on why that's significant here :)
from gulp-rev.
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.
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.
@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.
@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.
@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.
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.
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.
One of those two sounds good :P
from gulp-rev.
@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.js
but 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.
@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)
- Manifest.json not produced on multiple level folders
- support ignore CR and CRLF? HOT 1
- rev.manifest() TypeError: file.isSymbolic is not a function
- Sourcemap (.map) files get revisioned with different hash HOT 3
- rev.manifest() crashes due to Buffer.from usage HOT 3
- “gulp-rename-rev” is used by your main code. HOT 2
- gulp rev adds hash to image twice HOT 2
- Old revisions strategy HOT 14
- Hash placed in wrong location on file name when multiple periods in name HOT 3
- Original path as manifest key, new path as value?
- Manifest only shows one line when I generate many taks HOT 1
- Issue in rev-manifest.json file path HOT 4
- Not using the latest css as source
- Not creating manifest correctly HOT 7
- why the source has changed, but the hash no change? HOT 4
- Help - Generating manifest
- not work with gulp watch HOT 1
- help manifest format
- Parallel Tasks Overwriting Manfiest File
- The corresponding image path string does not exist in the css file, what should I do? HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from gulp-rev.