-
Notifications
You must be signed in to change notification settings - Fork 0
/
webpack.config.ts
82 lines (76 loc) · 2.2 KB
/
webpack.config.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
import ReactRefreshWebpackPlugin from '@pmmmwh/react-refresh-webpack-plugin';
import { CleanWebpackPlugin } from 'clean-webpack-plugin';
import HtmlWebPackPlugin from 'html-webpack-plugin';
import * as path from 'path';
import * as webpack from 'webpack';
import { Configuration as WebpackDevServerConfiguration } from 'webpack-dev-server';
const MiniCssExtractPlugin = require('mini-css-extract-plugin');
interface Configuration extends webpack.Configuration {
devServer?: WebpackDevServerConfiguration;
}
export default (env: any, { mode }: { mode: 'production' | 'development' }) => {
const isProduction = mode === 'production';
const isDevelopment = !isProduction;
const config: Configuration = {
entry: './src/index.tsx',
output: {
path: path.resolve(__dirname, 'dist'),
filename: 'bundle.[contenthash].js',
},
module: {
rules: [
{
test: /\.[jt]sx?$/,
exclude: /node_modules/,
use: [
{
loader: 'babel-loader',
options: {
plugins: [
isDevelopment && require.resolve('react-refresh/babel'),
].filter(Boolean),
},
},
],
},
{
test: /\.css$/,
use: [
{
loader: isDevelopment
? 'style-loader'
: MiniCssExtractPlugin.loader,
},
{ loader: 'css-loader' },
{ loader: 'postcss-loader' },
],
},
],
},
plugins: [
new HtmlWebPackPlugin({
template: path.resolve(__dirname, 'src', 'index.html'),
}),
new CleanWebpackPlugin(),
new MiniCssExtractPlugin({
filename: '[name].[contenthash].css',
}),
isDevelopment && new ReactRefreshWebpackPlugin(),
].filter(Boolean) as any,
resolve: {
extensions: ['.js', '.jsx', '.ts', '.tsx'],
alias: {
'@project': path.resolve(__dirname, 'src'),
},
},
devServer: {
contentBase: path.join(__dirname, 'dist'),
port: 9000,
historyApiFallback: true,
hot: true,
clientLogLevel: 'none',
compress: true,
},
};
return config;
};