Skip to content

Commit

Permalink
fix(ui): use configured outDir for replace version plugin (#313)
Browse files Browse the repository at this point in the history
This updates the `replaceVersionPlugin` to use the configured output directory for version.json, fixing build issues when a custom `outDir` is specified.

- Add `configResolved` hook to capture `outDir` from Vite config
- Replace hardcoded 'dist' with `outDir` when writing `version.json`
- Ensure `version.json` is created in the correct output directory during build
  • Loading branch information
drichar authored Oct 19, 2024
1 parent 112f545 commit 60961df
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion ui/vite.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,19 @@ import { version } from './package.json'
* This plugin replaces the `__APP_VERSION__` placeholder in the `public/version.json` file
*/
const replaceVersionPlugin = () => {
let outDir
return {
name: 'replace-version-in-json',
apply: 'build',
enforce: 'pre',
configResolved(config) {
outDir = config.build.outDir
},
generateBundle() {
const filePath = path.resolve(__dirname, 'public/version.json')
const content = fs.readFileSync(filePath, 'utf-8')
const updatedContent = content.replace('__APP_VERSION__', version)
const newFilePath = path.resolve(__dirname, 'dist/version.json')
const newFilePath = path.resolve(outDir, 'version.json')
fs.writeFileSync(newFilePath, updatedContent, 'utf-8')
},
}
Expand Down

0 comments on commit 60961df

Please sign in to comment.