js13k-vite-plugins
Collection of Vite plugins and utilities for js13k games.
Included tools:
Example project: https://github.com/codyebberson/js13k-starter
Table of Contents
Getting Started
From Template
Go to the js13k-starter repository and click "Use this template" to create a new repository with the same files and folders as the template.
Clone the new repository and install the dependencies:
git clone git@github.com:your-username/js13k-starter.git
cd js13k-starter
npm install
Then run the development server:
npm run dev
From Scratch
First, setup a new Vite project: https://vitejs.dev/guide/#scaffolding-your-first-vite-project
npm create vite@latest
Next, add js13k-vite-plugins
:
npm install --save-dev js13k-vite-plugins
Then update your Vite configuration as needed. See below for example Vite configurations.
Example Configurations
Example vite.config.ts
files
Use All Recommendations
Use js13kViteConfig()
for a quick and easy default configuration (recommended).
import { js13kViteConfig } from "js13k-vite-plugins";
import { defineConfig } from "vite";
export default defineConfig(js13kViteConfig());
Disable Plugins
Some plugins can be disabled individually by passing false
for the options.
- Disable Roadroller by passing
roadrollerOptions: false
- Disable Advzip by passing
advzipOptions: false
For example, disable Roadroller:
import { js13kViteConfig } from "js13k-vite-plugins";
import { defineConfig } from "vite";
export default defineConfig(
js13kViteConfig({
roadrollerOptions: false,
})
);
Override Specific Settings
Pass in options to configure specific plugins.
For example, change the Advzip shrink level to "fast" (from default "insane").
import { js13kViteConfig } from "js13k-vite-plugins";
import { defineConfig } from "vite";
export default defineConfig(
js13kViteConfig({
advzipOptions: {
shrinkLevel: "fast",
},
})
);
Use Plugins Individually
Use the individual plugins for more control over the build.
import {
advzipPlugin,
ectPlugin,
getDefaultViteBuildOptions,
roadrollerPlugin,
} from "js13k-vite-plugins";
import { defineConfig } from "vite";
export default defineConfig({
build: getDefaultViteBuildOptions(),
plugins: [roadrollerPlugin(), ectPlugin(), advzipPlugin()],
});
Options
The top level options is a collection of options for the various sub-plugins.
export interface JS13KOptions {
viteOptions?: BuildOptions;
terserOptions?: Terser.MinifyOptions;
rollupOptions?: RollupOptions;
htmlMinifyOptions?: HtmlMinifyOptions;
roadrollerOptions?: RoadrollerOptions;
ectOptions?: EctOptions;
advzipOptions?: AdvzipOptions;
}
Vite Options
Base package: vite
Full Vite documentation: https://vitejs.dev/config/build-options.html
Default options:
export const defaultViteBuildOptions: BuildOptions = {
target: "esnext",
minify: "terser",
cssCodeSplit: false,
modulePreload: {
polyfill: false,
},
terserOptions: defaultTerserOptions,
rollupOptions: defaultRollupOptions,
};
Terser Options
Base package: terser
Full Terser documentation: https://terser.org/docs/options/
Default options:
export const defaultTerserOptions: Terser.MinifyOptions = {
compress: {
ecma: 2020 as ECMA,
module: true,
passes: 3,
unsafe_arrows: true,
unsafe_comps: true,
unsafe_math: true,
unsafe_methods: true,
unsafe_proto: true,
},
mangle: {
module: true,
toplevel: true,
},
format: {
comments: false,
ecma: 2020 as ECMA,
},
module: true,
toplevel: true,
};
Rollup Options
Base package: rollup
Full Rollup documentation: https://rollupjs.org/configuration-options/
Default options:
export const defaultRollupOptions: RollupOptions = {
output: {
inlineDynamicImports: true,
manualChunks: undefined,
},
};
HTML Minify Options
Base package: html-minifier-terser
Full HTML Minify documentation: https://github.com/terser/html-minifier-terser
Default options:
export const defaultHtmlMinifyOptions: HtmlMinifyOptions = {
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,
};
Imagemin Options
Base package: imagemin
params | type | default | default |
---|
verbose | boolean | true | Whether to output the compressed result in the console |
filter | RegExp or (file: string) => boolean | - | Specify which resources are not compressed |
disable | boolean | false | Whether to disable |
svgo | object or false | - | See Options |
gifsicle | object or false | - | See Options |
mozjpeg | object or false | - | See Options |
optipng | object or false | - | See Options |
pngquant | object or false | - | See Options |
webp | object or false | - | See Options |
Roadroller Options
Base package: roadroller
Full Roadroller documentation: https://lifthrasiir.github.io/roadroller/
This plugin uses the Roadroller defaults.
ECT Options
Base package: ect-bin
ECT documentation: https://github.com/fhanau/Efficient-Compression-Tool/blob/master/doc/Manual.docx (Google Docs)
export interface EctOptions {
quiet?: boolean;
level?: number;
strip?: boolean;
keep?: boolean;
strict?: boolean;
}
Default options:
export const defaultEctOptions: EctOptions = {
level: 10009,
strip: true,
};
Advzip Options
Base package: advzip-bin
Full Advzip documentation: https://linux.die.net/man/1/advzip
TypeScript interface:
export interface AdvzipOptions {
pedantic?: boolean;
shrinkLevel?:
| 0
| 1
| 2
| 3
| 4
| "store"
| "fast"
| "normal"
| "extra"
| "insane";
}
Default options:
export const defaultAdvzipOptions: AdvzipOptions = {
shrinkLevel: "insane",
};
Acknowledgements
Kang Seonghoon for Roadroller
Rob Louie for Roadroller configuration recommendations
Salvatore Previti for Terser configuration recommendations
License
MIT