https://github.com/MrQinYQ/vite-plugin-static-filehash
A Vite plugin that tries to keep the hash of a single file unchanged
https://github.com/MrQinYQ/vite-plugin-static-filehash
Last synced: about 1 month ago
JSON representation
A Vite plugin that tries to keep the hash of a single file unchanged
- Host: GitHub
- URL: https://github.com/MrQinYQ/vite-plugin-static-filehash
- Owner: MrQinYQ
- License: mit
- Created: 2024-08-27T08:37:33.000Z (9 months ago)
- Default Branch: main
- Last Pushed: 2024-11-01T05:38:24.000Z (7 months ago)
- Last Synced: 2024-11-01T05:39:45.426Z (7 months ago)
- Language: TypeScript
- Size: 50.8 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
- awesome-vite - vite-plugin-static-filehash - It can help the program improve the cache hit rate. (Plugins / Framework-agnostic Plugins)
- fucking-awesome-vite - vite-plugin-static-filehash - It can help the program improve the cache hit rate. (Plugins / Framework-agnostic Plugins)
README
## 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.
```typescript
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.
```typescript
interface PluginConfig {
emitFile?: boolean;
}// staticFilehashPlugin({ emitFile: true })
```The effect of not using this plugin:



The effect of using this plugin:



