Created
January 9, 2022 22:43
-
-
Save rajeshdavidbabu/f3047a3da21aebdd552109503e759d0a to your computer and use it in GitHub Desktop.
Webpack dev config for React TS Project
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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