forked from pyrohost/panel
-
Notifications
You must be signed in to change notification settings - Fork 0
/
webpack.config.js
169 lines (163 loc) · 5.6 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
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
const path = require('path');
const webpack = require('webpack');
const AssetsManifestPlugin = require('webpack-assets-manifest');
const ForkTsCheckerWebpackPlugin = require('fork-ts-checker-webpack-plugin');
const BundleAnalyzerPlugin = require('webpack-bundle-analyzer').BundleAnalyzerPlugin;
const TerserPlugin = require('terser-webpack-plugin');
const isProduction = process.env.NODE_ENV === 'production';
const typeChecking = process.env.TYPE_CHECKING !== 'false';
module.exports = {
resolve: {
extensions: ['.js', '.jsx', '.json', '.ts', '.tsx'],
fallback: {
fs: require.resolve('fs'),
os: require.resolve('os-browserify/browser'),
path: require.resolve('path-browserify'),
},
},
cache: true,
target: 'web',
mode: isProduction ? 'production' : 'development',
devtool: isProduction ? false : process.env.DEVTOOL || 'eval-source-map',
performance: {
hints: false,
},
entry: ['./resources/scripts/index.tsx'],
output: {
path: path.join(__dirname, '/public/assets'),
filename: 'bundle.js', // Simplify filename for development
publicPath: process.env.WEBPACK_PUBLIC_PATH || '/assets/',
crossOriginLoading: 'anonymous',
pathinfo: false,
},
module: {
rules: [
{
test: /\.tsx?$/,
exclude: /node_modules|\.spec\.tsx?$/,
use: {
loader: 'babel-loader',
options: {
cacheDirectory: true,
},
},
},
// Doesn't work sadly cause our packages need to be polyfilled
// and webpack doesn't feel like doing that ???
// {
// // Match `.js`, `.jsx`, `.ts` or `.tsx` files
// test: /\.[jt]sx?$/,
// exclude: /node_modules|\.spec\.tsx?$/,
// loader: 'esbuild-loader',
// options: {
// // JavaScript version to compile to
// target: 'es2015',
// },
// },
// Why do we need to transpile node_modules? Removing this doesn't
// break builds for me, but I'll keep it just in case. Should be
// faster with swc
{
test: /\.mjs$/,
include: /node_modules/,
type: 'javascript/auto',
// fails on production, works on dev
// use: {
// loader: 'swc-loader',
// options: {
// parseMap: true,
// },
// },
},
{
test: /\.css$/,
use: ['style-loader', 'css-loader', 'postcss-loader'], // Simplified CSS loader configuration
},
{
test: /\.(png|jp(e?)g|gif)$/,
loader: 'file-loader',
options: {
name: 'images/[name].[hash:8].[ext]',
},
},
{
test: /\.svg$/,
loader: 'svg-url-loader',
},
],
},
resolve: {
extensions: ['.ts', '.tsx', '.js', '.json'],
alias: {
'@': path.join(__dirname, '/resources/scripts'),
'@definitions': path.join(__dirname, '/resources/scripts/api/definitions'),
'@feature': path.join(__dirname, '/resources/scripts/components/server/features'),
},
symlinks: false,
},
externals: {
moment: 'moment',
},
plugins: [
new webpack.EnvironmentPlugin({
NODE_ENV: isProduction ? 'production' : 'development',
DEBUG: isProduction ? 'false' : 'true',
WEBPACK_BUILD_HASH: Date.now().toString(16),
}),
new AssetsManifestPlugin({ writeToDisk: true, publicPath: true, integrity: true, integrityHashes: ['sha384'] }),
typeChecking
? new ForkTsCheckerWebpackPlugin({
typescript: {
mode: 'write-references',
diagnosticOptions: {
semantic: true,
syntactic: true,
},
},
eslint: {
files: `${path.join(__dirname, '/resources/scripts')}/**/*.{ts,tsx}`,
},
})
: null,
process.env.ANALYZE_BUNDLE
? new BundleAnalyzerPlugin({
analyzerHost: '0.0.0.0',
analyzerPort: 8081,
})
: null,
].filter((p) => p),
optimization: {
usedExports: isProduction,
sideEffects: isProduction,
removeEmptyChunks: isProduction,
mergeDuplicateChunks: isProduction,
providedExports: isProduction,
concatenateModules: isProduction,
minimize: isProduction,
minimizer: [
new TerserPlugin({
extractComments: false,
terserOptions: {
compress: {
drop_console: true,
},
},
}),
],
},
watchOptions: {
poll: 1000,
ignored: /node_modules/,
},
devServer: {
hot: true,
port: 3000,
compress: true,
contentBase: path.join(__dirname, '/public'),
publicPath: process.env.WEBPACK_PUBLIC_PATH || '/assets/',
allowedHosts: ['.pterodactyl.test'],
headers: {
'Access-Control-Allow-Origin': '*',
},
},
};