sindresorhus / gulp-rev

Static asset revisioning by appending content hash to filenames: `unicorn.css` → `unicorn-d41d8cd98f.css`
MIT License
1.54k stars 218 forks source link

Question: How to use gulp-rev & gulp-rev-replace with custom src that does not match file name #197

Closed dragonflypl closed 7 years ago

dragonflypl commented 7 years ago

In Spring MVC application I have a set of script tags that in src attribute have a variable that drives which file version is used: <%=jsSuffix%> - it is set using application configuration settings during the runtime (long story but I think it has to stay this way):

<script src="build/js/app-vendor<%=jsSuffix%>.js "></script>
<script src="build/js/app-gom<%=jsSuffix%>.js "></script>
<script src="build/js/app<%=jsSuffix%>.js "></script>

Unfortunately gulp-rev & gulp-rev-replace does not match this syntax with physical file names (app-vendor.js and app-vendor.min.js).

Can this be achieved?

lukeed commented 7 years ago

I'm not entirely sure if I understand your question.

If you're looking to version the files, whether they're *.min.js or *.js, you would just treat them like any other gulp stream. If need be, create a new task that sources these files directly.

If you're trying to serve these files, you can get ideas from the Integration guide. Approach #3, the PHP example, would work just fine for you, but you'd have to configure your server's side of things.

Another idea: Since there's no need to version files in development, you change your script-handling to:

<%= if (isProduction) %>
  <script src="build/js/app-vendor.min.js"></script>
  <script src="build/js/app-gom.min.js"></script>
  <script src="build/js/app.min.js"></script>
<%= else %>
  <script src="build/js/app-vendor.js"></script>
  <script src="build/js/app-gom.js"></script>
  <script src="build/js/app.js"></script>
<%= end %>

And then just only include gulp-rev within your production task chain, as well as the gulp.rename modification.

dragonflypl commented 7 years ago

Thanks, that's what i needed.