FullHuman / purgecss-docs

Content of purgecss documentation
https://v1.purgecss.com
114 stars 44 forks source link

How to suppress output in terminal? #5

Closed lunelson closed 6 years ago

lunelson commented 6 years ago

I'm using the CLI tool via an NPM script, and a configuration file. There's a huge amount of output in the terminal which causes me to lose my place WRT other output. How do I suppress it?

jsnanigans commented 6 years ago

what is it logging to your terminal?

lunelson commented 6 years ago

It logs the entire purged CSS!

jsnanigans commented 6 years ago

That should not happen by default, can I see your NPM script?

lunelson commented 6 years ago

The the following line under scripts in package.json is calling the purgecss CLI:

"build:purge": "purgecss --c purgecss.config.js",

The purgecss.config.js file is this:

module.exports = {
  content: ['out/**/*.html'],
  css: ['out/app.css'],
  fontFace: true
};

And when I run the script, after the first build step is done, it outputs this (minus a few thousand lines):

> purgecss --c purgecss.config.js

[ { file: 'out/app.css',
    css: '@font-face{font-family:DIN;src:url(/assets/fonts/FFDinPro/1448138/aca1d56d-ac12-
---a few thousand lines removed---
a{margin-left:1rem}' } ]
jsnanigans commented 6 years ago

This is just running purgecss and that is what purgecss returns, Im guessing you would like to save the output to a new file?

anyway it would be easier to use just have a JS file like this:

// purgeScript.js
var Purgecss = require('purgecss')
var fs = require('fs')

var purgecss = new Purgecss({
  content: ['out/**/*.html'],
  css: ['out/app.css'],
  fontFace: true
})
var purgecssResult = purgecss.purge()

fs.writeFile('out/app.purged.css', purgecssResult[0].css, function(err) {
    if(err) {
        return console.log(err);
    }

    console.log("The file was saved!");
}); 

and then just run it like this:

node purgeScript.js
lunelson commented 6 years ago

šŸ˜… Aha so I sort of misunderstood how it worked thenā€”I thought the CLI would just purge the target file(s) and write it/them back to diskā€”is there a more generic way to just say "here's a folder of .html files and .css files, please purge the CSS in accordance with the content of the HTML"?

jsnanigans commented 6 years ago

Just with the CLI that is not really possible at the moment, but its long overdue to improve the CLI to be able to do this. If you'd like to, please create an Issue on the main repo for purgecss so that we don't forget about it. Let me know if you are having any other problems with purgecss šŸ‘