Skip to content

Commit

Permalink
move playground to rsbuild! now fast reloads!
Browse files Browse the repository at this point in the history
reload on workers change

fix cd
  • Loading branch information
zardoy committed Sep 10, 2024
1 parent 18bf1aa commit f9b87d5
Show file tree
Hide file tree
Showing 10 changed files with 171 additions and 184 deletions.
5 changes: 4 additions & 1 deletion .github/workflows/next-deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,10 @@ jobs:
run: vercel build --token=${{ secrets.VERCEL_TOKEN }}
- run: pnpm build-storybook
- name: Copy playground files
run: pnpm build-playground && cp prismarine-viewer/public/index.html .vercel/output/static/playground.html && cp prismarine-viewer/public/playground.js .vercel/output/static/playground.js
run: |
mkdir -p .vercel/output/static/playground
pnpm build-playground
cp -r prismarine-viewer/dist/* .vercel/output/static/playground/
- name: Download Generated Sounds map
run: node scripts/downloadSoundsMap.mjs
- name: Deploy Project Artifacts to Vercel
Expand Down
5 changes: 4 additions & 1 deletion .github/workflows/preview.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,10 @@ jobs:
run: vercel build --token=${{ secrets.VERCEL_TOKEN }}
- run: pnpm build-storybook
- name: Copy playground files
run: pnpm build-playground && cp prismarine-viewer/public/index.html .vercel/output/static/playground.html && cp prismarine-viewer/public/playground.js .vercel/output/static/playground.js
run: |
mkdir -p .vercel/output/static/playground
pnpm build-playground
cp -r prismarine-viewer/dist/* .vercel/output/static/playground/
- name: Download Generated Sounds map
run: node scripts/downloadSoundsMap.mjs
- name: Deploy Project Artifacts to Vercel
Expand Down
5 changes: 4 additions & 1 deletion .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,10 @@ jobs:
- run: vercel build --token=${{ secrets.VERCEL_TOKEN }} --prod
- run: pnpm build-storybook
- name: Copy playground files
run: pnpm build-playground && cp prismarine-viewer/public/index.html .vercel/output/static/playground.html && cp prismarine-viewer/public/playground.js .vercel/output/static/playground.js
run: |
mkdir -p .vercel/output/static/playground
pnpm build-playground
cp -r prismarine-viewer/dist/* .vercel/output/static/playground/
- name: Download Generated Sounds map
run: node scripts/downloadSoundsMap.mjs
- name: Deploy Project to Vercel
Expand Down
13 changes: 6 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,8 @@
"dev-rsbuild": "rsbuild dev",
"dev-proxy": "node server.js",
"start": "run-p dev-rsbuild dev-proxy watch-mesher",
"start-watch-script": "nodemon -w rsbuild.config.ts --watch",
"build": "rsbuild build",
"build-analyze": "BUNDLE_ANALYZE=true rsbuild build",
"build": "pnpm build-other-workers && rsbuild build",
"build-analyze": "BUNDLE_ANALYZE=true rsbuild build && pnpm build-other-workers",
"check-build": "tsx scripts/genShims.ts && tsc && pnpm build",
"test:cypress": "cypress run",
"test-unit": "vitest",
Expand All @@ -20,13 +19,13 @@
"build-storybook": "storybook build && node scripts/build.js moveStorybookFiles",
"start-experiments": "vite --config experiments/vite.config.ts --host",
"watch-other-workers": "echo NOT IMPLEMENTED",
"build-other-workers": "echo NOT IMPLEMENTED",
"build-mesher": "node prismarine-viewer/buildMesherWorker.mjs",
"watch-mesher": "pnpm build-mesher -w",
"run-playground": "run-p watch-mesher watch-other-workers playground-server watch-playground",
"run-playground": "run-p watch-mesher watch-other-workers watch-playground",
"run-all": "run-p start run-playground",
"playground-server": "live-server --port=9090 prismarine-viewer/public",
"build-playground": "node prismarine-viewer/esbuild.mjs",
"watch-playground": "node prismarine-viewer/esbuild.mjs -w"
"build-playground": "rsbuild build --root ./prismarine-viewer",
"watch-playground": "rsbuild dev --root ./prismarine-viewer"
},
"keywords": [
"prismarine",
Expand Down
8 changes: 4 additions & 4 deletions prismarine-viewer/buildMesherWorker.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ const buildOptions = {
sourcemap: 'linked',
write: false,
metafile: true,
outdir: path.join(__dirname, './public'),
outdir: path.join(__dirname, './dist'),
define: {
'process.env.BROWSER': '"true"',
},
Expand Down Expand Up @@ -108,9 +108,9 @@ const buildOptions = {
})
build.onEnd(({ metafile, outputFiles }) => {
if (!metafile) return
fs.mkdirSync(path.join(__dirname, './public'), { recursive: true })
fs.writeFileSync(path.join(__dirname, './public/metafile.json'), JSON.stringify(metafile))
for (const outDir of ['../dist/', './public/']) {
fs.mkdirSync(path.join(__dirname, './dist'), { recursive: true })
fs.writeFileSync(path.join(__dirname, './dist/metafile.json'), JSON.stringify(metafile))
for (const outDir of ['../dist/', './dist/']) {
for (const outputFile of outputFiles) {
if (outDir === '../dist/' && outputFile.path.endsWith('.map')) {
// skip writing & browser loading sourcemap there, worker debugging should be done in playground
Expand Down
96 changes: 0 additions & 96 deletions prismarine-viewer/esbuild.mjs

This file was deleted.

2 changes: 1 addition & 1 deletion prismarine-viewer/playground.html
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,6 @@
</style>
</head>
<body>
<script type="text/javascript" src="playground.js"></script>
<div id="root"></div>
</body>
</html>
37 changes: 37 additions & 0 deletions prismarine-viewer/rsbuild.config.ts
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),
},
},
})
)
100 changes: 100 additions & 0 deletions prismarine-viewer/rsbuildSharedConfig.ts
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/
]

}
Loading

0 comments on commit f9b87d5

Please sign in to comment.