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