2022-10-13 09:50:30 +02:00
|
|
|
const path = require("path")
|
|
|
|
const HtmlWebpackPlugin = require("html-webpack-plugin")
|
|
|
|
const MiniCssExtractPlugin = require("mini-css-extract-plugin")
|
2022-10-13 17:06:43 +02:00
|
|
|
const TsconfigPathsPlugin = require("tsconfig-paths-webpack-plugin")
|
2022-10-13 09:50:30 +02:00
|
|
|
|
2022-10-13 17:06:43 +02:00
|
|
|
module.exports = (env, argv) => {
|
|
|
|
const devMode = argv.mode !== 'production'
|
|
|
|
|
|
|
|
return {
|
|
|
|
mode: devMode ? "development" : "production",
|
|
|
|
entry: {
|
|
|
|
bundle: path.resolve(__dirname, "src", "index.tsx")
|
|
|
|
},
|
|
|
|
output: {
|
2022-10-26 22:39:54 +02:00
|
|
|
filename: devMode ? "[name].[contenthash:10].js" : "[name.js]",
|
2022-10-13 17:06:43 +02:00
|
|
|
path: path.resolve(__dirname, "dist"),
|
2022-10-20 09:05:43 +02:00
|
|
|
clean: true,
|
2022-10-26 19:02:06 +02:00
|
|
|
publicPath: '/',
|
2022-10-26 22:39:54 +02:00
|
|
|
sourceMapFilename: "[name].[contenthash:10].js.map"
|
2022-10-20 09:05:43 +02:00
|
|
|
},
|
2022-10-26 19:02:06 +02:00
|
|
|
devtool: "source-map",
|
2022-10-20 09:05:43 +02:00
|
|
|
devServer: {
|
|
|
|
historyApiFallback: true
|
2022-10-13 17:06:43 +02:00
|
|
|
},
|
|
|
|
module: {
|
|
|
|
rules: [
|
|
|
|
{
|
|
|
|
test: /\.tsx?/,
|
|
|
|
use: 'ts-loader',
|
|
|
|
exclude: /node_modules/
|
|
|
|
},
|
|
|
|
{
|
|
|
|
test: /\.jsx?$/,
|
|
|
|
include: path.resolve(__dirname, 'src'),
|
|
|
|
exclude: /node_modules/,
|
|
|
|
use: {
|
|
|
|
loader: 'babel-loader',
|
|
|
|
options: {
|
|
|
|
presets: [
|
|
|
|
['@babel/preset-env', { "targets": "defaults" }],
|
|
|
|
'@babel/preset-react'
|
|
|
|
]
|
|
|
|
}
|
2022-10-13 09:50:30 +02:00
|
|
|
}
|
2022-10-13 17:06:43 +02:00
|
|
|
},
|
|
|
|
{
|
|
|
|
test: /\.(sa|sc|c)ss$/,
|
|
|
|
use: [
|
|
|
|
// Creates `style` nodes from JS strings
|
|
|
|
devMode ? 'style-loader' : MiniCssExtractPlugin.loader,
|
|
|
|
// Translates CSS into CommonJS
|
|
|
|
"css-loader",
|
|
|
|
// Compiles Sass to CSS
|
|
|
|
"sass-loader",
|
|
|
|
],
|
2022-10-14 16:15:13 +02:00
|
|
|
}
|
2022-10-13 17:06:43 +02:00
|
|
|
]
|
|
|
|
},
|
|
|
|
resolve: {
|
2022-10-27 09:24:07 +02:00
|
|
|
extensions: [".tsx", ".ts", ".jsx", ".js"],
|
2022-10-13 17:06:43 +02:00
|
|
|
alias: {
|
|
|
|
"@mui/styles": path.resolve(__dirname, "node_modules", "@mui/styles"),
|
2022-10-13 09:50:30 +02:00
|
|
|
},
|
2022-10-13 17:06:43 +02:00
|
|
|
plugins: [new TsconfigPathsPlugin()]
|
|
|
|
},
|
|
|
|
plugins: [
|
|
|
|
new HtmlWebpackPlugin({
|
|
|
|
template: path.join(__dirname, "src", "html", "template.html"),
|
|
|
|
filename: "index.html",
|
|
|
|
title: "React with Webpack",
|
|
|
|
}),
|
|
|
|
].concat(devMode ? [] : [new MiniCssExtractPlugin({
|
|
|
|
filename: '[name].css',
|
|
|
|
chunkFilename: '[id].css'
|
|
|
|
})])
|
|
|
|
}
|
2022-10-20 09:05:43 +02:00
|
|
|
}
|