-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathwebpack.config.ts
129 lines (121 loc) · 3.89 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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
const webpack = require('webpack');
const { WebpackPluginServe: Serve } = require('webpack-plugin-serve');
const CopyWebpackPlugin = require('copy-webpack-plugin');
// @ts-ignore false redeclare warning
const path = require('path');
const ReactLoadablePlugin = require('react-loadable/webpack').ReactLoadablePlugin;
const HTMLWebpackPlugin = require('html-webpack-plugin');
const MiniCssExtractPlugin = require('mini-css-extract-plugin');
const CssMinimizerPlugin = require('css-minimizer-webpack-plugin');
const TerserPlugin = require('terser-webpack-plugin');
const Dotenv = require('dotenv-webpack');
// @TODO: do not this lol
const isProduction = (process.env.NODE_ENV || 'development') === 'production';
module.exports = {
entry: path.resolve(__dirname, 'src/index.tsx'),
output: {
publicPath: '/',
path: path.resolve(__dirname, 'dist'),
filename: '[name].bundle.js',
chunkFilename: '[name].chunk.js',
},
mode: isProduction ? 'production' : 'development',
devtool: 'source-map',
resolve: {
extensions: ['.ts', '.tsx', '.js', '.jsx'],
modules: [path.resolve('src'), path.resolve('node_modules')],
fallback: {
"buffer": require.resolve("buffer"),
"path": require.resolve("path"),
},
},
devServer: {
contentBase: 'dist',
host: 'localhost',
port: 8080,
noInfo: true,
hot: false,
stats: 'errors-only',
historyApiFallback: true,
writeToDisk: false,
},
stats: {
warnings: false,
},
optimization: {
minimize: isProduction,
minimizer: [
new TerserPlugin(),
new CssMinimizerPlugin(),
],
splitChunks: {
chunks: 'all',
minSize: 10000,
},
},
module: {
rules: [
{
test: /\.tsx?$/,
use: ['babel-loader', 'ts-loader'],
include: [path.resolve(__dirname, 'src')],
},
{
test: /\.css$/,
use: [MiniCssExtractPlugin.loader, 'css-loader', 'postcss-loader', 'resolve-url-loader'],
},
{
test: /\.s(a|c)ss$/,
use: [MiniCssExtractPlugin.loader, 'css-loader', 'resolve-url-loader', 'sass-loader'],
},
{
test: /\.(woff|woff2)$/,
loader: 'url-loader',
options: {
name: 'fonts/[hash].[ext]',
limit: 5000,
mimetype: 'application/font-woff',
},
},
{
test: /\.(ttf|eot|svg)$/,
loader: 'file-loader',
options: {
name: 'fonts/[hash].[ext]',
module: false,
},
},
{
test: /\.(jpg|png|gif)$/,
loader: 'file-loader',
options: {
name: 'assets/[name].[hash].[ext]',
module: false,
},
},
],
},
plugins: [
new CopyWebpackPlugin({
patterns: [
{ from: path.resolve(__dirname, 'src/img'), to: './img' },
{ from: path.resolve(__dirname, 'src/assets'), to: './assets' },
{ from: path.resolve(__dirname, 'src/assets/icons'), to: './icons' },
]
}),
new HTMLWebpackPlugin({
template: path.resolve(__dirname, 'src/index.html'),
}),
new MiniCssExtractPlugin({ filename: '[name].css' }),
new Dotenv({
systemvars: true,
}),
new webpack.ProvidePlugin({
process: 'process/browser',
}),
new Serve({ static: path.resolve(__dirname, 'dist'), host: 'localhost', port: 8080 })
],
externals: {
fs: {},
},
};