一个webpack插件,可以将当前git提交的哈希值写到chunk文件中
一个webpack插件,可以将当前git提交的哈希值写到chunk文件中
JavaScript 构建工具
共8Star
详细介绍
webpack-git-version-plugin
Write the hash value of the current commit of the code to the js and css chunk file.
Why
After an online problem occurs in the current project, we need to know the version of the problem code and whether the problem is caused by the cache not being refreshed. Writing the hash value of the current git commit to the file can help us analyze these situations.
Getting Started
To begin, you'll need to install webpack-git-version-plugin
:
$ npm install webpack-git-version-plugin --save-dev
Then add the plugin to your webpack
config. For example:
webpack.config.js
const GitVersionPlugin = require('webpack-git-version-plugin');
module.exports = {
plugins: [new GitVersionPlugin()],
};
Example chunk files
JS file:
CSS file:
Options
processor
Type: function
Default: null
Function for processing git hash value, which can be used to add prefix or encryption to the output value.
webpack.config.js
const GitVersionPlugin = require('webpack-git-version-plugin');
module.exports = {
plugins: [
new GitVersionPlugin({
processor: (hashData) =>
`Git Version: ${Buffer.from(hashData).toString('base64')}`,
}),
],
};
The generated chunk file:
-
73 Star
-
80 Star
-
2523 Star
-
0 Star
-
669 Star
-
15 Star
-
0 Star
-
208 Star