question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

How to use css modules

See original GitHub issue

Is there a way to use css modules with docz?

Description I’m using css modules with the webpack loader css-loader

here is a component for an exemple

import * as React from 'react'
import classNames from 'classnames'

const styles = require('./styles.css')

interface State {
  isFocused: boolean
}

export default class TextField extends React.Component<{}, State> {
  public constructor(props: {}) {
    super(props)

    this.state = {
      isFocused: false
    }
  }

  private onFocus = () => {
    this.setState({ isFocused: true })
  }

  private onBlur = () => {
    this.setState({ isFocused: false })
  }

  public render() {
    return <div className={styles.container}>
      <input className={styles.input}
        onFocus={this.onFocus}
        onBlur={this.onBlur} />
      <label className={classNames(styles.label, this.state.isFocused ? styles.labelFocus : {})}>label</label>
    </div >
  }
}

and my very simple mdx file

---
name: TextField
---

import {Playground } from 'docz'
import TextField from './'

# TextField

<Playground>
  <TextField />
</Playground>

when I start docz dev server, I have this error message

 ERROR  Failed to compile with 1 errors                                                                       09:39:00

 error  in ./src/libs/text-field/text.mdx

Module build failed (from ./node_modules/@mdx-js/loader/index.js):
Error: ENOENT: no such file or directory, open '/Users/bgranger/htdocs/perso/pocs/docz/src/libs/text-field/text.mdx'

 @ ./.docz/app/imports.js 9:11-123
 @ ./.docz/app/index.jsx
 @ multi ./node_modules/babel-polyfill/lib/index.js ./.docz/app/index.jsx

I assume that the css loader is not used with the bundler.

I have two questions:

  • is it possible to use css modules?
  • if not is it possible to use custom bundler/bundler config?

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

11reactions
pedronauckcommented, Jun 21, 2018

Try to make your config like that @S-unya:

// doczrc.js
export default {
  modifyBundlerConfig: (config) => {
    config.resolve.extensions.push('.scss')
    config.module.rules.push({
      test: /\.scss$/,
      use: ["style-loader", "css-loader", "sass-loader"]
    })

    return config
  }
}
1reaction
pedronauckcommented, Jun 22, 2018

After released v0.2.11 you can use docz-plugin-css to configure your CSS just by adding a plugin ✌️

@S-unya @bastienGranger

Read more comments on GitHub >

github_iconTop Results From Across the Web

Using CSS Modules in React - Programming with Mosh
First, create a normal CSS file. · Add CSS classes to this file. · Import the module you've just created from within your...
Read more >
Using CSS modules in React - Bootcamp
A CSS Module is simply a .css file, where classes act similarly to local variables in Javascript. It is a tool that makes...
Read more >
What are CSS Modules and how to use it in React - UseCSV
CSS Modules are "CSS files in which all class names and animation names are scoped locally by default". Instead of having CSS files...
Read more >
Adding a CSS Modules Stylesheet - Create React App
CSS Modules let you use the same CSS class name in different files without worrying about naming clashes. Learn more about CSS Modules...
Read more >
Using CSS Modules in React - OpenReplay Blog
Using CSS Modules in React ... In React js, where classes function similarly to local variables in JavaScript, a CSS Module is just...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found