webpack-contrib / purifycss-webpack

UNMAINTAINED, use https://github.com/FullHuman/purgecss-webpack-plugin
MIT License
772 stars 37 forks source link

plugin no effect with my css, sass loaders #55

Closed elvisbegovic closed 7 years ago

elvisbegovic commented 8 years ago

Hi,

I use loader extractCSS.extract([ 'css', 'sass' ])

And in my plugins I add

new purify({
    basePath: __dirname + '../',
    paths: [
      'index.html'
    ]
  })

When I build my app without purifycss plugin my css i builded and minified but when I put purifycss plugin as above, so my css is well extracted to an build.css file but two problem : it isn't minified and the big problem is my unused class are still here, no change effect!

thanks in advance

HumbleBeck commented 8 years ago

Had same issue, but, I thing i fixed it by adding

resolveExtensions: ['.html']

before my config was

new Purify({
    basePath: __dirname,
    paths: [
        '/home/*.html'
    ],
    //resolveExtensions: ['.html'],
    purifyOptions: {
        minify: true,
        rejected: true
    }
})

without 'resolveExtensions', plugin takes all from webpack's 'resolve.extensions' and if log the files variable inside plugin it would be like

[ */home/index.html',
  '*/node_modules/css-loader/lib/css-base.js',
  '*/node_modules/style-loader/addStyles.js',
  '*/source/home/index.js',
  '*source/home/style.css' ]

so source css file in files that be passed to purify, and it thinks styles is used and doesn't remove them if add 'resolveExtensions: ['.html']' path variable would be like

[ '*/home/index.html' ]

Just the right html will be passed to purify. Hope this will help fix your issue. P.S. Maybe I'm wrong in explaining, but its works.

IAMtheIAM commented 8 years ago

@HumbleBeck Wow man, thanks. It is absolutely necessary to add resolveExtensions: ['.html'] to the Purify-Webpack-Plugin object, otherwise it thinks all css is used and does nothing. Works like a charm, now!

Anima-t3d commented 8 years ago

Shouldn't this be stated in the docs? I had the same issue. Thanks for the solution!

bebraw commented 7 years ago

Same. Please add it to the docs, or even better, set it as a default and document how to change it.