Only write the user themes file if the map has been changed. This fixes the issue where watcher being triple triggered on cold starts.

This commit is contained in:
Sercan Yemen 2022-11-08 12:47:38 +03:00
parent c88d30a4f4
commit 646b084a12

View File

@ -96,14 +96,32 @@ const theming = plugin.withOptions((options) => ({
/* Generate the SASS map using the themes object */ /* Generate the SASS map using the themes object */
const sassMap = jsonToSassMap(JSON.stringify({'user-themes': themes})); const sassMap = jsonToSassMap(JSON.stringify({'user-themes': themes}));
/* Write the SASS map to the file */ /* Get the file path */
fs.writeFile(path.resolve(__dirname, ('../../styles/user-themes.scss')), sassMap, (err) => const filename = path.resolve(__dirname, ('../../styles/user-themes.scss'));
/* Read the file and get its data */
let data;
try
{ {
if ( err ) data = fs.readFileSync(filename, {encoding: 'utf8'});
}
catch ( err )
{
console.error(err);
}
/* Write the file if the map has been changed */
if ( data !== sassMap )
{
try
{ {
return console.log(err); fs.writeFileSync(filename, sassMap, {encoding: 'utf8'});
} }
}); catch ( err )
{
console.error(err);
}
}
/** /**
* Iterate through the user's themes and build Tailwind components containing * Iterate through the user's themes and build Tailwind components containing