npm install --save-dev webpack-version-file-plugin
webpack.config.js
const VersionFilePlugin = require('webpack-version-file-plugin');
module.exports = {
// ...
plugins: [new VersionFilePlugin()],
};
默认会生成一个 version.json 的文件,内容如下:
{
"hash": "3c84397d21aef9fe86528a5b12a8bbbe"
}
// webpack.config.js
module.exports = {
// ...
plugins: [
new VersionFilePlugin({
filePath: 'version.json',
serialize: function (json) {
return JSON.stringify(json, null, 2);
},
}),
],
};
Type: String
Default: version.json
生成文件路径
Type: Function(Object): string
Default: (json) => JSON.stringify(json, null, 2)
文件内容序列化方法