I previously saved the [hash] value of webpack to a meta.json file:
class MetaInfoPlugin {
constructor(options) {
this.options = { filename: 'meta.json', ...options };
}
apply(compiler) {
compiler.hooks.done.tap(this.constructor.name, (stats) => {
const metaInfo = {
// add any other information if necessary
hash: stats.hash
};
const json = JSON.stringify(metaInfo);
return new Promise((resolve, reject) => {
fs.writeFile(this.options.filename, json, 'utf8', (error) => {
if (error) {
reject(error);
return;
}
resolve();
});
});
});
}
}
module.exports = {
mode: 'production',
target: 'web',
...
plugins: [
new MetaInfoPlugin({ filename: './public/theme/assets/scripts/meta.json' }),
],
...
};
After upgrading to webpack 5 I receive deprecation notices that point to using contenthash or other values instead.
[DEP_WEBPACK_TEMPLATE_PATH_PLUGIN_REPLACE_PATH_VARIABLES_HASH] DeprecationWarning: [hash] is now [fullhash] (also consider using [chunkhash] or [contenthash], see documentation for details)
But exchanging the .hash
part above with .contenthash
or any of the other hashes won't work. How do I save the contenthash to a file so I can later on use the value in a templating system to so link the file?
What I am basically trying is to get the [contenthash]
value into a text file (json, whatever format) to reuse in a PHP templating system later on.