This is a very small rollup plugin to save the current version from your package.json to a static file during the build process.
First install the plugin npm i --save-dev @binary-butterfly/rollup-plugin-version-file
.
Then, in your rollup config add it to the plugins array:
import versionFile from '@binary-butterfly/rollup-plugin-version-file';
export default {
// ... other config
plugins: [
// ... other plugins
versionFile({
'outputPath': './public/version',
'packageFilePath': './package.json',
'log': true,
})
]
// ... other config
}
The config parameters given in that example are the defaults, so if you want to use these settings, you may forego providing a value for them.
outputPath
: Where to store the version file, relative to your project root directorypackageFilePath
: Where to find yourpackage.json
file, relative to your project root directorylog
: If you want the plugin to log what it wrote once it is done
Vite uses rollup internally for production builds.
To use this plugin within vite, all you have to do is add the above configuration within your vite
config's build.rollupOptions
.