FullHuman / grunt-purgecss

Grunt plugin for purgecss
MIT License
9 stars 2 forks source link

Code example error #1

Open spointecker opened 6 years ago

spointecker commented 6 years ago

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.
spointecker commented 6 years ago

@Ffloriel ping

Ffloriel commented 6 years ago

Thanks for reporting the issue. Fixing the grunt plugin is my next priority.

spointecker commented 6 years ago

Thanks for your time!

Ffloriel commented 6 years ago

The plugin has been updated. The Readme contains an example of a working configuration. There is also an example here. The documentation of purgecss will soon be updated to add grunt plugin to the list.

spointecker commented 6 years ago

I am still having the same result with the new version and adapted config. There is no purged.css file written

My config:

purgecss: {
        app: {
            options: {
                content: [path + '/**/*.html.twig']
            },
            files: {
                'purged.min.css': ['web/assets/css/app.css']
            }
        }
    },

Output is still the same as in the opening post (the var purgecssResult = new Purgecss({...) doesnt return anything.

Any ideas how to debug this? Is it possible to add more info output to the whole process?

Ffloriel commented 6 years ago

Could you provide a repo that reproduce the issue? One potential reason I can think of is if the paths to the files are not correct.

spointecker commented 6 years ago

Unfortunately it´s not that easy to provide an example of our grunt structure (working with subrepos...) due to its complexity.

optimalisatie commented 6 years ago

Hi!

We noticed the same issue. We hereby confirm that no CSS file is written.

image image

Gruntfile.js config:

purgecss: {
    options: {
        content: ['html/*.html']
    },
    verkoop: {
        files: {
            'css/purged.css': ['../httpdocs/verkoop.css']
        }
    }
}
jsnanigans commented 6 years ago

@optimalisatie I think that could be one of two things

  1. node does not have rights to write the file css/purged.css or into the directory css
  2. the css directory does not exist, im not sure if purgecss can create it for you
tofof commented 6 years ago

I also get no file written. PurifyCSS has no trouble writing to the same path, so it's not (1). The output directory exists, so it's not (2).

purgecss: {
      my_target: {
        options: {
          content: ['src/index.html']
        },
        files: {
          'out.css': ['src/in.css']
        }
      }
    }

EDIT: using the CLI revealed a thrown exception on a missing semicolon in my CSS source. Grunt-purgecss still reported Done, without errors.

After fixing the missing semicolon, grunt-purgecss successfully wrote its output file. Looks like your error detection is incomplete.