storybookjs / addon-postcss

This Storybook addon can be used to run the PostCSS preprocessor against your stories.
MIT License
20 stars 22 forks source link

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

Open zakkor opened 3 years ago

zakkor commented 3 years ago

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

danawoodman commented 3 years ago

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

fvanwijk commented 2 years ago

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.

alkorlos commented 2 years ago

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.

danawoodman commented 2 years ago

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?

alkorlos commented 2 years ago

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.

danawoodman commented 2 years ago

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

WesleySmits commented 2 years ago

Also running into this issue.

i1ko commented 1 year ago

I have the same issue. My stack:

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"
  ],
}