-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwebpack.config.cjs
More file actions
166 lines (164 loc) · 4.91 KB
/
webpack.config.cjs
File metadata and controls
166 lines (164 loc) · 4.91 KB
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
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
const path = require("path");
const webpack = require("webpack");
const TerserPlugin = require("terser-webpack-plugin");
module.exports = {
mode: process.env.NODE_ENV === "production" ? "production" : "development",
entry: "./src/index.ts",
output: {
path: path.resolve(__dirname, "dist/browser"),
filename: "shogun-core.js",
library: {
name: "ShogunCore",
type: "umd",
},
globalObject: "this",
// Add clean webpack plugin configuration
clean: true,
},
// Make Gun external to avoid bundling issues
externals: {
gun: "Gun",
"gun/gun": "Gun",
"gun/gun.js": "Gun",
"gun/sea": "Gun.SEA",
"gun/sea.js": "Gun.SEA",
"gun/lib/then": "Gun",
"gun/lib/then.js": "Gun",
"gun/lib/radix": "Gun",
"gun/lib/radix.js": "Gun",
"gun/lib/radisk": "Gun",
"gun/lib/radisk.js": "Gun",
"gun/lib/store": "Gun",
"gun/lib/store.js": "Gun",
"gun/lib/rindexed": "Gun",
"gun/lib/rindexed.js": "Gun",
"gun/lib/webrtc": "Gun",
"gun/lib/webrtc.js": "Gun",
},
resolve: {
extensions: [".ts", ".js", ".json"],
alias: {
// Explicit aliases for Gun.js modules
gun$: path.resolve(__dirname, "node_modules/gun/gun.js"),
"gun/gun": path.resolve(__dirname, "node_modules/gun/gun.js"),
"gun/sea": path.resolve(__dirname, "node_modules/gun/sea.js"),
gun: path.resolve(__dirname, "node_modules/gun"),
// Fix axios process/browser requirement
"process/browser": require.resolve("process/browser"),
},
fallback: {
crypto: require.resolve("crypto-browserify"),
stream: require.resolve("stream-browserify"),
buffer: require.resolve("buffer"),
util: require.resolve("util"),
os: require.resolve("os-browserify"),
path: require.resolve("path-browserify"),
vm: require.resolve("vm-browserify"),
assert: require.resolve("assert/"),
constants: require.resolve("constants-browserify"),
gun: path.resolve(__dirname, "node_modules/gun/gun.js"),
"gun/gun": path.resolve(__dirname, "node_modules/gun/gun.js"),
"gun/sea": path.resolve(__dirname, "node_modules/gun/sea.js"),
zlib: false, // winston/file.js - not needed in browser
// Add Node.js core modules that should be ignored in browser builds
http: false,
https: false,
fs: false,
net: false,
tls: false,
child_process: false,
ws: false,
readline: false, // CLI-only module
// Add fallback for neo4j (used by cypher-query)
"neo4j/lib/GraphDatabase": false,
},
},
module: {
rules: [
{
test: /\.ts$/,
use: "ts-loader",
exclude: /node_modules/,
},
],
},
plugins: [
new webpack.ProvidePlugin({
Buffer: ["buffer", "Buffer"],
process: "process/browser",
}),
// Remove the IgnorePlugin for Gun since we want to bundle it
// new webpack.IgnorePlugin({
// resourceRegExp: /gun\/(sea|lib)$/,
// contextRegExp: /node_modules/,
// }),
// Ignore Node.js modules that are not available in browser
new webpack.IgnorePlugin({
resourceRegExp: /^(http|https|fs|net|tls|child_process|ws)$/,
contextRegExp: /node_modules/,
}),
// Ignore Gun.js ws.js file that imports Node.js ws module
new webpack.IgnorePlugin({
resourceRegExp: /gun\/lib\/ws\.js$/,
contextRegExp: /node_modules/,
}),
// Add module concatenation plugin for better tree-shaking
new webpack.optimize.ModuleConcatenationPlugin(),
// Define Gun as a global variable
new webpack.DefinePlugin({
"typeof window": '"object"',
}),
// Provide Gun as a global variable (not needed since Gun is external)
// new webpack.ProvidePlugin({
// Gun: "gun",
// }),
],
optimization: {
minimize: process.env.NODE_ENV === "production",
minimizer: [
new TerserPlugin({
terserOptions: {
compress: {
drop_console: process.env.NODE_ENV === "production",
drop_debugger: true,
},
},
}),
],
splitChunks: {
chunks: "async",
minSize: 20000,
maxSize: 200000,
minChunks: 1,
maxAsyncRequests: 30,
maxInitialRequests: 30,
automaticNameDelimiter: "~",
enforceSizeThreshold: 50000,
cacheGroups: {
defaultVendors: {
test: /[\\/]node_modules[\\/]/,
priority: -10,
reuseExistingChunk: true,
},
default: {
minChunks: 2,
priority: -20,
reuseExistingChunk: true,
},
},
},
},
performance: {
maxEntrypointSize: 1000000, // Increased to 1MB
maxAssetSize: 1000000, // Increased to 1MB
hints: "warning",
},
// Add source map for better debugging
devtool: "source-map",
stats: {
warningsFilter: [
/the request of a dependency is an expression/,
/Critical dependency: the request of a dependency is an expression/,
],
},
};