-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathwebpack.config.ts
92 lines (88 loc) · 2.36 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
83
84
85
86
87
88
89
90
91
92
/* eslint-disable @typescript-eslint/no-var-requires */
import * as path from 'path';
import * as webpack from 'webpack';
import HtmlWebpackPlugin from 'html-webpack-plugin';
import MiniCssExtractPlugin from 'mini-css-extract-plugin';
import ReactRefreshWebpackPlugin from '@pmmmwh/react-refresh-webpack-plugin';
const __DEV__ =
(process.env.NODE_ENV as webpack.Configuration['mode']) || 'development';
const config: webpack.Configuration = {
mode: __DEV__,
entry: path.resolve(__dirname, './src/index.tsx'),
output: {
path: path.resolve(__dirname, './dist'),
filename: 'index_bundle.js',
},
plugins: [
new MiniCssExtractPlugin({
filename: '[name].[contenthash].css',
chunkFilename: '[id].[contenthash].css',
}),
new HtmlWebpackPlugin({ template: path.resolve('./public/index.html') }),
__DEV__ && new webpack.HotModuleReplacementPlugin(),
__DEV__ && new ReactRefreshWebpackPlugin(),
].filter(Boolean),
resolve: {
extensions: ['.tsx', '.ts', '.js'],
alias: {
react: path.join(__dirname, '../node_modules/react'),
'react-dom': path.join(__dirname, '../node_modules/react-dom'),
},
},
module: {
rules: [
{
test: /\.(sa|sc|c)ss$/,
use: [
MiniCssExtractPlugin.loader,
{
loader: '@teamsupercell/typings-for-css-modules-loader',
options: {
formatter: 'prettier',
},
},
{
loader: 'css-loader',
options: {
importLoaders: 1,
sourceMap: true,
modules: {
auto: true,
},
},
},
{
loader: 'sass-loader',
options: {
implementation: require('sass'),
sourceMap: true,
},
},
],
},
{
test: /\.tsx?$/,
use: [
__DEV__ && {
loader: 'babel-loader',
options: { plugins: ['react-refresh/babel'] },
},
'ts-loader',
].filter(Boolean),
exclude: /node_modules/,
},
{
test: /\.(woff2?|svg|ttf|otf|eot)$/,
loader: 'file-loader',
},
],
},
devtool: 'eval-cheap-module-source-map',
// @ts-ignore
devServer: {
compress: true,
port: 9000,
hot: true,
},
};
export default config;