-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwebpack.config.ts
More file actions
95 lines (91 loc) · 2.9 KB
/
webpack.config.ts
File metadata and controls
95 lines (91 loc) · 2.9 KB
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
93
94
95
import * as path from 'path';
import {Configuration as WebpackConfiguration} from "webpack";
import {Configuration as WebpackDevServerConfiguration} from "webpack-dev-server";
import HtmlWebpackPlugin from 'html-webpack-plugin';
import DotEnv from 'dotenv-webpack';
import {TsconfigPathsPlugin} from 'tsconfig-paths-webpack-plugin';
interface Configuration extends WebpackConfiguration {
devServer?: WebpackDevServerConfiguration;
}
process.env.TS_NODE_PROJECT = '';
const tsConfigPath = path.join(__dirname, 'src', 'tsconfig.json');
const IS_PROD = process.env.NODE_ENV === 'production';
const IS_DEV = !IS_PROD;
const plugins = [
new HtmlWebpackPlugin({
template: path.resolve(__dirname, './index.html'),
}),
new DotEnv({systemvars: true, path: path.join(__dirname, '.env')})
]
const config: Configuration = {
mode: IS_DEV ? 'development' : 'production',
devtool: 'source-map',
entry: path.join(__dirname, 'src', 'index.tsx'),
output: {
path: path.resolve('dist'),
filename: `assets/js/[name]-[contenthash:8]-bundle.js`,
chunkFilename: 'assets/js/[name]-[contenthash:8]-bundle.js',
publicPath: '/'
},
resolve: {
extensions: ['.js', '.ts', '.tsx'],
plugins: [new TsconfigPathsPlugin({configFile: tsConfigPath}) as any],
},
module: {
rules: [
{
test: /\.(ts|js)x?$/,
exclude: /node_modules/,
include: path.resolve(__dirname, 'src'),
use: {
loader: "babel-loader",
options: {
presets: [
"@babel/preset-env",
"@babel/preset-react",
"@babel/preset-typescript",
],
},
},
},
{
test: /.jpe?g$|.gif$|.png$|.svg$|.woff$|.woff2$|.ttf$/,
type: 'asset/inline'
},
{
test: /\.css$/i,
use: ['style-loader', 'css-loader'],
},
],
},
plugins,
optimization: {
minimize: !IS_DEV,
splitChunks: {
cacheGroups: {
vendors: {
test: /[\\/]node_modules[\\/]/,
name: 'vendors',
chunks: 'all',
priority: 10,
},
material: {
test: /[\\/]node_modules[\\/]@material-ui[\\/]/,
name: 'material-ui',
chunks: 'all',
priority: 20,
},
},
},
},
devServer: {
contentBase: path.join(__dirname, 'dist'),
port: 3001,
hot: true,
open: true,
clientLogLevel: "silent",
overlay: true,
historyApiFallback: true,
}
}
export default config