Skip to content

Instantly share code, notes, and snippets.

@basecss
Last active November 29, 2018 12:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save basecss/287a8671a0e9b7df8ddba61d871859f6 to your computer and use it in GitHub Desktop.
Save basecss/287a8671a0e9b7df8ddba61d871859f6 to your computer and use it in GitHub Desktop.
React + Redux + Webpack + Babel + HMR(JS + CSS) + CSS Extract

dependencies

npm install webpack webpack-cli webpack-dev-server @babel/core @babel/preset-env
@babel/preset-react babel-loader css-loader mini-css-extract-plugin css-hot-loader --save-dev --verbose

npm install react react-dom redux react-redux --save --verbose

.babelrc

{
  "presets": {
    "@babel/preset-env",
    "@babel/preset-react"
  }
}

webpack.config.js

const path = require('path')
const webpack = require('webpack')
const MiniCssExtractPlugin = require('mini-css-extract-plugin')

module.exports = {
  entry: './src/index.js',
  output: {
    path: path.resolve(__dirname, 'build'),
    publicPath: '/build',
    filename: 'app.js'
  },
  devtool: 'cheap-module-source-map',
  module: {
    rules: [{
      test: /\.css$/,
      use: [
        'css-hot-loader',
        MiniCssExtractPlugin.loader,
        'css-loader'
      ]
    }, {
      test: /\.js$/,
      exclude: /node_module/,
      use: ['babel-loader']
    }]
  },
  resolve: {
    extensions: ['.js', '.json', '.wasm']
  },
  plugins: [
    new MiniCssExtractPlugin({
      filename: 'app.css'
    }),
    new webpack.HotModuleReplacementPlugin()
  ],
  devServer: {
    contentBase: './',
    hot: true
  },
  optimization: {}
}

usage

webpack-dev-server --config webpack.config.js --mode development
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment