import path from "path";
import HtmlWebpackPlugin from "html-webpack-plugin";
import TsconfigPathsPlugin from "tsconfig-paths-webpack-plugin";
import MiniCssExtractPlugin from "mini-css-extract-plugin";
import dotenv from "dotenv";
dotenv.config();
const absolutePath = (relativePath: string) =>
path.resolve(__dirname, relativePath);
module.exports = {
mode: process.env.MODE,
entry: {
index: "src/index.ts",
main: "src/main.ts"
},
output: {
filename: "[name].js",
path: absolutePath("dist"),
},
module: {
rules: [
{
test: /\.ts$/,
include: [absolutePath("src")],
use: "ts-loader",
},
{
test: /\.js$/,
enforce: "pre",
use: "source-map-loader",
},
{
test: /\.css$/,
use: [MiniCssExtractPlugin.loader, "css-loader"],
},
],
},
resolve: {
extensions: [".ts", "..."],
plugins: [new TsconfigPathsPlugin()],
},
devtool:
process.env.MODE === "development"
? "eval-cheap-module-source-map"
: undefined,
plugins: [
new HtmlWebpackPlugin({
template: "src/templates/index.html",
favicon: "static/favicon.ico",
filelename: "index.html",
showErrors: true,
excludeChunks: ["main"],
}),
new HtmlWebpackPlugin({
template: "src/templates/main.html",
favicon: "static/favicon.ico",
filename: "main.html",
showErrors: true,
excludeChunks: ["index"],
}),
new MiniCssExtractPlugin(),
],
node: {
global: true,
},
devServer: {
// contentBase: absolutePath("static"),
compress: true,
port: 8000,
liveReload: true,
hot: false,
allowedHosts: "all",
client: {
overlay: true,
},
host: "0.0.0.0",
headers: {
"Access-Control-Allow-Origin": "*",
}
},
};