Skip to content

A Vite plugin that tries to keep the hash of a single file unchanged

License

Notifications You must be signed in to change notification settings

MrQinYQ/vite-plugin-static-filehash

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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:

image

image

image

The effect of using this plugin:

image

image

image

image

About

A Vite plugin that tries to keep the hash of a single file unchanged

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published