|
I know everyone has their own favorite method, but one that I'm extremely satisfied with is using webpack > sass-loader > extract-text[1] to `include Styles from './MyComponent.scss'` in each component file, and then it all gets bundled up into a single css file per target (also great for eliminating dead CSS!). I use "layouts" at the root of my react hierarchy (under stores and routers and whatnot) and put my global styles there. I haven't run into a situation using this setup where I felt like I needed a dirty hack to make something work. It does add a layer of complexity to the build, but if you can get it working once you can just copy paste it into every new webpack config, and It feels very natural and tends to organize itself. I am really not a fan of this new "css in your js" approach that the cool kids are using, but I guess I'm just getting old. [1] output of the following config will be: dist/
|_app/
|_bundle.js
|_bundle.css
|_admin/
|_bundle.js
|_bundle.css
``` const webpack = require("webpack");
const ExtractTextPlugin = require("extract-text-webpack-plugin");
const ExtractCSS = new ExtractTextPlugin("[name].css");
module.exports = {
entry: {
"./dist/app/bundle": "./app.js",
"./dist/admin/bundle": "./admin.js",
},
output: {
path: __dirname,
filename: "[name].js"
},
module: {
loaders: {
test: /\.scss$/,
loader: ExtractCSS.extract(["css", "sass?sourceMap"])
}, {
test: /\.js$/,
loader: 'babel',
exclude: /node_modules/,
include: __dirname
},
},
sassLoader: {
includePaths: "source/styles",
sourceMap: true
},
plugins: [ ExtractCSS ]
}
``` |