🐛 fix: Add version.lock plugin to generate version lock file after build
This commit is contained in:
parent
a3d1c00826
commit
574c06c754
@ -1,9 +1,27 @@
|
||||
import { readFileSync, writeFileSync } from "node:fs";
|
||||
import { fileURLToPath, URL } from "node:url";
|
||||
import tailwindcss from "@tailwindcss/vite";
|
||||
import { devtools } from "@tanstack/devtools-vite";
|
||||
import { tanstackRouter } from "@tanstack/router-plugin/vite";
|
||||
import viteReact from "@vitejs/plugin-react";
|
||||
import { defineConfig } from "vite";
|
||||
import { defineConfig, type Plugin } from "vite";
|
||||
|
||||
// Plugin to generate version.lock file after build
|
||||
function versionLockPlugin(): Plugin {
|
||||
return {
|
||||
name: "version-lock",
|
||||
apply: "build",
|
||||
closeBundle() {
|
||||
const distDir = fileURLToPath(new URL("./dist", import.meta.url));
|
||||
const rootPkgPath = fileURLToPath(
|
||||
new URL("../../package.json", import.meta.url)
|
||||
);
|
||||
const rootPkg = JSON.parse(readFileSync(rootPkgPath, "utf-8"));
|
||||
const version = rootPkg.version || "0.0.0";
|
||||
writeFileSync(`${distDir}/version.lock`, version);
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
// https://vitejs.dev/config/
|
||||
export default defineConfig({
|
||||
@ -16,6 +34,7 @@ export default defineConfig({
|
||||
}),
|
||||
viteReact(),
|
||||
tailwindcss(),
|
||||
versionLockPlugin(),
|
||||
],
|
||||
resolve: {
|
||||
alias: {
|
||||
|
||||
@ -1,9 +1,27 @@
|
||||
import { readFileSync, writeFileSync } from "node:fs";
|
||||
import { fileURLToPath, URL } from "node:url";
|
||||
import tailwindcss from "@tailwindcss/vite";
|
||||
import { devtools } from "@tanstack/devtools-vite";
|
||||
import { tanstackRouter } from "@tanstack/router-plugin/vite";
|
||||
import viteReact from "@vitejs/plugin-react";
|
||||
import { defineConfig } from "vite";
|
||||
import { defineConfig, type Plugin } from "vite";
|
||||
|
||||
// Plugin to generate version.lock file after build
|
||||
function versionLockPlugin(): Plugin {
|
||||
return {
|
||||
name: "version-lock",
|
||||
apply: "build",
|
||||
closeBundle() {
|
||||
const distDir = fileURLToPath(new URL("./dist", import.meta.url));
|
||||
const rootPkgPath = fileURLToPath(
|
||||
new URL("../../package.json", import.meta.url)
|
||||
);
|
||||
const rootPkg = JSON.parse(readFileSync(rootPkgPath, "utf-8"));
|
||||
const version = rootPkg.version || "0.0.0";
|
||||
writeFileSync(`${distDir}/version.lock`, version);
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
// https://vitejs.dev/config/
|
||||
export default defineConfig({
|
||||
@ -16,6 +34,7 @@ export default defineConfig({
|
||||
}),
|
||||
viteReact(),
|
||||
tailwindcss(),
|
||||
versionLockPlugin(),
|
||||
],
|
||||
resolve: {
|
||||
alias: {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user