Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PostCSS and CSS Modules not working (again) #1791

Closed
chapati23 opened this issue Sep 3, 2017 · 1 comment
Closed

PostCSS and CSS Modules not working (again) #1791

chapati23 opened this issue Sep 3, 2017 · 1 comment

Comments

@chapati23
Copy link

Description

Sorry, to open this again. I'm aware there were several issue before e.g. #48 and #755

But unfortunately none of these solutions seem to work in the latest version (3.2.8). The storybook webpack doesn't complain but I don't get any of my styles because the class names that CSS Modules usually generates are now all undefined.

Very happy about any ideas.

.storybook/webpack.config.js

copy-pasted from my normal webpack.config where it works

const path = require('path')

module.exports = {
  plugins: [
    // your custom plugins
  ],
  module: {
    rules: [
      {
        test: /\.css$/,
        use: [
          {
            loader: 'css-loader',
            options: {
              camelCase: true,
              importLoaders: 1,
              modules: true,
              localIdentName: '[name]__[local]--[hash:base64:5]'
            }
          },
          'resolve-url-loader',
          'postcss-loader?sourceMap'
        ],
        include: path.resolve(__dirname, '../')
      }
    ]
  }
}

button.component.js

import React from 'react'
import styles from './button.styles.css'

export const Button = (props) => {
  return (
    <button className={`${styles.button} ${styles.big}`}
    >{props.children}</button>
  )
}
export default Button

button.styles.css

.normal {
  padding: 5px 15px;
}

.big {
  padding: 10px 50px;
}

.button {
  background-color: var(--cta);
  border: none;
  border-radius: 8px;
  color: var(--black);
  cursor: pointer;
  display: inline-block;
  font-family: 'cinetype', sans-serif;
  font-size: 18px;
  line-height: 30px;
  min-height: 40px;
  min-width: 90px;
  position: relative;
  text-transform: uppercase;
}

postcss.config.js

const colors = {
  black: '#141a2f',
  cta: '#e3d841',
  'dark-blue': '#172c81',
  'light-blue': '#4884c2',
  highlight: '#6bc3ff',
  light: '#e8ecff',
  'text-inactive': 'rgba(255, 255, 255, 0.4)',
  white: '#fff'
}

// Why em instead of px? Glad you asked: https://cloudfour.com/thinks/the-ems-have-it-proportional-media-queries-ftw/
const mediaQueries = {
  '--phone': '(min-width: 20em)', // 320px
  '--tablet': '(min-width: 48em)', // 768px
  '--desktop': '(min-width: 62em)', // 992px
  '--large-desktop': '(min-width: 75em)' // 1200px
}

module.exports = {
  plugins: {
    'postcss-import': {},
    'postcss-custom-properties': { variables: colors },
    'postcss-custom-media': { extensions: mediaQueries },
    'postcss-calc': {},
    'postcss-color-function': {},
    'postcss-cssnext': {
      browsers: ['last 2 versions', '> 5%'],
      warnForDuplicates: false
    },
    cssnano: {}
  }
}
@chapati23
Copy link
Author

god i hate webpack. my bad, forgot style-loader of course…

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

No branches or pull requests

1 participant