UNPKG

cache-buster-react

Version:

This package allows clients to automatically check the new version when a new version is released in the production environment, and if a new version is published, clearing the cache and reload the page.

23 lines (19 loc) 693 B
var _require = require('fs'), writeFile = _require.writeFile; var path = require('path'); var packageJson = require(process.cwd() + "/package.json"); var metaJson = path.join(process.cwd(), 'public', 'meta.json'); var appVersion = packageJson.version + "." + process.env.REACT_APP_CB_VERSION; var jsonData = { version: appVersion }; console.log(appVersion, process.env); var jsonContent = JSON.stringify(jsonData); writeFile(metaJson, jsonContent, 'utf8', function (err) { if (err) { console.error('An error occurred while writing JSON Object to meta.json'); throw console.error(err); } else { console.log("meta.json file has been saved with v" + appVersion); } });