Skip to content

Commit 42094aa

Browse files
committed
build: refactor vite plugins to emit files (@fehmer)
1 parent 331ca1a commit 42094aa

2 files changed

Lines changed: 7 additions & 12 deletions

File tree

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
typescript: {
8687
tsconfigPath: path.resolve(__dirname, "./tsconfig.json"),
@@ -105,7 +106,6 @@ function getPlugins({
105106
const prodPlugins: PluginOption[] = [
106107
fontPreview(),
107108
fontawesomeSubset(),
108-
versionFile({ clientVersion }),
109109
ViteMinifyPlugin(),
110110
VitePWA({
111111
// injectRegister: "networkfirst",

0 commit comments

Comments
 (0)