-
Notifications
You must be signed in to change notification settings - Fork 0
/
webpack.config.js
107 lines (96 loc) · 2.82 KB
/
webpack.config.js
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
const path = require('path');
const webpack = require('webpack');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const TerserJSPlugin = require('terser-webpack-plugin');
const CnameWebpackPlugin = require('cname-webpack-plugin');
const settings = require('./settings');
const mode = process.env.NODE_ENV === 'production' ? 'production' : 'development';
const entry = path.join(__dirname, './src/index.tsx');
const port = 8262;
const output = path.join(__dirname, './dist');
const publicPath = mode === 'production' ? settings.repoPath || '/' : '/';
module.exports = {
mode,
optimization: {
minimizer: [new TerserJSPlugin({})],
runtimeChunk: 'single',
},
devServer: {
port,
compress: true,
hot: true,
historyApiFallback: true,
open: true,
},
devtool: mode === 'production' ? false : 'eval',
entry:
mode === 'production'
? entry
: [
`webpack-dev-server/client?http://localhost:${port}`,
'webpack/hot/only-dev-server',
entry,
],
output: {
path: output,
filename: '[name].js',
publicPath,
},
resolve: {
modules: [path.join(__dirname, './node_modules')],
extensions: ['.js', '.jsx', '.ts', '.tsx'],
},
module: {
rules: [
{
test: /\.(ts|tsx|js|jsx)$/,
exclude: /node_modules/,
include: path.join(__dirname, './src'),
use: 'ts-loader',
},
{
test: /\.(svg|png|jpg|gif|woff|woff2|otf|ttf|eot)$/,
type: 'asset/resource',
},
{
test: /\.css$/i,
use: ['style-loader', 'css-loader', 'postcss-loader', 'sass-loader'],
},
{
test: /node_modules\/https-proxy-agent\//,
use: 'null-loader',
},
],
},
plugins: [
new webpack.DefinePlugin({
'process.env': {
NODE_ENV: JSON.stringify(mode),
},
}),
new HtmlWebpackPlugin({
favicon: path.join(__dirname, './favicon.png'),
templateContent: ({ htmlWebpackPlugin }) => `
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>${settings.title}</title>
</head>
<body class="bg-gray-800">
<noscript>
Enable JavaScript to use Frontend toolbox
</noscript>
<div id="app"></div>
${htmlWebpackPlugin.tags.bodyTags}
</body>
</html>
`,
}),
...(mode !== 'production'
? [new webpack.HotModuleReplacementPlugin()]
: [...(settings.cname ? [new CnameWebpackPlugin({ domain: settings.cname })] : [])]),
],
};