KaiHotz / react-rollup-boilerplate

Boilerplate for creating React component libraries, bundled with Rollup.js to ESM and/or CJS Modules, Storybook, Typescript
https://kaihotz.github.io/react-rollup-boilerplate/
MIT License
300 stars 67 forks source link

How to enable css module? #9

Closed chardy closed 4 years ago

chardy commented 4 years ago

I try to use css module to do the styling and it's not working. It return undefined.

import React from "react";
import PropTypes from "prop-types";
import style from "./styles.css";

const Button = ({ onClick, disabled, className, text }) => (
  <button
    type="button"
    className={style.button}
    onClick={onClick}
    disabled={disabled}
  >
    {text}
  </button>
);

Button.propTypes = {
  onClick: PropTypes.func,
  /** Disable the button */
  disabled: PropTypes.bool,
  className: PropTypes.string,
  /** Text of the button */
  text: PropTypes.string
};

Button.defaultProps = {
  onClick: () => {},
  disabled: false,
  className: null,
  text: "Click Me"
};

export default Button;
shayc commented 4 years ago

@chardy in rollup.config change to:

postcss({
      modules: true,
      autoModules: true,
      plugins: [],
      minimize: true,
      sourceMap: "inline"
})