Add minification to build
This commit is contained in:
parent
e6e3a38328
commit
ed9ddd5e89
|
|
@ -12,8 +12,10 @@
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@types/bun": "latest",
|
"@types/bun": "latest",
|
||||||
|
"@types/html-minifier": "4.0.5",
|
||||||
"@types/inquirer": "9.0.7",
|
"@types/inquirer": "9.0.7",
|
||||||
"bun-lightningcss": "0.2.0",
|
"bun-lightningcss": "0.2.0",
|
||||||
|
"html-minifier": "4.0.0",
|
||||||
"inquirer": "9.3.4",
|
"inquirer": "9.3.4",
|
||||||
"typescript": "5.5.2"
|
"typescript": "5.5.2"
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -5,7 +5,7 @@
|
||||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||||
<title>$TITLE$</title>
|
<title>$TITLE$</title>
|
||||||
<style>
|
<style>
|
||||||
html, body, #c {
|
html, body, #canvas {
|
||||||
width: 100vw;
|
width: 100vw;
|
||||||
height: 100vh;
|
height: 100vh;
|
||||||
margin: 0;
|
margin: 0;
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,9 @@
|
||||||
import path from 'path';
|
import path from 'path';
|
||||||
|
import { minify } from 'html-minifier';
|
||||||
|
|
||||||
import dataUrlPlugin from './dataUrlPlugin';
|
import dataUrlPlugin from './dataUrlPlugin';
|
||||||
import lightningcss from 'bun-lightningcss';
|
import lightningcss from 'bun-lightningcss';
|
||||||
|
|
||||||
import { getGames } from './isGame';
|
import { getGames } from './isGame';
|
||||||
|
|
||||||
export async function buildHTML(game: string, production = false) {
|
export async function buildHTML(game: string, production = false) {
|
||||||
|
|
@ -23,9 +25,15 @@ export async function buildHTML(game: string, production = false) {
|
||||||
|
|
||||||
if (bundle.success && bundle.outputs.length === 1) {
|
if (bundle.success && bundle.outputs.length === 1) {
|
||||||
const script = await bundle.outputs[0].text();
|
const script = await bundle.outputs[0].text();
|
||||||
return html
|
const resultHTML = html
|
||||||
.replace('$SCRIPT$', `<script>${script}</script>`)
|
.replace('$SCRIPT$', `<script>${script}</script>`)
|
||||||
.replace('$TITLE$', game[0].toUpperCase() + game.slice(1).toLowerCase());
|
.replace('$TITLE$', game[0].toUpperCase() + game.slice(1).toLowerCase());
|
||||||
|
|
||||||
|
return minify(resultHTML, {
|
||||||
|
collapseWhitespace: true,
|
||||||
|
decodeEntities: true,
|
||||||
|
minifyCSS: true,
|
||||||
|
});
|
||||||
} else {
|
} else {
|
||||||
console.error('Multiple assets: ', bundle.outputs, 'or fail: ', !bundle.success, bundle);
|
console.error('Multiple assets: ', bundle.outputs, 'or fail: ', !bundle.success, bundle);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue