Grunt Simple Version
Easily update the version across your project. By default this updates the version field in package.json. Uses Semantic Versioning format.
Sample Gruntfile.js below. The version can take an optional map of file names as the options for files to update (other than package.json). For updating JSON files, the value is the name of the field to change. For instance, in this example bower.json has a field called
Tasks Setup Examples
Nested-Field Update (JSON-only)
The target field property on a JSON file can also be nested using a dot-syntax style address. The example below would update a
version field on a
Cache-Busting Update (HTML-only)
Providing a value of
cache-bust to an HTML file will append any src or CSS href properties with the version number. For instance,
<script src="main.js"></script> would become
<script src="main.js?v=1.0.0"></script>. This will help invalid the browser cache for linked assets.
A replacement function can be used to replace the version in the contents of a file. The function takes two arguments, the contents of the file and the version number to update to. The function must return an update string with the contents of the file.
The target field also supports multiple options (fields, nested-fields, functions,
cache-bust) for a single file. The example below would update two fields in the JSON file with the version and do a dynamic function replacement.
Ways to set the version across the project:
# Return the current versiongrunt version:current# Set a specific versiongrunt version:1.0.0-rc# Bump the patch version e.g., 1.0.1 => 1.0.2grunt version:patch# Bump the patch version e.g., 1.2.1 => 1.3.0grunt version:minor# Bump the patch version e.g., 1.3.0 => 2.0.0grunt version:major