简体   繁体   中英

how to change the version of the project in grunt but from the changes of the files in my project

In a web project with grunt, how to configure my gruntfile.js for when it run, apply the version of my cache item in the index.html and heading of the .js and .css from the changes it has in this version. for example:

i probably have:

... js/last.js, js/new.js ...

i run and i want get:

js/lastAndNew.js <- version 0.0.2

but when probably i have: ... js/last.js, js/new1.js, js/new2.js, js/new3.js, js/new4.js, js/new5.js ...

i want get, for example:

js/lastAndAllNews.js --> version 0.1.0 (or maybe 1.0.0 i dont know how works really)

for grunt change automatically the versions on my project, what i do in the gruntfile.js code?

only i get with bump, change 1 by 1 the number of the version. with one easy configuration.

I usually do something like this in my grunt file..

Put this at the top of the grunt file to read the version from the package.json which reads the version into a variable, increments it, then updates the package.json. If you don't want to increment the version on every build just use the first line.

var pkg = grunt.file.readJSON('package.json');
pkg.version = pkg.version.split(".");
var subversion = pkg.version.pop();
subversion++;
pkg.version.push(subversion);
pkg.version = pkg.version.join(".");
grunt.file.write('package.json', JSON.stringify(pkg, null, 2));

Then you can use that to define your headers and footers using your preferred tasks.

Here's an example of one of my grunt files that does this.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM