zucchetti-sa5/webpack.config.js

82 lines
2.8 KiB
JavaScript
Raw Permalink Normal View History

const path = require("path")
const HtmlWebpackPlugin = require("html-webpack-plugin")
const MiniCssExtractPlugin = require("mini-css-extract-plugin")
const TsconfigPathsPlugin = require("tsconfig-paths-webpack-plugin")
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]",
path: path.resolve(__dirname, "dist"),
clean: true,
publicPath: '/',
2022-10-26 22:39:54 +02:00
sourceMapFilename: "[name].[contenthash:10].js.map"
},
devtool: "source-map",
devServer: {
historyApiFallback: true
},
module: {
rules: [
{
test: /\.tsx?$/,
loader: 'ts-loader',
exclude: /node_modules|\.d\.ts$/
},
{
test: /\.d\.ts$/,
loader: 'ignore-loader'
},
{
test: /\.jsx?$/,
include: path.resolve(__dirname, 'src'),
exclude: /node_modules/,
use: {
loader: 'babel-loader',
options: {
presets: [
['@babel/preset-env', { "targets": "defaults" }],
'@babel/preset-react'
]
}
}
},
{
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",
],
}
]
},
resolve: {
extensions: [".tsx", ".ts", ".jsx", ".js"],
alias: {
"@mui/styles": path.resolve(__dirname, "node_modules", "@mui/styles"),
},
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'
})])
}
}