This might make it more confusing, but I thought to send you a copy of the file that I use for the dev environment which includes SASS and React. you should be able to decifer what is needed and not needed.
I have excluded anything that is directly work related such as IP address used for a proxy in the devServer setup but other than that it is complete.
hope it helps!
const webpack = require('webpack');
const path = require('path');
const ExtractTextPlugin = require('extract-text-webpack-plugin');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const CopyWebpackPlugin = require('copy-webpack-plugin');
const Paths = {
dist: path.resolve(__dirname, 'dist'),
src: path.resolve(__dirname, 'src'),
indexFile: path.resolve(__dirname, 'src/index.jsx'),
nodeModulesDir: path.resolve(__dirname, 'node_modules'),
sassFile: path.resolve(__dirname, 'assets/css/main.scss')
};
const config = {
devtool: '#source-map',
entry: {
main: ['react-hot-loader/patch', 'babel-polyfill', Paths.indexFile, Paths.sassFile],
},
output: {
path: Paths.dist,
filename: "[name].[hash].bundle.js",
publicPath: "/"
},
module: {
rules: [
{
test: /\.(js|jsx)$/,
exclude: [Paths.nodeModulesDir],
use: [{
loader: 'babel-loader?cacheDirectory&cacheIdentifier='+ Math.random(),
options: {
presets: ["env", "react", "stage-0",
["env", {
"targets": {
"browsers": ["last 2 versions", "ie >= 8", "safari >= 7"]
},
debug: true
}]
]
}
}]
},
{
test: /\.css/,
use: ExtractTextPlugin.extract({
fallback: 'style-loader',
use: [
{
loader: 'css-loader',
options: {
modules: true,
localIdentName: '[name]_[local]__[hash:base64:5]'
}
},
'postcss-loader'
]
})
},
{
test: /\.scss$/,
use: ExtractTextPlugin.extract({
fallback: 'style-loader',
use: [
{
loader: 'css-loader',
options: {
modules: false,
sourceMap: true,
importLoaders: 2,
localIdentName: '[name]_[local]__[hash:base64:5]'
}
},
'sass-loader'
]
})
},
{
test: /\.(eot|woff|woff2|ttf|svg|png|jpe?g|gif)(\?\S*)?$/,
use: [
{
loader: 'url-loader',
options: {
limit: 100000,
name: '[name].[ext]'
}
}
]
}
]
},
resolve: {
extensions: ['.js', '.jsx'],
modules: ['node_modules', 'src']
},
plugins: [
new webpack.DefinePlugin({
'process.env.NODE_ENV': JSON.stringify('development')
}),
new HtmlWebpackPlugin({
template: path.join(Paths.src, 'index.html')
}),
new ExtractTextPlugin({filename: "[name].[contenthash].css", allChunks: true}),
new CopyWebpackPlugin([
{from: 'assets/images/**/*', to: ''},
{from: 'assets/fonts/**/*', to: ''},
{from: 'assets/lang/**/*', to: ''},
{from: 'assets/js/**/*', to: ''},
{from: 'src/static/**/*', to: ''}
]),
new webpack.HotModuleReplacementPlugin(),
new webpack.NamedModulesPlugin()
],
devServer: {
port: 8081,
host: '127.0.0.1',
disableHostCheck: true, // so you can use the computers IP address not just 'localhost'/127.0.0.1
contentBase: Paths.src,
historyApiFallback: true,
hot: true,
headers: {
"Access-Control-Allow-Origin": "http://localhost:8081",
"Access-Control-Allow-Methods": "GET, POST, PUT, DELETE, PATCH, OPTIONS",
"Access-Control-Allow-Headers": "X-Requested-With, content-type, Authorization"
},
inline: true
}
}
};