Skip to content
This repository was archived by the owner on Feb 1, 2020. It is now read-only.

Doesn't detect classes inside es6 template strings #32

Closed
huygn opened this issue Jun 28, 2018 · 2 comments
Closed

Doesn't detect classes inside es6 template strings #32

huygn opened this issue Jun 28, 2018 · 2 comments

Comments

@huygn
Copy link

huygn commented Jun 28, 2018

  • webpack 4
  • purgecss-webpack-plugin 1.2.0

this doesn't work (below 2 classes don't appear in the final css bundle):

const className = `no-underline bg-blue-lighter`

this works (single quote):

const className = 'no-underline bg-blue-lighter'

My config:

const path = require('path');
const glob = require('glob');
const PurgecssPlugin = require('purgecss-webpack-plugin');

class TailwindExtractor {
  static extract(content) {
    return content.match(/[A-z0-9-:/]+/g) || [];
  }
}

new PurgecssPlugin({
  // files to scan for class names.
  paths: glob.sync(path.join(__dirname, './src/**/*.js')),
  extractors: [
    {
      extractor: TailwindExtractor,
      extensions: ['js', 'jsx'],
    },
  ],
  whitelist: ['html', 'body'],
  whitelistPatterns: [],
});
@huygn
Copy link
Author

huygn commented Jun 29, 2018

Ok it turns out the match result contains the back tick ie.

['`no-underline', 'inline-block']

which is why it doesn't work. My dirty solution is removing back ticks in the final result array, hope this help.

@jsnanigans
Copy link
Collaborator

Try this in the extractor: /[A-Za-z0-9-_:\/]+/g the A-z somehow includes a backtick

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

No branches or pull requests

2 participants