forked from PrismarineJS/prismarine-web-client
-
Notifications
You must be signed in to change notification settings - Fork 199
Expand file tree
/
Copy pathrsbuildSharedConfig.ts
More file actions
130 lines (128 loc) · 4.69 KB
/
Copy pathrsbuildSharedConfig.ts
File metadata and controls
130 lines (128 loc) · 4.69 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
import { defineConfig, ModifyRspackConfigUtils } from '@rsbuild/core';
import { pluginNodePolyfill } from '@rsbuild/plugin-node-polyfill';
import { pluginReact } from '@rsbuild/plugin-react';
import path from 'path'
import fs from 'fs'
export const appAndRendererSharedConfig = () => defineConfig({
dev: {
progressBar: true,
writeToDisk: true,
watchFiles: {
paths: [
// path.join(__dirname, './dist/webgpuRendererWorker.js'),
// path.join(__dirname, './dist/mesher.js'),
]
},
},
output: {
polyfill: 'usage',
// 50kb limit for data uri
dataUriLimit: 50 * 1024,
assetPrefix: './',
},
source: {
alias: {
fs: path.join(__dirname, `./src/shims/fs.js`),
http: 'http-browserify',
stream: 'stream-browserify',
net: 'net-browserify',
'minecraft-protocol$': 'minecraft-protocol/src/index.js',
'buffer$': 'buffer',
// avoid bundling, not used on client side
'prismarine-auth': path.join(__dirname, `./src/shims/prismarineAuthReplacement.ts`),
perf_hooks: path.join(__dirname, `./src/shims/perf_hooks_replacement.js`),
crypto: path.join(__dirname, `./src/shims/crypto.js`),
dns: path.join(__dirname, `./src/shims/dns.js`),
yggdrasil: path.join(__dirname, `./src/shims/yggdrasilReplacement.ts`),
'three$': 'three/src/Three.js',
'stats.js$': 'stats.js/src/Stats.js',
},
define: {
'process.platform': '"browser"',
},
decorators: {
version: 'legacy',
},
},
server: {
htmlFallback: false,
// publicDir: false,
headers: {
// enable shared array buffer
'Cross-Origin-Opener-Policy': 'same-origin',
'Cross-Origin-Embedder-Policy': 'require-corp',
// Match prod static servers: subresources/workers under COEP need CORP in dev.
'Cross-Origin-Resource-Policy': 'cross-origin',
},
open: process.env.OPEN_BROWSER === 'true',
},
plugins: [
pluginReact(),
pluginNodePolyfill()
],
tools: {
rspack (config, helpers) {
const packageJson = JSON.parse(fs.readFileSync(path.join(__dirname, './package.json'), 'utf8'))
const hasFileProtocol = Object.values(packageJson.pnpm.overrides).some((dep) => (dep as string).startsWith('file:'))
if (hasFileProtocol) {
// enable node_modules watching
config.watchOptions.ignored = /\.git/
}
rspackViewerConfig(config, helpers)
}
},
})
export const rspackViewerConfig = (config, { appendPlugins, addRules, rspack }: ModifyRspackConfigUtils) => {
appendPlugins(new rspack.NormalModuleReplacementPlugin(/data|prismarine-physics/, (resource) => {
let absolute: string
const request = resource.request.replaceAll('\\', '/')
absolute = path.join(resource.context, request).replaceAll('\\', '/')
if (request.includes('minecraft-data/data/pc/1.') || request.includes('prismarine-physics')) {
console.log('Error: incompatible resource', request, 'from', resource.contextInfo.issuer)
process.exit(1)
// throw new Error(`${resource.request} was requested by ${resource.contextInfo.issuer}`)
}
if (absolute.endsWith('/minecraft-data/data.js')) {
resource.request = path.join(__dirname, `./src/shims/minecraftData.ts`)
}
if (absolute.endsWith('/minecraft-data/data/bedrock/common/legacy.json')) {
resource.request = path.join(__dirname, `./src/shims/empty.ts`)
}
if (absolute.endsWith('/minecraft-data/data/pc/common/legacy.json')) {
resource.request = path.join(__dirname, `./src/preflatMap.json`)
}
}))
addRules([
{
test: /\.obj$/,
type: 'asset/source',
},
{
test: /\.wgsl$/,
type: 'asset/source',
},
{
test: /\.mp3$/,
type: 'asset/source',
},
{
test: /\.txt$/,
type: 'asset/source',
},
{
test: /\.log$/,
type: 'asset/source',
},
{
test: /\.gltf$/,
type: 'asset/resource',
}
])
config.ignoreWarnings = [
/the request of a dependency is an expression/,
/Unsupported pseudo class or element: xr-overlay/
]
if (process.env.SINGLE_FILE_BUILD === 'true') {
config.module!.parser!.javascript!.dynamicImportMode = 'eager'
}
}