-
Notifications
You must be signed in to change notification settings - Fork 1
/
webpack.config.js
112 lines (105 loc) · 3.17 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
const path = require("path");
const fs = require("fs");
require("dotenv").config();
const ReactRefreshPlugin = require("@pmmmwh/react-refresh-webpack-plugin");
const ForkTsCheckerWebpackPlugin = require("fork-ts-checker-webpack-plugin");
const HtmlWebpackPlugin = require("html-webpack-plugin");
const CopyWebpackPlugin = require("copy-webpack-plugin");
const NodePolyfillPlugin = require("node-polyfill-webpack-plugin");
const { ProvidePlugin, DefinePlugin, optimize } = require("webpack");
const isDevelopment = process.env.NODE_ENV !== "production";
module.exports = {
mode: isDevelopment ? "development" : "production",
devServer: {
port: 3000,
client: { overlay: false },
},
entry: {
main: "./src/index.tsx",
},
module: {
rules: [
{
test: /\.(ts)x?$/,
exclude: /node_modules\/(?!(melonjs)\/).*/,
use: "babel-loader",
},
],
},
plugins: [
isDevelopment && new ReactRefreshPlugin(),
new ForkTsCheckerWebpackPlugin(),
new HtmlWebpackPlugin({
filename: "./index.html",
template: "./src/index.html",
hash: true,
}),
new CopyWebpackPlugin({
patterns: [
{
from: "./src/game/data",
to: "./data",
filter: async resourcePath => {
const data = await fs.promises.readFile(resourcePath);
// add your custom extension here if not listed
var texture = /\.(jpe?g|gif|png|svg|heic|pkm|pvr)$/;
var fnt = /\.(woff|woff2|ttf|fnt)$/;
var map = /\.(tmx|tsx)$/;
var audio =
/\.(wav|mp3|mpeg|opus|ogg|oga|wav|aac|caf|m4a|m4b|mp4|weba|webm|dolby|flac)$/;
var misc = /\.(xml|bin|glsl|ym|json|js|md|ico)$/;
// only copy production files
var ret =
texture.test(resourcePath) ||
fnt.test(resourcePath) ||
map.test(resourcePath) ||
audio.test(resourcePath) ||
misc.test(resourcePath);
if (ret === false) {
console.log("ignoring data: " + resourcePath);
}
return ret;
},
},
],
}),
new NodePolyfillPlugin({ excludeAliases: ["process"] }),
new ProvidePlugin({
Buffer: ["buffer", "Buffer"],
}),
new DefinePlugin({
"process.env": JSON.stringify(process.env),
"process.release.name": "your-mum",
}),
].filter(Boolean),
resolve: {
// modules: [path.resolve('./src'), path.resolve('./node_modules')],
extensions: [".tsx", ".ts", ".js", "..."],
fallback: {
util: require.resolve(`util/`),
url: require.resolve(`url/`),
assert: require.resolve(`assert/`),
tls: require.resolve("tls-browserify"),
net: require.resolve("net-browserify"),
async_hooks: false,
path: false,
fs: false,
},
symlinks: false,
},
target: "web",
devtool: "inline-source-map",
externals: {
bufferutil: "commonjs bufferutil",
"utf-8-validate": "commonjs utf-8-validate",
},
output: {
path: path.resolve(__dirname, "dist"),
filename: "[name].[contenthash].js",
},
optimization: {
splitChunks: {
chunks: "all",
},
},
};