Вот готовый конфиги
webpack.config.js
const path = require('path')
const HtmlWebpackPlugin = require('html-webpack-plugin')
const MiniCssExtractPlugin = require('mini-css-extract-plugin')
const { CleanWebpackPlugin } = require('clean-webpack-plugin')
module.exports = {
mode: 'production',
entry: ['@babel/polyfill', path.resolve(__dirname, 'src/index.tsx')],
output: {
filename: 'js/vm.js',
path: path.resolve(__dirname, 'dist')
},
devtool: process.env.NODE_ENV === 'development' ? 'source-map' : false,
devServer: {
port: 3000,
historyApiFallback: true,
open: true
},
target: 'web',
resolve: {
extensions: ['.tsx', '.ts', '.jsx', '.js']
},
performance: {
hints: false
},
plugins: [
new HtmlWebpackPlugin({
template: path.resolve(__dirname, 'public/index.html'),
filename: 'index.html'
}),
new MiniCssExtractPlugin({
filename: 'css/style.css'
}),
new CleanWebpackPlugin()
],
module: {
rules: [
{
test: /\.(tsx|ts)$/,
exclude: /node_modules/,
use: ['ts-loader']
},
{
test: /\.(jsx|js)$/,
exclude: /node_modules/,
use: ['babel-loader']
},
{
test: /\.(css|scss|sass)$/,
use: [MiniCssExtractPlugin.loader, 'css-loader', 'sass-loader']
},
{
test: /\.(pdf|png|jpeg|jpg|svg)$/,
use: [
{
loader: 'file-loader',
options: {
name: '/assets/[name].[ext]'
}
}
]
}
]
}
}
tsconfig.json
{
"compilerOptions": {
"target": "es6",
"lib": [
"dom",
"dom.iterable",
"esnext"
],
"allowJs": true,
"skipLibCheck": true,
"esModuleInterop": true,
"allowSyntheticDefaultImports": true,
"strict": true,
"forceConsistentCasingInFileNames": true,
"noFallthroughCasesInSwitch": true,
"module": "esnext",
"moduleResolution": "node",
"resolveJsonModule": true,
"isolatedModules": false,
"noEmit": false,
"jsx": "react-jsx"
},
"include": [
"src"
]
}
.babelbr
{
"presets": ["@babel/preset-env", "@babel/preset-react", "@babel/preset-typescript"]
}
пакеты
"devDependencies": {
"@babel/core": "^7.19.3",
"@babel/polyfill": "^7.12.1",
"@babel/preset-env": "^7.19.4",
"@babel/preset-react": "^7.18.6",
"@babel/preset-typescript": "^7.18.6",
"babel-loader": "^8.2.5",
"clean-webpack-plugin": "^4.0.0",
"css-loader": "^6.7.1",
"file-loader": "^6.2.0",
"html-webpack-plugin": "^5.5.0",
"mini-css-extract-plugin": "^2.6.1",
"ts-loader": "^9.4.1",
"typescript": "^4.8.4",
"webpack": "^5.74.0",
"webpack-cli": "^4.10.0",
"webpack-dev-server": "^4.11.1"
}