windicss / windicss-webpack-plugin

🍃 Windi CSS for webpack ⚡
https://windicss.org/integrations/webpack.html
79 stars 19 forks source link

Error when use extractors on windi config #109

Closed karyanayandi closed 2 years ago

karyanayandi commented 2 years ago

Describe the bug I use storybook with windicss webpack plugin and use extractors option like on documentation but there's error like below. Cheese_22 04 12_07 21 21

this is my windicss config

export default defineConfig({
  extract: {
    include: [
      "./packages/**/**/**/*{.js,.jsx,.ts,.tsx}",
      "./packages/**/**/**/**/*{.js,.jsx,.ts,.tsx}",
    ],
    extractors: [
      {
        extractor: (content) => {
          return { classes: content.match(/(?<=class:)[!@\w-]+/g) ?? [] }
        },
        extensions: ["tsx"],
      },
    ],
  },
  darkMode: "class",
  theme: {
    extend: {
      colors: {
        primary: colors.teal,
        secondary: colors.zinc,
      },
    },
  },
  plugins: [require("windicss/plugin/forms")],
})
await-ovo commented 2 years ago

@harlan-zw Hi, I can reproduce this issue on my side too, I think we might need to make the @windicss/plugin-utils compatible with custom extractor which return undefined tags, attributes values, etc.

The relevant code changed to this should work, and if it does, I'm happy to mention a PR:

image

@karyanayandi A temporary solution here can be configured like this:

export default defineConfig({
  extract: {
    include: [
      "./packages/**/**/**/*{.js,.jsx,.ts,.tsx}",
      "./packages/**/**/**/**/*{.js,.jsx,.ts,.tsx}",
    ],
    extractors: [
      {
        extractor: (content) => {
          return { 
             classes: content.match(/(?<=class:)[!@\w-]+/g) ?? [],
             attributes: {
               names: [],
               values: [],
             },
             tags: [],
             ids: []
          }
        },
        extensions: ["tsx"],
      },
    ],
  },
})
harlan-zw commented 2 years ago

Hey @await-ovo

Thanks for being proactive with that PR, have pushed up a new version 1.6.10 using the utils change