Build System
Relevant source files
The following files were used as context for generating this wiki page:
The HoloPrint build system is a Node.js-based pipeline designed to transform source code from the src directory into a production-ready dist directory. It utilizes a combination of modern web development tools to handle asset minification, JavaScript bundling, and versioning. The system is specifically tailored to handle the unique requirements of the HoloPrint application, such as processing Molang scripts and Minecraft-related JSON formats.
The pipeline ensures that the final output is optimized for performance by minifying HTML, CSS, and JSON, while also managing source maps for debugging. It also handles the injection of version numbers and environment flags, such as setting the production mode in the application logic.
Sources: pipeline/build.js:1-12, pipeline/package.json:1-10
Pipeline Architecture
The build process follows a structured sequence that begins with preparing a temporary environment and ends with a finalized distribution folder.
The diagram above illustrates the high-level flow of the build script, moving from source preparation to the final bundling and asset replacement phase.
Sources: pipeline/build.js:23-55
Core Build Components
Pipeline Dependencies
The build system relies on several specialized libraries defined in the pipeline's configuration:
| Tool | Purpose |
|---|---|
esbuild | Primary JavaScript and CSS bundler with minification capabilities. |
lightningcss | Handles CSS transformation, bundling, and minification. |
html-minifier-next | Compresses HTML files and handles inline CSS/JS. |
jsonminify | Strips comments and whitespace from JSON and .material files. |
browserslist | Defines target browser support for CSS transformations. |
Sources: pipeline/package.json:7-14, pipeline/build.js:4-8
File Processing Logic
The system identifies and processes files based on their extension using the findProcessingFunction helper. Each file type undergoes specific transformations:
- HTML: Minified with comments removed. It also processes JSON within
<script>tags (importmaps and LD+JSON) and minifies inline CSS. - CSS: Processed via
lightningcssfor bundling and minification according tobrowserslisttargets. - JavaScript: Replaces the
IN_PRODUCTIONflag fromfalsetotrue. InHoloPrint.js, the version string is updated fromdevto the current build version. - JSON/Materials: Minified using
jsonminifyto reduce payload size.
Sources: pipeline/build.js:89-106, pipeline/build.js:145-164
Bundling and Asset Management
Esbuild Configuration
The esbuild step is the final stage of JavaScript and CSS consolidation. It targets temp/index.js and temp/styles/index.css as entry points.
let { metafile } = esbuild.buildSync({
absWorkingDir: process.cwd(),
entryPoints: ["temp/index.js", "temp/styles/index.css"],
bundle: true,
external: externalModules,
dropLabels: ["TS"],
minify: true,
format: "esm",
outdir: distDir,
entryNames: "[dir]/[name]-[hash]",
assetNames: "[dir]/[name]-[hash]",
loader: {
".molang.js": "copy",
".css": "copy"
},
sourcemap: true,
metafile: true
});
Sources: pipeline/build.js:34-52
Versioning and Environment Flags
The build script accepts command-line arguments to customize the build output. The --version= parameter sets the application version, while the IN_PRODUCTION constant in src/index.js is programmatically flipped to enable production-specific optimizations or logging behaviors.
| Constant/Flag | Source File | Build Action |
|---|---|---|
VERSION | src/HoloPrint.js | Replaced with build version string. |
IN_PRODUCTION | src/index.js | Replaced from false to true. |
--export-holoprint-lib | Command Line | Injects export * from "./HoloPrint.js"; into index.js. |
Sources: pipeline/build.js:15-18, pipeline/build.js:146-155, src/HoloPrint.js:19, src/index.js:17
Distribution Finalization
After bundling, the system performs a cleanup of the temp directory and finalizes the dist folder. A critical final step is updating the importmap in index.html. Since esbuild appends hashes to filenames for cache busting (e.g., index-ABC123.js), the build script reads the metafile generated by esbuild to map original entry point names to their new hashed counterparts and updates the HTML references accordingly.
Sources: pipeline/build.js:53-85, pipeline/build.js:180-188
The build system ensures that the HoloPrint web application is optimized for deployment while maintaining the complex logic required to interface with Minecraft Bedrock Edition's resource pack structures.