This repository has been archived by the owner on Dec 11, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 8
/
webpack.config.js
129 lines (127 loc) · 4.2 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
const path = require('path');
const AssetsManifestPlugin = require('webpack-assets-manifest');
const ForkTsCheckerWebpackPlugin = require('fork-ts-checker-webpack-plugin');
const TerserPlugin = require('terser-webpack-plugin');
const BundleAnalyzerPlugin = require('webpack-bundle-analyzer').BundleAnalyzerPlugin;
const os = require('os')
const isProduction = process.env.NODE_ENV === 'production';
module.exports = {
cache: true,
target: 'web',
mode: process.env.NODE_ENV,
devtool: isProduction ? false : (process.env.DEVTOOL || 'eval-source-map'),
performance: {
hints: false,
},
entry: ['react-hot-loader/patch', './resources/scripts/index.tsx'],
output: {
path: path.join(__dirname, '/public/assets'),
filename: isProduction ? 'bundle.[chunkhash:8].js' : 'bundle.[hash:8].js',
chunkFilename: isProduction ? '[name].[chunkhash:8].js' : '[name].[hash:8].js',
publicPath: (process.env.WEBPACK_PUBLIC_PATH || '/assets/'),
crossOriginLoading: 'anonymous',
},
module: {
rules: [
{
test: /\.tsx?$/,
exclude: /node_modules/,
loader: 'babel-loader',
},
{
test: /\.css$/,
use: [ 'style-loader', 'css-loader' ],
},
{
test: /\.(png|jp(e?)g|gif)$/,
loader: 'file-loader',
options: {
name: 'images/[name].[hash:8].[ext]',
},
},
{
test: /\.svg$/,
loader: 'svg-url-loader',
},
{
test: /\.js$/,
enforce: 'pre',
loader: 'source-map-loader',
}
],
},
stats: {
// Ignore warnings emitted by "source-map-loader" when trying to parse source maps from
// JS plugins we use, namely brace editor.
warningsFilter: [/Failed to parse source map/],
},
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: {
// Mark moment as an external to exclude it from the Chart.js build since we don't need to use
// it for anything.
moment: 'moment',
},
plugins: [
new AssetsManifestPlugin({ writeToDisk: true, publicPath: true, integrity: true, integrityHashes: ['sha384'] }),
new ForkTsCheckerWebpackPlugin({
typescript: {
mode: 'write-references',
diagnosticOptions: {
semantic: true,
syntactic: true,
},
},
eslint: isProduction ? undefined : {
files: `${path.join(__dirname, '/resources/scripts')}/**/*.{ts,tsx}`,
}
}),
process.env.ANALYZE_BUNDLE ? new BundleAnalyzerPlugin({
analyzerHost: '0.0.0.0',
analyzerPort: 8081,
}) : null
].filter(p => p),
optimization: {
mergeDuplicateChunks: true,
usedExports: true,
sideEffects: false,
runtimeChunk: false,
removeEmptyChunks: true,
minimize: isProduction,
minimizer: [
new TerserPlugin({
cache: isProduction,
parallel: os.cpus().length,
extractComments: false,
terserOptions: {
mangle: true,
output: {
comments: false,
},
},
}),
],
},
watchOptions: {
poll: 1000,
ignored: /node_modules/,
},
devServer: {
compress: true,
contentBase: path.join(__dirname, '/public'),
publicPath: process.env.WEBPACK_PUBLIC_PATH || '/assets/',
allowedHosts: [
'.pterodactyl.test',
],
headers: {
'Access-Control-Allow-Origin': '*',
},
},
};