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

css-purge always minifies, no matter which trim option is enabled #26

Closed
COLABORATI opened this issue May 12, 2018 · 6 comments
Closed
Labels

Comments

@COLABORATI
Copy link

I tried all combinations of the trim options, no matter what I do, the resulting file is always minified - I do not want that to happen, as I still would like to edit the resulting files sometimes, but the options that look like should be used to disable that (trimming of whitespace and newline chars) do not seem to work at all.

@AndrewEQ
Copy link
Contributor

Hi there @COLABORATI, can you describe your setup to me? Are you using it via a plugin or as a library, or local or global command line?

@christophervoigt
Copy link

christophervoigt commented Jul 19, 2018

I think I can reproduce this issue.

In my setup I'm using node-sass to compile scss files to css. Since I'm optimizing for http2 I'm creating bundles for every module on the page.
However, as a fallback I had to create a bundle that includes all code and just imported every single module bundle.
In my case bootstrap gets included several times, but if I just use the node-sass outputStyle compressed, it blews up my bundle like hell. So I found css-purge to be a very good solution.

Here is my setup:

sass.render({
    // ... sass options
}, (error, result) => {
    if (error) { console.log(error) } else {
        const css = result.css.toString(); // need this since result.css is a Buffer
        
        cssPurge.purgeCSS(
            css,
            {
                trim: false,
                shorten: false,
                format: false,
            },
            (purgeError, purgeResult) => {
                if (purgeError) { console.log(purgeError) } else {
                    // ... write file
                }
            }
        });
    }
});

The css-purge options don't change result, doesn't matter which ones I choose. (e.g. last rule semicolons always get removed)
It even goes to the point where something gets formated in a way that leads to missing '}'s as the css parser states.
Error Message from css parser:

CSS Parser Error: probably have something funny in your CSS, change it then please try again.
Reason: @supports missing '}'
Line: 3
Column: 49
Filename: demo/test1.css

Which is odd, since it's a file in your package and I don't use it anywhere.

I'm using css-purge 3.0.10.
Hope you can help

@AndrewEQ
Copy link
Contributor

AndrewEQ commented Jul 20, 2018

Hmm, I'll have to test and have a look at it, kinda busy right now though, lemme see if I can get to it this weekend.

@AndrewEQ
Copy link
Contributor

Hey guys, finally found the issue, it was the default vars, my bad, sorted.

You should be able to just update gulp-css-purge else uninstall and reinstall.

@AndrewEQ AndrewEQ added the bug label Jul 25, 2018
@dmolesUC
Copy link

I'm seeing this with css-purge 3.0.13 — just the plain node module, from the command line. I'm running CSS-PURGE against the output of my SCSS compilation, with the intent of looking over the diffs to identify duplications etc. and then going back to the SCSS source to fix them. Eliminating comments and whitespace and newlines and extra semicolons makes this difficult.

I tried explicitly specifying the default (?) config file, which appears to disable trim_comments, trim_whitespace, trim_breaklines, and trim_last_semicolon, with -f`, but the output is a minified single line without comments or trailing semicolons.

Per the trim docs (“Only when its off can you turn on or off the other trim options”) I then tried setting "trim": "false", but the output was identical.

Am I misunderstanding the config? Am I doing something else wrong? Is the available node module out of date?

@AndrewEQ
Copy link
Contributor

@dmolesUC3 thanks for the heads up, I believe I sorted out the issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants