All Projects → SkeLLLa → gulp-version-append

SkeLLLa / gulp-version-append

Licence: MIT license
Gulp plugin to append version from package.json to static file url to avoid caching

Programming Languages

javascript
184084 projects - #8 most used programming language
HTML
75241 projects

Projects that are alternatives of or similar to gulp-version-append

gulp-append-prepend
➕ Simple Gulp plugin to append/prepend.
Stars: ✭ 15 (-16.67%)
Mutual labels:  gulp, gulp-plugins
gulp-webdriver
gulp-webdriver is a gulp plugin to run selenium tests with the WebdriverIO testrunner
Stars: ✭ 77 (+327.78%)
Mutual labels:  gulp, gulp-plugins
beginner-windows-npm-gulp-webdev-tutorial
Beginner guide for users on web development with node.js/npm + gulp terminal commands. You'll learn how to use other terminal commands like git, gulp, bower, yarn, and more!
Stars: ✭ 40 (+122.22%)
Mutual labels:  gulp, gulp-plugins
gulp-iife
A Gulp plugin for wrapping JavaScript code in IIFEs.
Stars: ✭ 39 (+116.67%)
Mutual labels:  gulp, gulp-plugins
gulp-spsync
Gulp plugin for synchronizing local files with a SharePoint library
Stars: ✭ 57 (+216.67%)
Mutual labels:  gulp, gulp-plugins
gulp-px2rem
This is a gulp plugin for node-px2rem.
Stars: ✭ 19 (+5.56%)
Mutual labels:  gulp
campus-leaflets
校园传单是一个使用 Node.js、MongoDB、Koa、EJS、MDL、Less、RequireJS 和 Gulp 开发的 Node 应用程序。
Stars: ✭ 16 (-11.11%)
Mutual labels:  gulp
UpGulp
A Gulp Starter for your WordPress project
Stars: ✭ 29 (+61.11%)
Mutual labels:  gulp
gulp-cordova
[UNMAINTAINED] Very simple plugin to run cordova commands with a simple interface from gulp
Stars: ✭ 23 (+27.78%)
Mutual labels:  gulp
code-line-daily
A line of code of the day.
Stars: ✭ 17 (-5.56%)
Mutual labels:  gulp
dockervel
Laravel development environment in Docker containers
Stars: ✭ 30 (+66.67%)
Mutual labels:  gulp
bymattlee-11ty-starter
A starter boilerplate powered by 11ty, Sanity, Gulp, Tailwind CSS, rollup.js, Alpine.js and Highway.
Stars: ✭ 27 (+50%)
Mutual labels:  gulp
gulp-shopify-theme
Shopify theme synchronisation during development
Stars: ✭ 26 (+44.44%)
Mutual labels:  gulp
WP-Gulp-Starter
A starter kit for developing WordPress themes and plugins with Gulp workflow.
Stars: ✭ 26 (+44.44%)
Mutual labels:  gulp
Prometheus
🌈 A Clean And Modern Ghost Theme with Progressive Web Apps (PWA)
Stars: ✭ 94 (+422.22%)
Mutual labels:  gulp
jekyll-gulpified
Jekyll Gulpified. Optimize assets, fire up Browser Sync, deploy, and more.
Stars: ✭ 20 (+11.11%)
Mutual labels:  gulp
queiroz.js
JavaScript Extension for Dimep Kairos
Stars: ✭ 47 (+161.11%)
Mutual labels:  gulp
animecenter
The source code for animecenter
Stars: ✭ 16 (-11.11%)
Mutual labels:  gulp
gulp-pug-inheritance
Only build affected files when modify a Pug file.
Stars: ✭ 16 (-11.11%)
Mutual labels:  gulp
web-starter-kit-gulp
Starter kit for automated front-end web development using Gulp, NPM, Bower, Babel, Sass, and Pug.
Stars: ✭ 35 (+94.44%)
Mutual labels:  gulp

gulp-version-append

npm version Dependency Status

Gulp plugin to append version from package.json to static file url to avoid caching.

Pre-requirements

Have package.json file in your project root folder with version field.

Usage

In gulp task:

var versionAppend = require('gulp-version-append');

...
.pipe(versionAppend(extensionsArray[, options]))
...

extensionsArray - is an array of extensions that require version to be appended, e.g. ['html', 'js', 'css'] options - optional config object for custom params. options.versionFile - path to json file that contains version in case you're need to use different file instead of package.json (path should be relative to application root folder) options.appendType - override appending version with timestamp or short "guid" based on date (actually it's a date that counted from the beginning of current year in HEX). Possible values 'version','timestamp','guid', defaults to 'version'

In html code:

<script src="https://github.com/js/scriptname.js?v=@version@"></script>

package.json:

{
  "name": "my-app",
  "version": "0.0.1"
}

result:

<script src="https://github.com/js/scriptname.js?v=0.0.1"></script>

Example

var gulp = require('gulp'),
	$ = require('gulp-load-plugins')(),
	path = require('path');

gulp.task('html', function(){
    return gulp.src(path.join(__dirname, '*.html'))
		  .pipe($.versionAppend(['html', 'js', 'css']))
		  .pipe($.minifyHtml());
});
/// version.json:
{
	"version": "0.0.1"
}

/// gulpfile.js: 
var gulp = require('gulp'),
	$ = require('gulp-load-plugins')(),
	path = require('path');

gulp.task('html', function(){
    return gulp.src(path.join(__dirname, '*.html'))
		  .pipe($.versionAppend(['html', 'js', 'css'], {appendType: 'guid', versionFile: 'version.json'}))
		  .pipe($.minifyHtml());
});

Thanks

Many thanks to @bustardcelly and his gulp-rev-append (https://github.com/bustardcelly/gulp-rev-append/) plugin that was taken as an example for this plugin.

Another plugin? Why?

  • gulp-rev-append plugin is very good and in some cases even better, because it relies on file hash, so if file didn't changed between versions, the hash will remain the same so file can stay in cache. But in my case all files are concatenated to sevral files, so changing one file will cause change in big file. So in 95% cases file will change on version update. That's why I've wrote this plugin, which is slightly faster than gulp-rev-append because it not read files and not calculates their hash.
  • gulp-css-urlversion and it's analogues are limited to one static file type, but I need one unified plugin that could append version everywhere: in html, js, css, etc.
  • gulp-ver - very good plugin, but it rename files instead of appending query param. This is good practice in some cases, but not mine. I've tried to make my plugin simple as a pie, with minimum code modifications, renames, etc.
  • also I use angular and have a lot of stuff that needs version appending in js source code, but many plugins are limited and replace only usual url, that start with e.g. 'src=/js/myjs.js?rev='. My plugin relies only on file extensions and special "template": .<file_extension>?v=@version@.
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].