Skip to content

Commit 882b12c

Browse files
committed
build: refactor vite plugins to emit files (@fehmer)
1 parent 3f21023 commit 882b12c

File tree

2 files changed

+7
-12
lines changed

2 files changed

+7
-12
lines changed
Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,15 @@
11
import { Plugin } from "vite";
2-
import path from "node:path";
3-
import { existsSync, mkdirSync, writeFileSync } from "node:fs";
42
export function versionFile(options: { clientVersion: string }): Plugin {
53
return {
64
name: "generate-version-json",
75
apply: "build",
86

9-
closeBundle() {
10-
const distPath = path.resolve("./dist");
11-
if (!existsSync(distPath)) {
12-
mkdirSync(distPath, { recursive: true });
13-
}
14-
15-
const versionJson = JSON.stringify({ version: options.clientVersion });
16-
const versionPath = path.resolve(distPath, "version.json");
17-
writeFileSync(versionPath, versionJson);
7+
generateBundle() {
8+
this.emitFile({
9+
type: "asset",
10+
source: JSON.stringify({ version: options.clientVersion }),
11+
fileName: "version.json",
12+
});
1813
},
1914
};
2015
}

frontend/vite.config.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ function getPlugins({
8181
const plugins: PluginOption[] = [
8282
envConfig({ isDevelopment, clientVersion, env }),
8383
languageHashes({ skip: isDevelopment }),
84+
versionFile({ clientVersion }),
8485
checker({
8586
oxlint: {
8687
lintCommand: "oxlint . --type-aware --type-check",
@@ -98,7 +99,6 @@ function getPlugins({
9899
const prodPlugins: PluginOption[] = [
99100
fontPreview(),
100101
fontawesomeSubset(),
101-
versionFile({ clientVersion }),
102102
ViteMinifyPlugin(),
103103
VitePWA({
104104
// injectRegister: "networkfirst",

0 commit comments

Comments
 (0)