addon-postcss icon indicating copy to clipboard operation
addon-postcss copied to clipboard

[Bug] Loader won't work for files with an extension other than ".css" (such as ".pcss" or ".postcss")

Open zakkor opened this issue 3 years ago • 8 comments

Related PR: #17 There's no option to change the test either.

zakkor avatar May 13 '21 11:05 zakkor

Coming across this myself, any change this will be addressed?

danawoodman avatar Jul 01 '21 17:07 danawoodman

This also happens with .vue files that have <style lang="postcss">. As workaround remove the lang attribute (but then syntax highlighting breaks).

Or fix it by setting the webpack config yourself:

webpackFinal(webpackConfig) {
    // Same config as what @storybook/addon-postcss produces, but for Vue <style lang="postcss"> blocks
    webpackConfig.module?.rules.push({
      test: /\.postcss$/, // Matches lang="postcss" in Vue files
      sideEffects: true,
      use: [
        require.resolve("style-loader"),
        require.resolve("css-loader"),
        require.resolve("postcss-loader"),
      ],
    });;

So please update the addon to match more extensions.

fvanwijk avatar Jul 22 '21 10:07 fvanwijk

Official twitter PostCSS recommendation use .pcss extension for PostCSS based sources. https://twitter.com/PostCSS/status/661645290622083073 This change is required to comply with official requirements.

alkorlos avatar Jul 31 '21 04:07 alkorlos

That is a 6 year old Tweet, so I'm not sure it's relevant anymore? I believe either do not work with Storybook, correct?

danawoodman avatar Aug 01 '21 21:08 danawoodman

What has changed in six years? postcss is still not css. The general rule is that the file format should match its content, for many reasons. For instance it postcss has different syntax highlighting, lint rules, snippets, etc. In any case, people themselves must decide what is more convenient for them.

alkorlos avatar Aug 02 '21 03:08 alkorlos

I think we are agreeing here as Storybook fails with .pcss or .postcss and using .css for PostCSS files isn't ideal.

danawoodman avatar Aug 02 '21 15:08 danawoodman

Also running into this issue.

WesleySmits avatar Nov 28 '21 07:11 WesleySmits

I have the same issue. My stack:

  • storybook
  • nextJS and React
  • tailwindCSS with postCSS.

Configuration:

postcss.config.js

//postcss.config.js
module.exports = {
  plugins: {
    'postcss-import': {},
    "tailwindcss/nesting": {},
    tailwindcss: {},
    autoprefixer: {},
  },
}

tailwind.config.js

//tailwind.config.js
module.exports = {
  important: true,
  content: [
    "./pages/**/*.{js,ts,jsx,tsx}",
    "./components/**/*.{js,ts,jsx,tsx}",
    "./stories/**/*.{js,ts,jsx,tsx}",
    "./styles/**/*.{css,pcss}"
  ],
}

main.js (storybook)

//main.js (storybook)
module.exports = {
  "stories": [
    "../stories/**/*.stories.mdx",
    "../stories/**/*.stories.@(js|jsx|ts|tsx)"
  ],
  "addons": [
    "@storybook/addon-links",
    "@storybook/addon-essentials",
    "@storybook/addon-interactions",
    "@storybook/addon-postcss"
  ],
  "framework": "@storybook/react",
  "core": {
    "builder": "@storybook/builder-webpack5"
  },
  typescript: {
    check: false,
    checkOptions: {},
    reactDocgen: 'react-docgen-typescript',
    reactDocgenTypescriptOptions: {
      shouldExtractLiteralValuesFromEnum: true,
      propFilter: (prop) => (prop.parent ? !/node_modules/.test(prop.parent.fileName) : true),
    },
  },
  "staticDirs": [
    "../public",
    "../styles"
  ],
}

i1ko avatar Jan 11 '23 15:01 i1ko