67 lines
1.7 KiB
TypeScript
67 lines
1.7 KiB
TypeScript
import * as path from "path";
|
|
import ForkTsCheckerWebpackPlugin from "fork-ts-checker-webpack-plugin";
|
|
import ReactRefreshWebpackPlugin from "@pmmmwh/react-refresh-webpack-plugin";
|
|
import HtmlWebpackPlugin from "html-webpack-plugin";
|
|
import webpack from "webpack";
|
|
import Dotenv from "dotenv-webpack";
|
|
|
|
const isDevelopment = process.env.NODE_ENV !== "production";
|
|
|
|
const config: webpack.Configuration = {
|
|
mode: isDevelopment ? "development" : "production",
|
|
entry: "./client/index.tsx",
|
|
output: {
|
|
filename: "bundle.js",
|
|
path: path.resolve(__dirname, "dist/client"),
|
|
},
|
|
resolve: {
|
|
extensions: [".tsx", ".ts", ".js", ".mjs"],
|
|
modules: [path.join(__dirname, "./client"), "node_modules"],
|
|
},
|
|
module: {
|
|
rules: [
|
|
{
|
|
test: /\.css$/i,
|
|
use: ["style-loader", "css-loader"],
|
|
},
|
|
{
|
|
test: /\.hbs$/,
|
|
loader: "handlebars-loader",
|
|
},
|
|
{
|
|
test: /\.(mjs|js|jsx|ts|tsx)$/,
|
|
exclude: /node_modules/,
|
|
use: {
|
|
loader: "babel-loader",
|
|
options: {
|
|
cacheDirectory: true,
|
|
babelrc: true,
|
|
},
|
|
},
|
|
},
|
|
],
|
|
},
|
|
plugins: [
|
|
new Dotenv(),
|
|
new ForkTsCheckerWebpackPlugin({
|
|
async: false,
|
|
eslint: {
|
|
files: "./client/**/*.{ts,tsx,js,jsx}",
|
|
},
|
|
typescript: { configFile: "client/tsconfig.json" },
|
|
}),
|
|
new HtmlWebpackPlugin({
|
|
template: "client/index.hbs",
|
|
}),
|
|
isDevelopment && new ReactRefreshWebpackPlugin(),
|
|
].filter(Boolean),
|
|
devServer: {
|
|
hot: true,
|
|
contentBase: "./dist/client",
|
|
overlay: true,
|
|
},
|
|
devtool: isDevelopment ? "inline-source-map" : undefined,
|
|
};
|
|
|
|
export default config;
|