Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
pterodactyl
GitHub Repository: pterodactyl/panel
Path: blob/1.0-develop/webpack.config.js
10277 views
1
const path = require('node:path');
2
const webpack = require('webpack');
3
const { WebpackAssetsManifest } = require('webpack-assets-manifest');
4
const TerserPlugin = require('terser-webpack-plugin');
5
6
const isProduction = process.env.NODE_ENV === 'production';
7
8
module.exports = {
9
cache: true,
10
target: 'web',
11
mode: isProduction ? 'production' : 'development',
12
devtool: process.env.DEVTOOL || (isProduction ? false : 'eval-source-map'),
13
performance: {
14
hints: false,
15
},
16
entry: ['react-hot-loader/patch', './resources/scripts/index.tsx'],
17
output: {
18
path: path.join(__dirname, '/public/assets'),
19
filename: isProduction ? 'bundle.[chunkhash:8].js' : 'bundle.[fullhash:8].js',
20
chunkFilename: isProduction ? '[name].[chunkhash:8].js' : '[name].[fullhash:8].js',
21
publicPath: process.env.WEBPACK_PUBLIC_PATH || '/assets/',
22
crossOriginLoading: 'anonymous',
23
},
24
module: {
25
rules: [
26
{
27
test: /\.tsx?$/,
28
exclude: /node_modules|\.spec\.tsx?$/,
29
loader: 'babel-loader',
30
},
31
{
32
test: /\.mjs$/,
33
include: /node_modules/,
34
type: 'javascript/auto',
35
},
36
{
37
test: /\.css$/,
38
use: [
39
{ loader: 'style-loader' },
40
{
41
loader: 'css-loader',
42
options: {
43
modules: {
44
auto: true,
45
// https://github.com/webpack/css-loader/blob/main/CHANGELOG.md#700-2024-04-04
46
namedExport: false,
47
exportLocalsConvention: 'as-is',
48
localIdentName: isProduction ? '[name]_[hash:base64:8]' : '[path][name]__[local]',
49
localIdentContext: path.join(__dirname, 'resources/scripts/components'),
50
},
51
sourceMap: !isProduction,
52
importLoaders: 1,
53
},
54
},
55
{
56
loader: 'postcss-loader',
57
options: { sourceMap: !isProduction },
58
},
59
],
60
},
61
{
62
test: /\.(png|jp(e?)g|gif)$/,
63
loader: 'file-loader',
64
options: {
65
name: 'images/[name].[hash:8].[ext]',
66
},
67
},
68
{
69
test: /\.(woff|woff2)$/i,
70
type: 'asset/resource',
71
},
72
{
73
test: /\.svg$/,
74
loader: 'svg-url-loader',
75
},
76
{
77
test: /\.js$/,
78
enforce: 'pre',
79
loader: 'source-map-loader',
80
},
81
],
82
},
83
stats: {
84
// Ignore warnings emitted by "source-map-loader" when trying to parse source maps from
85
// JS plugins we use, namely brace editor.
86
warningsFilter: [/Failed to parse source map/],
87
},
88
resolve: {
89
extensions: ['.ts', '.tsx', '.js', '.json'],
90
alias: {
91
'@': path.join(__dirname, '/resources/scripts'),
92
'@definitions': path.join(__dirname, '/resources/scripts/api/definitions'),
93
'@feature': path.join(__dirname, '/resources/scripts/components/server/features'),
94
},
95
symlinks: false,
96
},
97
externals: {
98
// Mark moment as an external to exclude it from the Chart.js build since we don't need to use
99
// it for anything.
100
moment: 'moment',
101
},
102
plugins: [
103
new webpack.EnvironmentPlugin({
104
NODE_ENV: process.env.NODE_ENV || 'development',
105
DEBUG: process.env.NODE_ENV !== 'production',
106
WEBPACK_BUILD_HASH: Date.now().toString(16),
107
}),
108
new WebpackAssetsManifest({
109
output: 'manifest.json',
110
writeToDisk: true,
111
publicPath: true,
112
integrity: true,
113
integrityHashes: ['sha384'],
114
}),
115
],
116
optimization: {
117
usedExports: true,
118
sideEffects: false,
119
runtimeChunk: false,
120
removeEmptyChunks: true,
121
minimize: isProduction,
122
minimizer: [
123
new TerserPlugin({
124
parallel: true,
125
extractComments: false,
126
terserOptions: {
127
mangle: true,
128
output: {
129
comments: false,
130
},
131
},
132
}),
133
],
134
},
135
watchOptions: {
136
poll: 1000,
137
ignored: /node_modules/,
138
},
139
devServer: {
140
compress: true,
141
port: 5173,
142
server: {
143
type: 'https',
144
options: process.env.USE_LOCAL_CERTS
145
? {
146
ca: path.join(__dirname, '../../docker/certificates/root_ca.pem'),
147
cert: path.join(__dirname, '../../docker/certificates/pterodactyl.test.pem'),
148
key: path.join(__dirname, '../../docker/certificates/pterodactyl.test-key.pem'),
149
}
150
: undefined,
151
},
152
static: {
153
directory: path.join(__dirname, '/public'),
154
publicPath: process.env.WEBPACK_PUBLIC_PATH || '/assets/',
155
},
156
allowedHosts: ['.pterodactyl.test'],
157
headers: {
158
'Access-Control-Allow-Origin': '*',
159
},
160
},
161
};
162
163