@studiokloek/vite-config 0.13.1 → 0.14.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -1,16 +1,121 @@
1
- # vite-config
2
- Externalize our vitejs config setup, so we can use it in multiple projects. Right now built for internal use, maybe useful for the world later...
1
+ # @studiokloek/vite-config
3
2
 
4
- # Installation
3
+ Shared Vite config and CLI for the Studio Kloek game projects: handlebars pages per game, Svelte, SCSS, legacy
4
+ bundles, image optimisation, web manifests and, when configured, the sprites/sounds pipeline of
5
+ [`@studiokloek/vite-assets-plugin`](https://github.com/studiokloek/vite-assets-plugin).
6
+
7
+ Built for internal use; it expects our project layout.
8
+
9
+ ## Install
10
+
11
+ ```sh
12
+ pnpm add -D @studiokloek/vite-config
13
+ pnpm approve-builds # sharp, and ffmpeg-static when you use kloekAssets
5
14
  ```
6
- npm i @studiokloek/vite-config --save-dev
15
+
16
+ Node 22.19 or newer.
17
+
18
+ Games import packages that come in through `@studiokloek/ts-core-lib` and this package (pixi, capacitor, howler,
19
+ `vite/client`, …) without declaring them. With pnpm, hoist everything like yarn did, in the game's
20
+ `pnpm-workspace.yaml`:
21
+
22
+ ```yaml
23
+ shamefullyHoist: true
7
24
  ```
8
25
 
9
- # Usage
26
+ ## Usage
27
+
28
+ ```jsonc
29
+ // package.json
30
+ "scripts": {
31
+ "development": "kloek-development",
32
+ "build": "kloek-build --create-zip --base=/games/2025/"
33
+ }
10
34
  ```
11
- npm run kloek-development
12
- npm run kloek-build --empty-output-dir --base "https://example.com/test"
35
+
36
+ `kloek-development [--mode <mode>]` starts the dev server. `kloek-build` builds into `public/`:
37
+
38
+ | Flag | |
39
+ |---|---|
40
+ | `-b, --base <path>` | base path (default: `vite.build.basePath`) |
41
+ | `-m, --mode <mode>` | Vite mode (default: `production`) |
42
+ | `-l, --log-level <level>` | `info`, `warn`, `error` or `silent` |
43
+ | `-e, --empty-out-dir` | empty `public/` first (default; `--no-empty-out-dir` keeps it) |
44
+ | `-s, --sourcemaps`, `-i, --inline-sourcemaps` | source maps (default: `vite.build.sourceMaps`) |
45
+ | `-z, --create-zip` | zip the build into `zips/` (default: `vite.build.createZip`) |
46
+
47
+ Flags you leave out take their value from `package.json`.
48
+
49
+ The same is available from code: `kloekBuild(options)`, `kloekDevelopment(options)` and
50
+ `defineKloekViteConfig(env)` for a `vite.config.ts`.
51
+
52
+ ## Project layout
53
+
54
+ ```
55
+ assets/ source assets for kloekAssets (tagged directories)
56
+ env/ .env files (KLOEK_* and VITE_* are exposed)
57
+ source/ Vite root
58
+ partials/ handlebars partials; game.hbs renders every game page
59
+ script/ style/ svelte/
60
+ static/ public dir, copied as is
61
+ public/ build output
13
62
  ```
14
63
 
15
- # Under development
16
- This module is currently under development and may not be ready for production.
64
+ Every game in `settings.games` becomes a page `<page>.html`, rendered from the partial `game.hbs` with its
65
+ settings as `data`. `development.html` lists every game.
66
+
67
+ ## Configuration
68
+
69
+ Everything lives in `package.json`. `vite` is validated; an unknown option is an error.
70
+
71
+ ```jsonc
72
+ "settings": {
73
+ "generic": { "info": { "client": "…" }, "meta": { "title": "…" }, "options": { "backgroundColor": "#000" } },
74
+ "games": [{ "info": { "id": "verdwaald" }, "meta": { "title": "Verdwaald" } }]
75
+ },
76
+ "vite": {
77
+ "dev": { "serveParams": "?debug", "https": true, "cors": true, "fullReloadSvelte": true },
78
+ "build": {
79
+ "basePath": "/",
80
+ "legacy": false,
81
+ "manifest": false,
82
+ "sourceMaps": false,
83
+ "createZip": false,
84
+ "analyzeBundle": false,
85
+ "imageQuality": { "jpeg": 80, "png": [0.5, 0.7] },
86
+ "imageExclude": ["sprites", "sounds", "fonts"],
87
+ "cleanPatterns": []
88
+ },
89
+ "dedupe": []
90
+ }
91
+ ```
92
+
93
+ Game settings are merged per section over `generic`. Any extra field is kept and available in the templates.
94
+
95
+ ## Assets
96
+
97
+ With a `kloekAssets` key in `package.json`, the assets plugin packs the tagged directories under `assets/`
98
+ before the dev server starts and before every build, and repacks on changes while developing. Paths are relative
99
+ to the project, exactly as for the `kloek-assets` CLI, so both share their output and cache:
100
+
101
+ ```jsonc
102
+ "kloekAssets": {
103
+ "output": { "directory": "source/static" },
104
+ "scriptDirectory": "source/script",
105
+ "sounds": { "prefixes": ["sj25"] }
106
+ }
107
+ ```
108
+
109
+ See the [assets plugin](https://github.com/studiokloek/vite-assets-plugin#readme) for the tags and options.
110
+
111
+ ## Development
112
+
113
+ ```sh
114
+ pnpm install
115
+ pnpm lint && pnpm typecheck && pnpm test && pnpm build
116
+ pnpm changeset # describe your change; merging to main opens the release PR
117
+ ```
118
+
119
+ ## License
120
+
121
+ MIT
package/bin/assets.js ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env node
2
+ // Doorgifte naar de CLI van de assets-plugin, zodat projecten alleen vite-config als dependency nodig hebben
3
+ import('@studiokloek/vite-assets-plugin/cli')
4
+ .then(({ run }) => run(process.argv.slice(2)))
5
+ .catch((error) => {
6
+ console.error(error);
7
+ process.exitCode = 1;
8
+ });
package/bin/build.js CHANGED
@@ -1,62 +1,7 @@
1
1
  #!/usr/bin/env node
2
- import meow from 'meow';
3
- import {kloekBuild} from '../dist/index.js';
4
-
5
- const cli = meow(
6
- `
7
- Usage
8
- $ kloek-build
9
-
10
- Options:
11
- -b, --base PATH set the base path
12
-
13
- Other options:
14
- -m, --mode MODE set the mode in which vite should run
15
- -l, --log-level LEVEL sets the log level for vite (info | warn | error | silent)
16
- -e, --empty-out-dir empty output dir before building
17
- -s, --sourcemaps should we create source maps
18
- -i, --inline-sourcemaps inline source maps
19
- -z, --create-zip create zip file from build
20
- `,
21
- {
22
- importMeta: import.meta,
23
- flags: {
24
- base: {
25
- type: 'string',
26
- shortFlag: 'b',
27
- default: '/',
28
- },
29
- mode: {
30
- type: 'string',
31
- shortFlag: 'm',
32
- },
33
- logLevel: {
34
- type: 'string',
35
- shortFlag: 'l',
36
- default: 'info',
37
- },
38
- emptyOutDir: {
39
- type: 'boolean',
40
- shortFlag: 'e',
41
- default: true,
42
- },
43
- sourcemaps: {
44
- type: 'boolean',
45
- shortFlag: 's',
46
- default: false,
47
- },
48
- inlineSourcemaps: {
49
- type: 'boolean',
50
- shortFlag: 'i',
51
- default: false,
52
- },
53
- createZip: {
54
- type: 'boolean',
55
- shortFlag: 'z',
56
- default: false,
57
- },
58
- },
59
- },
60
- );
61
-
62
- await kloekBuild(cli.flags);
2
+ import('../dist/cli.js')
3
+ .then(({ runBuild }) => runBuild(process.argv.slice(2)))
4
+ .catch((error) => {
5
+ console.error(error);
6
+ process.exitCode = 1;
7
+ });
@@ -1,24 +1,7 @@
1
1
  #!/usr/bin/env node
2
- import meow from 'meow';
3
- import {kloekDevelopment} from '../dist/index.js';
4
-
5
- const cli = meow(
6
- `
7
- Usage
8
- $ kloek-development
9
-
10
- Options:
11
- -m, --mode MODE set the mode in which vite should run
12
- `,
13
- {
14
- importMeta: import.meta,
15
- flags: {
16
- mode: {
17
- type: 'string',
18
- shortFlag: 'm',
19
- },
20
- },
21
- },
22
- );
23
-
24
- await kloekDevelopment(cli.flags);
2
+ import('../dist/cli.js')
3
+ .then(({ runDevelopment }) => runDevelopment(process.argv.slice(2)))
4
+ .catch((error) => {
5
+ console.error(error);
6
+ process.exitCode = 1;
7
+ });
package/dist/cli.d.ts ADDED
@@ -0,0 +1,6 @@
1
+ //#region src/cli.d.ts
2
+ /** `kloek-build`; opties die niet meegegeven worden, komen uit package.json#vite. */
3
+ export declare function runBuild(argv: readonly string[]): Promise<number>;
4
+ /** `kloek-development`: start de dev-server. */
5
+ export declare function runDevelopment(argv: readonly string[]): Promise<number>;
6
+ //#endregion
package/dist/cli.js ADDED
@@ -0,0 +1,64 @@
1
+ import { a as packageDirectory, n as kloekDevelopment, t as kloekBuild } from "./commands-ujEjJD4C.js";
2
+ import { readFileSync } from "node:fs";
3
+ import { cac } from "cac";
4
+ //#region src/cli.ts
5
+ const LOG_LEVELS = [
6
+ "info",
7
+ "warn",
8
+ "error",
9
+ "silent"
10
+ ];
11
+ function packageVersion() {
12
+ return JSON.parse(readFileSync(packageDirectory("package.json"), "utf8")).version;
13
+ }
14
+ function logLevelOf(value) {
15
+ if (value !== void 0 && !LOG_LEVELS.includes(value)) throw new Error(`Unknown log level "${value}"; use ${LOG_LEVELS.join(", ")}`);
16
+ return value;
17
+ }
18
+ /** Parseert `argv` en draait `action`; geeft de exit-code terug. */
19
+ async function runCli(name, argv, setup) {
20
+ const cli = cac(name);
21
+ let exitCode = 0;
22
+ setup(cli);
23
+ cli.help();
24
+ cli.version(packageVersion());
25
+ try {
26
+ cli.parse([
27
+ "node",
28
+ name,
29
+ ...argv
30
+ ], { run: false });
31
+ await cli.runMatchedCommand();
32
+ } catch (error) {
33
+ console.error(error instanceof Error ? error.message : error);
34
+ exitCode = 1;
35
+ }
36
+ process.exitCode = exitCode;
37
+ return exitCode;
38
+ }
39
+ /** `kloek-build`; opties die niet meegegeven worden, komen uit package.json#vite. */
40
+ function runBuild(argv) {
41
+ return runCli("kloek-build", argv, (cli) => {
42
+ cli.command("", "Build the project into public/").option("-b, --base <path>", "Base path (default: vite.build.basePath)").option("-m, --mode <mode>", "Mode in which Vite runs (default: production)").option("-l, --log-level <level>", "Log level: info, warn, error or silent").option("-e, --empty-out-dir", "Empty the output directory first (default: true; --no-empty-out-dir to keep it)").option("-s, --sourcemaps", "Create source maps (default: vite.build.sourceMaps)").option("-i, --inline-sourcemaps", "Inline the source maps").option("-z, --create-zip", "Create a zip of the build (default: vite.build.createZip)").action(async (flags) => {
43
+ await kloekBuild({
44
+ base: flags.base,
45
+ mode: flags.mode,
46
+ logLevel: logLevelOf(flags.logLevel),
47
+ emptyOutDir: flags.emptyOutDir,
48
+ sourcemaps: flags.sourcemaps,
49
+ inlineSourcemaps: flags.inlineSourcemaps,
50
+ createZip: flags.createZip
51
+ });
52
+ });
53
+ });
54
+ }
55
+ /** `kloek-development`: start de dev-server. */
56
+ function runDevelopment(argv) {
57
+ return runCli("kloek-development", argv, (cli) => {
58
+ cli.command("", "Start the development server").option("-m, --mode <mode>", "Mode in which Vite runs (default: development)").action(async (flags) => {
59
+ await kloekDevelopment({ mode: flags.mode });
60
+ });
61
+ });
62
+ }
63
+ //#endregion
64
+ export { runBuild, runDevelopment };