Skip to content

Instantly share code, notes, and snippets.

@Luiyit
Created July 27, 2023 20:26
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 Luiyit/0e018c65c5a203706261e4ea14df6a01 to your computer and use it in GitHub Desktop.
Save Luiyit/0e018c65c5a203706261e4ea14df6a01 to your computer and use it in GitHub Desktop.
How to fix Webpack Dev Server HMR using WSL 2 (TypeScript)
import { Configuration as WebpackConfiguration } from "webpack";
import { Configuration as WebpackDevServerConfiguration } from 'webpack-dev-server';
import path from "path";
import HtmlWebpackPlugin from "html-webpack-plugin";
interface Configuration extends WebpackConfiguration {
devServer?: WebpackDevServerConfiguration;
}
const config = (): Configuration => ({
mode: "development",
entry: path.resolve(__dirname, "src", "index.tsx"),
output: {
path: path.resolve(__dirname, "dist"),
filename: "[name].js",
},
devServer: {
static: './dist',
},
/*
* From webpack docs
* If watching does not work for you, try out this option.
* This may help issues with NFS and machines in VirtualBox, WSL, Containers, or Docker.
* In those cases, use a polling interval and ignore large folders like /node_modules/ to keep CPU usage minimal.
*/
watchOptions: {
poll: 1000
},
module: {
rules: [{
test: /\.(ts|js)x?$/i,
exclude: [/node_modules/, /\.(spec|test).(ts|js)x?$/i],
loader: "babel-loader",
options: {
cacheDirectory: true,
cacheCompression: false,
compact: true,
}
}],
},
resolve: {
extensions: [".ts", ".tsx", ".js", ".jsx", ".json"],
alias: {
src: path.resolve(__dirname, "src"),
}
},
plugins: [
new HtmlWebpackPlugin({
title: "React App",
template: path.resolve(__dirname, "src", "index.html"),
}),
],
})
export default config;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment