GithubHelp home page GithubHelp logo

fullhuman / grunt-purgecss Goto Github PK

View Code? Open in Web Editor NEW
9.0 5.0 2.0 51 KB

Grunt plugin for purgecss

License: MIT License

JavaScript 96.18% CSS 2.55% HTML 1.27%
css optimization-tools grunt-plugins purgecss

grunt-purgecss's People

Contributors

calinou avatar ffloriel avatar peiche avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

Forkers

mewtlu calinou

grunt-purgecss's Issues

Grunt extractor issue

First of all, thanks for updating the Grunt plugin in regards to the issue with comments FullHuman/purgecss#90 @Ffloriel

Now, I'm having trouble getting the plugin to work with proper extractors that respect / do not cleanse responsive/etc. classes from my css which have been put there by TailwindCSS.

I know FullHuman/purgecss#56 and I also found this at the Tailwind repo. However, this doesn't solve my issue.

I want to keep css like

  .mn\:hidden {
    display: none;
  }

...when this can be found in my markup:

<div class="mn-hidden">

My setup inside my Gruntfile.js

    purgecss: {
      my_target: {
        options: {
          content: ['../theme/layout/*.liquid',
                    '../theme/sections/*.liquid',
                    '../theme/snippets/*.liquid',
                    '../theme/templates/*.liquid',
                    '../theme/templates/customers/*.liquid'],
          extractors: {
            extractor: class {
                static extract(content) {
                    content.match(/[A-z0-9-:\/]+/g) || []
                }
            },
            extension: ['css', 'html', 'liquid']
          },
          // whitelist: ['text'],
          // whitelistPatterns: [/mn$/],
          keyframes: true,
          fontFace: true
        },
        files: {
          'tmp/theme_sass_postcss_stringreplace_purgecss.css': ['tmp/theme_sass_postcss_stringreplace.css']
        }
      }
    },

However with this setup the css gets stripped. I'm currently helping myself by changing the separator from colon to dash (tailwind docs) as it works this way.

The purge works per se, so it's not an issue with the content files. However, I'm no regex-expert (always using regex101), so maybe the regex-code is simply wrong for my case?

Another possible reason would be that the plugin is not behaving correctly so I thought I probably report this, even though I got it working with an alternate separator.

Code example error

Hi,

I just tried the plugin and recognized an error in the example you have given:
I had to add a "section" and wrap the files parameter, otherwise "files" was always empty.

grunt.initConfig({
  purgecss: {
    options: {
      content: ['src/**/*.html'],
    },
    app: {
        files: {
          'dist/main.css': ['src/**/*.css'],
        },
    }
  },
});

In addition to this, there is no file written in my case. It just stops during the purge process.

     grunt.log.writeln('1');

      // purgecss
      var purgecssResult = new Purgecss({
        content: options.content,
        css: f.src
      }).purge()[0].css
      grunt.log.writeln('2');

So "1" will be printed but "2" doesn´t.


Running "purgecss:app" (purgecss) task
Verifying property purgecss.app exists in config...OK
Files: #mypath#mycss.css -> #mypath#mycss.min.css
Options: content=["#mypath#/**/*.twig"]
1

Done.

"Files" Syntax for wildcard

Does the "files" array always convert one source css file to one target file? Or can you give an example on how to use wildcards here (if possible with purgcss, like in the "content" option)

So basically what I want is:

  • Purge any css file in given directory structure and output every file (with the same name) to specified output directory

Something like:

files: { 'purged_output/**/*.css': 'scr/css/**/*.css' }

Plan B would be to purge all source css files into one large (purged) css file but I couldn't get that t work, too:

files: { 'purged_output/app.css': 'scr/css/*.css' }

results in an empty output file

Whitelist option not ignoring class

Using "whitelist" option to ignore certain classes isn't working -- purgecss still removes those classes. Am I doing something wrong or is this a bug? Running grunt-purgecss 1.0.0, and grunt 1.0.3.

`module.exports = function(grunt) {
grunt.initConfig({

	purgecss: {
      my_target: {
        options: {
          content: ['page-templates/home-page.php'],
          whitelist: ['random', 'text-white', 'button']
        },
        files: {
          'build/css/style-home-purge.css': ['source/sass/style-combined.css']
        }
      }
    }
    
});

grunt.loadNpmTasks('grunt-purgecss');

}`

bug(options): whitelisting options doesn't work

#7 — related issue. @Ffloriel, ping.

1. Summary

Any PurgeCSS whitelisting options doesn't work for me.

2. Data

2.1. Environment

  • Operating system:

    • Windows 10 Enterprise LTSB 64-bit EN — local
    • Ubuntu 14.04.5 LTS
  • Node.js 11.10.0

  • purgecss 1.1.0

  • grunt 1.0.3

  • grunt-purgecss 1.1.0

  • grunt-cli 1.3.2

3. Files

Look at KiraPurgeCSS branch of my demo repository:

  • KiraGoddess.html:
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>PurgeCSS debugging</title>
</head>
<body>
    <p class="KiraFirst">Kira</p>
</body>
</html>
  • KiraGoddess.css:
.KiraFirst {
    color: red
}

.KiraSecond {
    color: yellow
}
  • Gruntfile.coffee:
module.exports = (grunt) ->
    grunt.initConfig
        purgecss:
            options:
                content: ["KiraGoddess.html"]
                whitelist: [".KiraSecond"]
                whitelistPatterns: [/\.KiraSecond/g]
                whitelistPatternsChildren: [/\.KiraSecond/g]
            main:
                files:
                    "KiraGoddess.css": ["KiraGoddess.css"]

    grunt.loadNpmTasks 'grunt-purgecss'
    return

4. Steps to reproduce

4.1. PurgeCSS CLI

purgecss --css KiraGoddess.css --con KiraGoddess.html --out . --whitelist KiraSecond

4.2. grunt-purgecss

grunt purgecss

5. Behavior

5.1. Expected — CLI

.KiraFirst {
    color: red
}
.KiraSecond {
    color: yellow
}

purgecss-CLI successful ignore .KiraSecond class.

5.2. Unexpected — Grunt

.KiraFirst {
    color: red
}

grunt-purgecss not ignore .KiraSecond class.

Note, how Grunt show options:

Options: content=["KiraGoddess.html"], whitelist=[".KiraSecond"], whitelistPatterns=[{}], whitelistPatternsChildren=[{}]

6. Not helped

  1. Remove \. and /g from patterns
  2. Adding ^ and $ to regexes as in example

Thanks.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.