forked from PrismarineJS/prismarine-web-client
-
Notifications
You must be signed in to change notification settings - Fork 57
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
move playground to rsbuild! now fast reloads!
reload on workers change fix cd
- Loading branch information
Showing
10 changed files
with
171 additions
and
184 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import { defineConfig, mergeRsbuildConfig } from '@rsbuild/core'; | ||
import supportedVersions from '../src/supportedVersions.mjs' | ||
import childProcess from 'child_process' | ||
import path, { dirname, join } from 'path' | ||
import { pluginReact } from '@rsbuild/plugin-react'; | ||
import { pluginNodePolyfill } from '@rsbuild/plugin-node-polyfill'; | ||
import fs from 'fs' | ||
import { appAndRendererSharedConfig, rspackViewerConfig } from './rsbuildSharedConfig'; | ||
|
||
const mcDataPath = join(__dirname, '../generated/minecraft-data-optimized.json') | ||
|
||
if (!fs.existsSync(mcDataPath)) { | ||
childProcess.execSync('tsx ./scripts/makeOptimizedMcData.mjs', { stdio: 'inherit', cwd: path.join(__dirname, '..') }) | ||
} | ||
|
||
export default mergeRsbuildConfig( | ||
appAndRendererSharedConfig(), | ||
defineConfig({ | ||
html: { | ||
template: './playground.html', | ||
}, | ||
output: { | ||
cleanDistPath: false, | ||
}, | ||
server: { | ||
port: 9090, | ||
}, | ||
source: { | ||
entry: { | ||
index: join(__dirname, './examples/playground.ts') | ||
}, | ||
define: { | ||
'globalThis.includedVersions': JSON.stringify(supportedVersions), | ||
}, | ||
}, | ||
}) | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
import { defineConfig, ModifyRspackConfigUtils } from '@rsbuild/core'; | ||
import { pluginNodePolyfill } from '@rsbuild/plugin-node-polyfill'; | ||
import { pluginReact } from '@rsbuild/plugin-react'; | ||
import path from 'path' | ||
|
||
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 | ||
}, | ||
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', // default is a lie | ||
}, | ||
}, | ||
server: { | ||
htmlFallback: false, | ||
publicDir: false, | ||
headers: { | ||
// enable shared array buffer | ||
'Cross-Origin-Opener-Policy': 'same-origin', | ||
'Cross-Origin-Embedder-Policy': 'require-corp', | ||
}, | ||
open: process.env.OPEN_BROWSER === 'true', | ||
}, | ||
plugins: [ | ||
pluginReact(), | ||
pluginNodePolyfill() | ||
], | ||
tools: { | ||
rspack (config, helpers) { | ||
rspackViewerConfig(config, helpers) | ||
} | ||
}, | ||
}) | ||
|
||
export const rspackViewerConfig = (config, { appendPlugins, addRules, rspack }: ModifyRspackConfigUtils) => { | ||
appendPlugins(new rspack.NormalModuleReplacementPlugin(/data/, (resource) => { | ||
let absolute: string | ||
const request = resource.request.replaceAll('\\', '/') | ||
absolute = path.join(resource.context, request).replaceAll('\\', '/') | ||
if (request.includes('minecraft-data/data/pc/1.')) { | ||
console.log('Error: incompatible resource', request, 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`) | ||
} | ||
})) | ||
addRules([ | ||
{ | ||
test: /\.obj$/, | ||
type: 'asset/source', | ||
}, | ||
{ | ||
test: /\.wgsl$/, | ||
type: 'asset/source', | ||
}, | ||
{ | ||
test: /\.mp3$/, | ||
type: 'asset/source', | ||
} | ||
]) | ||
config.ignoreWarnings = [ | ||
/the request of a dependency is an expression/, | ||
/Unsupported pseudo class or element: xr-overlay/ | ||
] | ||
|
||
} |
Oops, something went wrong.