Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New PR for Unused CSS #1898

Open
wants to merge 14 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ id: f970dc8a-137e-49cc-a53e-362a924bf726
name: aws-k8s-cni.yaml
relationships: []
schemaVersion: designs.meshery.io/v1beta1
version: 0.0.47
version: 0.0.47
31 changes: 31 additions & 0 deletions check-unused-css.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
// Script for the checking of unused css

const { exec } = require('child_process');
const path = require('path');

// Get the CSS file name from the command line arguments
const cssFileName = process.argv[2];

if (!cssFileName) {
console.error('Error: Please provide a CSS file name as an argument.');
process.exit(1);
}

// Construct the command to run PostCSS with PurgeCSS
const postcssCommand = `npx postcss ${path.join('_sass', cssFileName)} -o ./output/${cssFileName} --config ./postcss.config.js`;

exec(postcssCommand, (error, stdout, stderr) => {
if (error) {
console.error(`Error: ${error.message}`);
return;
}
if (stderr) {
console.error(`Error: ${stderr}`);
return;
}

// If no errors, print a success message with more details
console.log(`Success: The file '${cssFileName}' was processed successfully.`);
console.log(`The output has been saved to './output/${cssFileName}'`);
console.log(`NOTE: ALL THE UNUSED CSS IS REMOVED FROM THE UPDATED FILE`);
});
27 changes: 27 additions & 0 deletions postcss.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
const purgecss = require('@fullhuman/postcss-purgecss');

module.exports = {
syntax: require('postcss-scss'),
plugins: [
purgecss({
content: [
// Change the path to match your HTML files in which you want to check unused css i'm checking all files at once
'./**/*.html',
// same for the js, i am checking all js files at once
'./**/*.js',
],
// First change the below code and then add the file name you want.
// For e.g. i checked it using variables.scss
css: ['./_sass/testimonials.scss'],
// and run this in terminal ->

// npx postcss _sass/variables.scss -o ./output/variables.css --config ./postcss.config.js

// change the variables to the file you want to check
safelist: [], // Add any CSS selectors you want to keep
keyframes: true,
fontFace: true,
// adding this line to for commiting with sign off
}),
],
};
Loading