2. 添加版本号
var cwd = '"' + process.cwd() + '"';
// 获取git版本
var fs = require("fs")
var gitHEAD = fs.readFileSync('.git/HEAD', 'utf-8').trim() // ref: refs/heads/develop
var ref = gitHEAD.split(': ')[1] // refs/heads/develop
var version = gitHEAD.split('/')[2] // 环境:develop
var gitVersion = fs.readFileSync('.git/' + ref, 'utf-8').trim() // git版本号,例如:6ceb0ab5059d01fd444cf4e78467cc2dd1184a66
gitVersion = gitVersion.substring(0,7);
var gitCommitVersion = '"' + version + ': ' + gitVersion + '"' // 例如dev环境: "develop: 6ceb0ab5059d01fd444cf4e78467cc2dd1184a66"
fs.writeFile("./build/version.txt", gitCommitVersion, function(err) {
if(err) {
return console.log(err);
}
console.log(" ok! File saved");
});
======
写在webpack.production.config.js