Skip to content

Instantly share code, notes, and snippets.

@lambdahands
Created September 28, 2015 17:09
Show Gist options
  • Save lambdahands/d19e0da96285b749f0ef to your computer and use it in GitHub Desktop.
Save lambdahands/d19e0da96285b749f0ef to your computer and use it in GitHub Desktop.

Revisions

  1. lambdahands revised this gist Sep 28, 2015. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion _readme.md
    Original file line number Diff line number Diff line change
    @@ -6,7 +6,7 @@ What WebPack allows us to do is "require" CSS files and use their class names:

    ```js
    import styles from "my_styles.css";
    import React from 'react';
    import React from "react";

    const MyComponent = React.createClass({
    render() {
  2. lambdahands created this gist Sep 28, 2015.
    30 changes: 30 additions & 0 deletions _readme.md
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,30 @@
    # Huh?

    So basically [FlowType](http://flowtype.org) doesn't know about [CSS Modules](https://github.com/webpack/css-loader/#css-modules), a really handy way of dealing with the plagues of CSS in codebases (global variables and dependency wackiness mainly).

    What WebPack allows us to do is "require" CSS files and use their class names:

    ```js
    import styles from "my_styles.css";
    import React from 'react';

    const MyComponent = React.createClass({
    render() {
    return <h1 className={styles.redHeader}>Hello!</h1>;
    }
    });
    ```

    Unfortunately, Flow will give us an error `Required module not found` because, well, let's be honest, importing CSS with JavaScript is pretty out of this world and a little bit crazy (i.e: [this](http://media0.giphy.com/media/NbgeJftsErO5q/giphy.gif)).

    So here's what I did to fix that. Flow has a nice way of dealing with this in its options, namely one called `module.name_mapper`. Somebody was kind enough to make an npm module called `empty` that– you guessed it– returns empty objects and arrays. I'm pretty amazed to have found a use for this.

    So as a fix, do this:
    Run `npm install --save empty` in your project directory.

    Open your `.flowconfig`, and add the following under `[options]`:
    ```
    module.name_mapper='.*\(.css\)' -> 'empty/object'
    ```

    Ta-da! Another fun day in JavaScript land.