1.1.3 • Published 8 years ago
extract-hash-webpack-plugin v1.1.3
extract-hash-webpack-plugin
Extract webpack compiler hash to generate version.json file after build in the dest directory.
Options
You can pass some configuration options to ExtractHashWebpackPlugin. Allowed values are as follows:
filename: Version file name. Default toversion.json.hashLength: Substring length of compiler hash. Default to value'normal'which means the wholehashvalue itself. You can pass anumberto get a substring of it. Or pass string'full'to get value offullHash.dest: Version file save path. Default toprocess.cwd(). Will do mkdir if path doesn't exist.fn: A function to customize content format of version file to be generated. Default to return a json string of hash with the keyversion.
Example
Generate file ver.json in directory path.resolve(process.cwd(), 'prd').
import ExtractHashWebpackPlugin from 'extract-hash-webpack-plugin';
var webpackConfig = {
entry: 'main.js',
output: {
filename: '[name]-[hash:8].js',
publicPath: '/js',
},
plugins: [
new ExtractHashWebpackPlugin({
dest: 'prd',
filename: 'ver.json',
hashLength: 8,
}),
new ExtractHashWebpackPlugin({
dest: 'prd',
filename: 'ver.xml',
hashLength: 8,
fn: hash => `<xml><version>${hash}</version></xml>`
})
]
};Contents of ver.json:
{
"version": "[hash:8]"
}Contents of ver.xml:
<xml>
<version>
[hash:8]
</version>
</xml>