Skip to content

Instantly share code, notes, and snippets.

@rajeshdavidbabu
Created January 9, 2022 22:43
Show Gist options
  • Save rajeshdavidbabu/f3047a3da21aebdd552109503e759d0a to your computer and use it in GitHub Desktop.
Save rajeshdavidbabu/f3047a3da21aebdd552109503e759d0a to your computer and use it in GitHub Desktop.
Webpack dev config for React TS Project
import path from 'path';
import { Configuration, HotModuleReplacementPlugin } from 'webpack';
import HtmlWebpackPlugin from 'html-webpack-plugin';
import ForkTsCheckerWebpackPlugin from 'fork-ts-checker-webpack-plugin';
import ESLintPlugin from 'eslint-webpack-plugin';
import 'webpack-dev-server'; // Imported just to avoid type error in configuration
const config: Configuration = {
mode: 'development',
output: {
publicPath: '/', // Paths of generated bundled injected in our public html.
},
entry: './src/index.tsx',
module: {
rules: [
{
test: /\.(ts|js)x?$/i,
exclude: /node_modules/,
use: {
loader: 'babel-loader', // Using babel-loader to load files using .babelrc configs.
},
},
],
},
resolve: {
extensions: ['.tsx', '.ts', '.js', '.jsx'],
},
plugins: [
new HtmlWebpackPlugin({
template: './public/index.html',
}),
new ForkTsCheckerWebpackPlugin({
async: false,
}),
new ESLintPlugin({
extensions: ['js', 'jsx', 'ts', 'tsx'],
}),
new HotModuleReplacementPlugin(), // Hot reloading enabled with hot field in webpack dev-server
],
devtool: 'inline-source-map',
devServer: {
static: path.join(__dirname, 'dist'),
historyApiFallback: true, // Enables direct route-loading in combination with output public-path
port: 3000,
open: true,
hot: true,
},
};
export default config;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment