Skip to content

Commit

Permalink
add contributing, speed start, cleanup esbuild
Browse files Browse the repository at this point in the history
and don't use minify in dev as it breaks breakpoints since minify inlines code
  • Loading branch information
zardoy committed Sep 19, 2023
1 parent 962b689 commit c6b78c3
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 20 deletions.
14 changes: 14 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# Contributing Guide

After forking the repository, run the following commands to get started:

0. Ensure you have [Node.js](https://nodejs.org) and `pnpm` installed. To install pnpm run `npm i -g pnpm`.
1. Install dependencies: `pnpm i`
2. Start the project in development mode: `pnpm start`

A few notes:

- It's recommended to use debugger for debugging. VSCode has a great debugger built-in. If debugger is slow, you can use `--no-sources` flag that would allow browser to speedup .map file parsing.
- Some data are cached between restarts. If you see something doesn't work after upgrading dependencies, try to clear the by simply removing the `dist` folder.
- The same folder `dist` is used for both development and production builds, so be careful when deploying the project.
- Use `start-prod` script to start the project in production mode after running `build` script to build the project.
23 changes: 4 additions & 19 deletions esbuild.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,8 @@ import { clients, plugins } from './scripts/esbuildPlugins.mjs'
import { generateSW } from 'workbox-build'
import { getSwAdditionalEntries } from './scripts/build.js'

/** @type {import('esbuild').BuildOptions} */
let baseConfig = {}

// // testing config
// baseConfig = {
// entryPoints: ['files/index.js'],
// outfile: 'out.js',
// outdir: undefined,
// }

try {
//@ts-ignore
await import('./localSettings.mjs')
} catch { }
//@ts-ignore
try { await import('./localSettings.mjs') } catch { }

fs.writeFileSync('dist/index.html', fs.readFileSync('index.html', 'utf8').replace('<!-- inject script -->', '<script src="index.js"></script>'), 'utf8')

Expand Down Expand Up @@ -53,7 +41,6 @@ const ctx = await esbuild.context({
'browser', 'module', 'main'
],
keepNames: true,
...baseConfig,
banner: {
js: banner.join('\n'),
},
Expand All @@ -73,10 +60,8 @@ const ctx = await esbuild.context({
'./src/shims.js'
],
metafile: true,
plugins: [
...plugins,
...baseConfig.plugins ?? [],
],
plugins,
sourcesContent: process.argv.includes('--no-sources'),
minify: process.argv.includes('--minify'),
define: {
'process.env.NODE_ENV': JSON.stringify(dev ? 'development' : 'production'),
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"version": "0.0.0-dev",
"description": "A minecraft client running in a browser",
"scripts": {
"start": "node scripts/build.js copyFilesDev && node scripts/prepareData.mjs && node esbuild.mjs --minify --watch",
"start": "node scripts/build.js copyFilesDev && node scripts/prepareData.mjs && node esbuild.mjs --watch",
"start-watch-script": "nodemon -w esbuild.mjs esbuild.mjs",
"build": "node scripts/build.js copyFiles && node scripts/prepareData.mjs && node esbuild.mjs --minify --prod",
"watch": "node scripts/build.js copyFilesDev && webpack serve --config webpack.dev.js --progress",
Expand Down
6 changes: 6 additions & 0 deletions scripts/prepareData.mjs
Original file line number Diff line number Diff line change
@@ -1,8 +1,14 @@
//@ts-check
import { build } from 'esbuild'
import { existsSync } from 'node:fs'
import Module from "node:module"
import { dirname } from 'node:path'

if (existsSync('dist/mc-data')) {
console.log('using cached prepared data')
process.exit(0)
}

const require = Module.createRequire(import.meta.url)

const dataPaths = require('minecraft-data/minecraft-data/data/dataPaths.json')
Expand Down

0 comments on commit c6b78c3

Please sign in to comment.