Skip to content

Commit

Permalink
readme
Browse files Browse the repository at this point in the history
  • Loading branch information
rndD committed Sep 24, 2024
1 parent c2555aa commit 1e3e2e7
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 103 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# JS13K games 2024 entry by @rndD
# This is postjam version of JS13K games 2024 entry by @rndD

js13kgames 2024 gamejam entry.
Theme: Triskaidekaphobia.
Check out the original entry [here](https://js13kgames.com/2024/games/data-warrior-13kb-limit)
This jam theme was : Triskaidekaphobia.

## Build with

Expand Down
101 changes: 1 addition & 100 deletions vite.config.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import { defineConfig, IndexHtmlTransformContext, Plugin } from "vite";
import { defineConfig, Plugin } from "vite";
import path from "path";
import fs from "fs/promises";
import typescriptPlugin from "@rollup/plugin-typescript";
import { OutputAsset, OutputChunk } from "rollup";
import { Input, InputAction, InputType, Packer } from "roadroller";
import CleanCSS from "clean-css";
import { statSync } from "fs";
const { execFileSync } = require("child_process");
Expand Down Expand Up @@ -49,111 +48,13 @@ export default defineConfig(({ command, mode }) => {
// @ts-ignore
config.plugins = [
typescriptPlugin(),
// closurePlugin(),
// roadrollerPlugin(),
// ectPlugin(),
];
}

return config;
});

function closurePlugin(): Plugin {
return {
name: "closure-compiler",
// @ts-ignore
renderChunk: applyClosure,
enforce: "post",
};
}

async function applyClosure(js: string, chunk: any) {
const tmpobj = tmp.fileSync();
// replace all consts with lets to save about 50-70 bytes
// ts-ignore
js = js.replaceAll("const ", "let ");

await fs.writeFile(tmpobj.name, js);
const closureCompiler = new ClosureCompiler({
js: tmpobj.name,
externs: "externs.js",
compilation_level: "ADVANCED",
language_in: "ECMASCRIPT_2021",
language_out: "ECMASCRIPT_2021",
assumeFunctionWrapper: true,
jscomp_off: "*",
// warning_level: 'VERBOSE',
});
return new Promise((resolve, reject) => {
closureCompiler.run((_exitCode: string, stdOut: string, stdErr: string) => {
if (stdOut !== "") {
resolve({ code: stdOut });
} else if (stdErr !== "") {
// only reject if stdout isn't generated
reject(stdErr);
return;
}

console.warn(stdErr); // If we make it here, there were warnings but no errors
});
});
}

function roadrollerPlugin(): Plugin {
return {
name: "vite:roadroller",
transformIndexHtml: {
enforce: "post",
transform: async (
html: string,
ctx?: IndexHtmlTransformContext
): Promise<string> => {
// Only use this plugin during build
if (!ctx || !ctx.bundle) {
return html;
}

const options = {
includeAutoGeneratedTags: true,
removeAttributeQuotes: true,
removeComments: true,
removeRedundantAttributes: true,
removeScriptTypeAttributes: true,
removeStyleLinkTypeAttributes: true,
sortClassName: true,
useShortDoctype: true,
collapseWhitespace: true,
collapseInlineTagWhitespace: true,
removeEmptyAttributes: true,
removeOptionalTags: true,
sortAttributes: true,
minifyCSS: true,
};

const bundleOutputs = Object.values(ctx.bundle);
const javascript = bundleOutputs.find((output) =>
output.fileName.endsWith(".js")
) as OutputChunk;
const css = bundleOutputs.find((output) =>
output.fileName.endsWith(".css")
) as OutputAsset;
const otherBundleOutputs = bundleOutputs.filter(
(output) => output !== javascript
);
if (otherBundleOutputs.length > 0) {
otherBundleOutputs.forEach((output) =>
console.warn(`WARN Asset not inlined: ${output.fileName}`)
);
}

const cssInHtml = css ? embedCss(html, css) : html;
const minifiedHtml = await htmlMinify.minify(cssInHtml, options);
return embedJs(minifiedHtml, javascript);
},
},
};
}

/**
* Transforms the given JavaScript code into a packed version.
* @param html The original HTML.
Expand Down

0 comments on commit 1e3e2e7

Please sign in to comment.