https://github.com/hediet/vite-git-plugin.git
A Vite plugin that allows you to load files from git references (branches, tags, commits) instead of the working directory.
?git=<ref> query parameternpm install vite-git-plugin
Add the plugin to your vite.config.ts:
import { defineConfig } from 'vite';
import { viteGitPlugin } from 'vite-git-plugin';
export default defineConfig({
plugins: [viteGitPlugin()],
});
Load any HTML file with a git reference:
http://localhost:5173/index.html?git=main
http://localhost:5173/page.html?git=v1.0.0
http://localhost:5173/app.html?git=feature/new-feature
When you load page.html?git=main, all modules it imports will automatically use the same git reference:
<!-- page.html?git=main -->
<script type="module" src="/src/index.ts"></script>
<!-- This will load src/index.ts?git=main -->
And if index.ts imports other modules:
// src/index.ts?git=main
import { helper } from './helper.ts';
// This will load src/helper.ts?git=main
viteGitPlugin({
debug: true, // Enable debug logging
})
?git=<ref> query parameter, the plugin uses git show <ref>:<path> to read the file content from that git referenceresolveId hook propagates the git reference to all imported modulesenforce: 'pre' to process files before other Vite plugins# Install dependencies
npm install
# Run tests
npm test
# Run integration tests
npm run test:integration
# Build
npm run build
MIT