Awesome
A Vite plugin that tries to keep the hash of a single file unchanged
When we update our program, if we only change one file, such as modifying the About file, it will still affect the cache hit of the entry file. This is because the hash change of the file affects other files, causing the content of other files to change, and their hashes to change. The change of hash spreads like a virus, affecting all files that depend on it, including the entry file.
So the role of this plugin is that when you modify one file, it will never affect other files.
Because this solution relies on import map, in order to ensure normal operation, es-module-shims dependency will be introduced into the project.
import {
defineConfig,
} from 'vite'
import react from '@vitejs/plugin-react-swc'
import staticFilehashPlugin from 'vite-plugin-static-filehash';
// https://vitejs.dev/config/
export default defineConfig({
plugins: [
react(),
staticFilehashPlugin(),
],
})
Output filehashs.js file separately.
interface PluginConfig {
emitFile?: boolean;
}
// staticFilehashPlugin({ emitFile: true })
The effect of not using this plugin:
The effect of using this plugin: