Skip to content
This repository has been archived by the owner on Jul 31, 2018. It is now read-only.

Extract css out of App container #29

Open
l4u opened this issue Jan 5, 2016 · 11 comments
Open

Extract css out of App container #29

l4u opened this issue Jan 5, 2016 · 11 comments

Comments

@l4u
Copy link

l4u commented Jan 5, 2016

Should we extract the css for html, body, button from /client/containers/App/style.css to another global stylesheet?

@tj
Copy link
Owner

tj commented Jan 5, 2016

probably, I'm not sure what the convention is there but that would make sense to me!

@tj tj changed the title Extract css Extract css out of App container Jan 5, 2016
@gpbl
Copy link

gpbl commented Jan 5, 2016

I usually put such css declarations into a generic html.css file, that I import from the entry file. In your case, since the entry file is called app/index.jsx, I'd call it index.css.

@c0b41
Copy link

c0b41 commented Jan 15, 2016

@wieringen
Copy link

Would this also fix the fouc that is visible sometimes when loading the index?

@mikaa123
Copy link

mikaa123 commented Feb 4, 2016

👍 for @ayhankuru proposition. I used Extract Text Plugin for my project and it works great.

What I like about it is that we don't have to change the current file architecture (css files can remain in component folders), and it fixes the fouc.

@wieringen
Copy link

@mikaa123 Can you share the code of your solution? I'm really interested :)

@mikaa123
Copy link

mikaa123 commented Feb 4, 2016

@wieringen sure.

There are two parts:

  • Use Extract Text Plugin in your webpack.config.js:
module: {
        loaders: [
            { test: /\.css$/, loader: ExtractTextPlugin.extract("style-loader", "css-loader") }
        ]
    },
    plugins: [
        new ExtractTextPlugin("styles.css")
    ]
}

This tells webpack to create a styles.css file with all the css inside.

Reference it from index.html. Use the regular link tag.

Do we want to do this for the boilerplate? If so, I'd happily make a PR.

@wieringen
Copy link

Thanks I will try it out now! :)

@wieringen
Copy link

@mikaa123 Wouldn't it be better to only use your solution for the App/style.css and the current solution for all the other css files?

@mikaa123
Copy link

mikaa123 commented Feb 4, 2016

@wieringen no need to use Extract Text Plugin if we only want to reference App/style.css. As @gpbl said we can create the css file and simply reference it from the index. However, it won't fix the FOUC.

The FOUC comes from the CSS being bundled in the JS. Our components get added to the DOM before the CSS exists and boom! Flash of Unstyled Content. Hoisting the CSS fixes it though. I'm sure there are other solutions too.

@gpbl
Copy link

gpbl commented Feb 4, 2016

I use the ExtractTextPlugin only when building for production. On development, a static .css breaks the css hot reload. Or, at least, I could't find a way to remove the included .css after the first hot reload...

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

No branches or pull requests

6 participants