-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
build: implement incremental build for esbuild
- Loading branch information
1 parent
c29f62a
commit 2b84ae1
Showing
5 changed files
with
204 additions
and
159 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,28 +1,18 @@ | ||
import * as fs from 'fs' | ||
import * as path from 'path' | ||
|
||
import * as esbuild from 'esbuild' | ||
|
||
import { gameSrcPath, serverBuildVersionPath, serverOutputPath } from './common' | ||
import { serverBuildOpts, writeServerBuildVersion } from './common' | ||
|
||
let buildVersion = '(none)' | ||
if (process.argv.length > 2) { | ||
buildVersion = process.argv[2] | ||
} | ||
async function main(): Promise<void> { | ||
let buildVersion = '(none)' | ||
if (process.argv.length > 2) { | ||
buildVersion = process.argv[2] | ||
} | ||
|
||
console.log(`Creating bundle for build version ${buildVersion}...`) | ||
console.log(`Creating bundle for build version ${buildVersion}...`) | ||
|
||
esbuild.buildSync({ | ||
bundle: true, | ||
entryPoints: [path.join(gameSrcPath, 'server', 'main.ts')], | ||
outdir: serverOutputPath, | ||
platform: 'node', | ||
sourcemap: true, | ||
target: 'es2019', | ||
}) | ||
await esbuild.build(serverBuildOpts) | ||
|
||
await writeServerBuildVersion(buildVersion) | ||
} | ||
|
||
// Write build version | ||
fs.mkdirSync(path.normalize(path.join(serverBuildVersionPath, '..')), { | ||
recursive: true, | ||
}) | ||
fs.writeFileSync(serverBuildVersionPath, buildVersion) | ||
main() |
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 |
---|---|---|
@@ -1,56 +1,18 @@ | ||
import * as fs from 'fs' | ||
import * as path from 'path' | ||
|
||
import * as esbuild from 'esbuild' | ||
|
||
import { | ||
gameSrcPath, | ||
webEntrypoints, | ||
webEphemeralPath, | ||
webOutputPath, | ||
} from './common' | ||
|
||
let buildVersion = '(none)' | ||
if (process.argv.length > 2) { | ||
buildVersion = process.argv[2] | ||
} | ||
import { copyWebHtml, updateWebBuildVersion, webBuildOpts } from './common' | ||
|
||
console.log(`Creating bundle for build version ${buildVersion}...`) | ||
async function main(): Promise<void> { | ||
let buildVersion = '(none)' | ||
if (process.argv.length > 2) { | ||
buildVersion = process.argv[2] | ||
} | ||
|
||
// Write build version | ||
fs.mkdirSync(webEphemeralPath, { recursive: true }) | ||
fs.writeFileSync( | ||
path.join(webEphemeralPath, 'buildVersion.ts'), | ||
`export const buildVersion = '${buildVersion}'`, | ||
) | ||
console.log(`Creating bundle for build version ${buildVersion}...`) | ||
|
||
esbuild.buildSync({ | ||
bundle: true, | ||
define: { | ||
'process.env.NODE_ENV': '"production"', // for react-dom | ||
}, | ||
entryPoints: webEntrypoints.map((srcPath) => | ||
path.join(gameSrcPath, srcPath, 'main.ts'), | ||
), | ||
loader: { | ||
'.obj': 'text', | ||
'.gltf': 'json', | ||
}, | ||
minify: false, | ||
outdir: webOutputPath, | ||
sourcemap: true, | ||
target: ['chrome88', 'firefox84', 'safari14'], | ||
}) | ||
await updateWebBuildVersion(buildVersion) | ||
await esbuild.build(webBuildOpts) | ||
await copyWebHtml() | ||
} | ||
|
||
// Copy index.html files | ||
Promise.all( | ||
webEntrypoints.map(async (srcPath) => { | ||
await fs.promises.mkdir(path.join(webOutputPath, srcPath), { | ||
recursive: true, | ||
}) | ||
await fs.promises.copyFile( | ||
path.join(gameSrcPath, srcPath, 'index.html'), | ||
path.join(webOutputPath, srcPath, 'index.html'), | ||
) | ||
}), | ||
) | ||
main() |
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
Oops, something went wrong.