Compiling Sass with Webpack (and local scope class names)
<p>I've spent hours attempting to get my Webpack config to compile Sass; it's kinda ridiculous.  During my research I found dozens of Github issues, Stackoverflow posts, and blogs talking about how to use Sass with Webpack, and they all do it differently.  Also, there are so many people with problems.  I just think Webpack needs to be better documented.  Ugh.</p>

<p><strong>I figured out how to compile Sass and have Webpack serve it in memory from <code>/static</code>, but I want the class names to be locally scoped.  Isn't that one of the benefits of modular CSS with React components?</strong></p>

<p>Example of <em>locally scoped</em>: <code>.foo__container___uZbLx {...}</code></p>

<p>So, this is my Webpack config file:</p>

<pre><code>const webpack = require('webpack');
const path = require('path');
const ExtractTextPlugin = require('extract-text-webpack-plugin');

module.exports = {
    devtool: 'source-map',
    entry: {
        bundle: './src/js/app'
    },
    output: {
        path: __dirname,
        filename: '[name].js',
        publicPath: '/static'
    },
    plugins: [
        new webpack.optimize.OccurrenceOrderPlugin(),
        new ExtractTextPlugin('[name].css', {allChunks: true})
    ],
    module: {
        loaders: [
            {
                test: /\.js$/,
                exclude:  /node_modules/,
                include: path.join(__dirname, 'src'),
                loader: 'babel'
            },
            {
                test: /\.scss$/,
                exclude:  /node_modules/,
                include: path.join(__dirname, 'src'),
                loader:  ExtractTextPlugin.extract('style', 'css?sourceMap!sass')
            }
        ]
    }
};
</code></pre>

<p>I managed to get it to work for vanilla CSS:</p>

<pre><code>{
    test: /\.css$/,
    exclude:  /node_modules/,
    include: path.join(__dirname, 'src'),
    loader:  ExtractTextPlugin.extract('style', 'css?modules&amp;importLoaders=1&amp;localIdentName=[name]__[local]___[hash:base64:5]')
}
</code></pre>

<p>I don't really understand the parameter-like syntax with all the <code>?</code> marks, and I don't know what to search for to find documentation pertaining to that.</p>

<p>This is what my React component looks like; just incase you want to see how I am importing the style:</p>

<pre><code>import React, { Component } from 'react';
import s from './foo.css';

class Foo extends Component {
    render() {
        return (
            &lt;div className={s.container}&gt;
                &lt;h1 className="title"&gt;Welcome!&lt;/h1&gt;
                &lt;p className="body"&gt;This is a dummy component for demonstration purposes.&lt;/p&gt;
            &lt;/div&gt;
        );
    }
}

export default Foo;
</code></pre>

<p>Also, I have three unrelated questions:</p>

<ul>
<li>What's the point of <code>output.path</code> property if Webpack merely serves the file from memory by means of <code>/static</code>?</li>
<li>What's the point of <code>webpack-dev-server</code> if what I am doing here is adequate?  From my understanding, <code>webpack-dev-server</code> is just for hot module replacement stuff, right?  Just automatic refreshing?</li>
<li>Are my <code>exclude</code> and <code>include</code> properties redundant?  From my understanding, excluding <code>node_modules</code> decreases the compilation time making it work quicker; less files to process.</li>
</ul>