-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathwebpack.config.js
132 lines (127 loc) · 3.28 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
const path = require('path');
const { EnvironmentPlugin } = require('webpack');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const { CleanWebpackPlugin } = require('clean-webpack-plugin');
const MiniCssExtractPlugin = require('mini-css-extract-plugin');
const isProd = process.env.NODE_ENV === 'production';
module.exports = {
mode: isProd ? 'production' : 'development',
devtool: isProd ? 'source-map' : 'eval-source-map',
entry: './src/index.tsx',
output: {
filename: 'js/[name].[contenthash].js',
path: path.resolve(__dirname, 'dist'),
},
optimization: {
// needed to avoid the hash changing when it should not
// https://developers.google.com/web/fundamentals/performance/webpack/use-long-term-caching#webpack_runtime_code
runtimeChunk: 'multiple',
splitChunks: {
// all so not only dynamic imports are considered
chunks: 'all',
maxInitialRequests: Infinity,
minSize: 0,
cacheGroups: {
npm: {
test: /[\\/]node_modules[\\/]/,
name(module) {
// split at the package or scope level
const directories = module.context.split(path.sep);
const name = directories[directories.lastIndexOf('node_modules') + 1];
return `npm.${name}`;
},
},
},
},
},
module: {
rules: [
{
test: /\.(?:svg|fnt|png)$/,
use: [
{
loader: 'file-loader',
options: {
outputPath: 'assets',
},
},
],
},
{
test: /\.(?:fnt)$/,
use: [
{
loader: 'extract-loader',
options: {
publicPath: '../',
},
},
{ loader: 'ref-loader' },
],
},
{
test: /\.tsx?$/,
use: [
{
loader: 'babel-loader',
options: {
presets: [
['@babel/preset-env', {
useBuiltIns: 'usage',
corejs: 3,
}],
'@babel/preset-react',
],
},
},
'ts-loader',
],
exclude: /node_modules/,
},
{
test: /\.css$/i,
use: [MiniCssExtractPlugin.loader, 'css-loader'],
},
],
},
resolve: {
alias: {
src: path.resolve(__dirname, 'src/'),
static: path.resolve(__dirname, 'static/'),
},
extensions: ['.tsx', '.ts', '.js'],
},
plugins: [
new EnvironmentPlugin({
'SENTRY_DSN': null,
}),
new MiniCssExtractPlugin(),
new CleanWebpackPlugin(),
new HtmlWebpackPlugin({
template: 'src/index.ejs',
// https://github.com/jantimon/html-webpack-plugin/tree/0a6568d587a82d88fd3a0617234ca98d26a1e0a6/examples/custom-insertion-position
// inject has to be false because we add the headTags and bodyTags manually in ejs (to position them in the best spot)
inject: false,
title: 'BombHopper.io\'s Level Editor',
meta: {
viewport: 'width=device-width, initial-scale=1, user-scalable=no',
description: 'Create and edit your BombHopper.io levels!',
keywords: 'bombhopperio, bombhopper, bomb hopper, bomb hopper io, platformer, level, editor, creator, maker',
'twitter:card': 'summary',
'twitter:creator:id': '1166876286',
},
xhtml: true,
}),
],
devServer: {
compress: true,
liveReload: false, // prevent the fucker from stealing the focus
host: '0.0.0.0',
client: {
overlay: {
warnings: false, // these warnings can be ignored, but not removed yet https://github.com/michalochman/react-pixi-fiber/issues/279
errors: true,
},
},
},
};