├── .gitignore ├── example ├── .gitignore ├── public │ └── favicon.ico ├── src │ ├── assets │ │ └── logo.png │ ├── main.ts │ ├── shims-vue.d.ts │ ├── App.vue │ └── components │ │ └── HelloWorld.vue ├── vite.config.ts ├── index.html ├── tsconfig.json ├── package.json ├── README.md └── yarn.lock ├── public └── favicon.ico ├── src ├── helpers │ ├── remove-empty-lines.ts │ └── run-git-command.ts └── index.ts ├── tsconfig.json ├── package.json ├── README.md └── yarn.lock /.gitignore: -------------------------------------------------------------------------------- 1 | node_modules 2 | .DS_Store 3 | dist 4 | dist-ssr 5 | yarn* 6 | *.local 7 | .vscode -------------------------------------------------------------------------------- /example/.gitignore: -------------------------------------------------------------------------------- 1 | node_modules 2 | .DS_Store 3 | dist 4 | dist-ssr 5 | *.local 6 | yarn* 7 | -------------------------------------------------------------------------------- /public/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/qduld/vite-plugin-git-revision/HEAD/public/favicon.ico -------------------------------------------------------------------------------- /example/public/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/qduld/vite-plugin-git-revision/HEAD/example/public/favicon.ico -------------------------------------------------------------------------------- /example/src/assets/logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/qduld/vite-plugin-git-revision/HEAD/example/src/assets/logo.png -------------------------------------------------------------------------------- /example/src/main.ts: -------------------------------------------------------------------------------- 1 | import { createApp } from 'vue' 2 | import App from './App.vue' 3 | 4 | createApp(App).mount('#app') 5 | -------------------------------------------------------------------------------- /src/helpers/remove-empty-lines.ts: -------------------------------------------------------------------------------- 1 | export function removeEmptyLines (string:string) { 2 | return string.replace(/[\s\r\n]+$/, '') 3 | } -------------------------------------------------------------------------------- /example/src/shims-vue.d.ts: -------------------------------------------------------------------------------- 1 | declare module '*.vue' { 2 | import { DefineComponent } from 'vue' 3 | const component: DefineComponent<{}, {}, any> 4 | export default component 5 | } 6 | -------------------------------------------------------------------------------- /example/vite.config.ts: -------------------------------------------------------------------------------- 1 | import { defineConfig } from 'vite' 2 | import vue from '@vitejs/plugin-vue' 3 | import ViteGitRevision from 'vite-plugin-git-revision' 4 | 5 | // https://vitejs.dev/config/ 6 | export default defineConfig({ 7 | define:{ 8 | }, 9 | plugins: [ 10 | vue(), 11 | ViteGitRevision({}) 12 | ] 13 | }) 14 | -------------------------------------------------------------------------------- /example/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | Vite App 8 | 9 | 10 |
11 | 12 | 13 | 14 | -------------------------------------------------------------------------------- /tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "target": "esnext", 4 | "module": "esnext", 5 | "moduleResolution": "node", 6 | "strict": true, 7 | "jsx": "preserve", 8 | "resolveJsonModule": true, 9 | "esModuleInterop": true, 10 | "outDir": "dist", 11 | "lib": ["esnext", "dom"], 12 | "types": ["vite/client","node"], 13 | "sourceMap": true 14 | }, 15 | "include": ["src/**/*.ts", "src/**/*.d.ts"] 16 | } 17 | -------------------------------------------------------------------------------- /example/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "target": "esnext", 4 | "module": "esnext", 5 | "moduleResolution": "node", 6 | "strict": true, 7 | "jsx": "preserve", 8 | "sourceMap": true, 9 | "resolveJsonModule": true, 10 | "esModuleInterop": true, 11 | "lib": ["esnext", "dom"], 12 | "types": ["vite/client"] 13 | }, 14 | "include": ["src/**/*.ts", "src/**/*.d.ts", "src/**/*.tsx", "src/**/*.vue"] 15 | } 16 | -------------------------------------------------------------------------------- /example/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "example", 3 | "version": "0.0.0", 4 | "scripts": { 5 | "dev": "vite", 6 | "build": "vue-tsc --noEmit && vite build", 7 | "serve": "vite preview" 8 | }, 9 | "dependencies": { 10 | "vite-plugin-git-revision": "0.1.6", 11 | "vue": "^3.0.5" 12 | }, 13 | "devDependencies": { 14 | "@vitejs/plugin-vue": "^1.2.1", 15 | "@vue/compiler-sfc": "^3.0.5", 16 | "typescript": "^4.1.3", 17 | "vite": "^2.1.5", 18 | "vue-tsc": "^0.0.24" 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /example/src/App.vue: -------------------------------------------------------------------------------- 1 | 5 | 6 | 17 | 18 | 28 | -------------------------------------------------------------------------------- /src/helpers/run-git-command.ts: -------------------------------------------------------------------------------- 1 | var exec = require('child_process').exec 2 | var execSync = require('child_process').execSync 3 | // import { exec,execSync } from 'child_process'; 4 | import path from 'path'; 5 | import { removeEmptyLines } from './remove-empty-lines'; 6 | 7 | export function runGitCommand(gitWorkTree:any, command:any, callback?:Function) { 8 | var gitCommand = gitWorkTree 9 | ? [ 10 | 'git', 11 | '--git-dir=' + path.join(gitWorkTree, '.git'), 12 | '--work-tree=' + gitWorkTree, 13 | command 14 | ].join(' ') 15 | : [ 16 | 'git', 17 | command 18 | ].join(' ') 19 | 20 | if (callback) { 21 | exec(gitCommand, function (err:any, stdout:any) { 22 | if (err) { return callback(err) } 23 | callback(null, removeEmptyLines(stdout)) 24 | }) 25 | } else { 26 | return removeEmptyLines('' + execSync(gitCommand)) 27 | } 28 | } -------------------------------------------------------------------------------- /src/index.ts: -------------------------------------------------------------------------------- 1 | import { Plugin } from 'vite' 2 | import { runGitCommand } from './helpers/run-git-command' 3 | 4 | const COMMITHASH_COMMAND = 'rev-parse HEAD' 5 | const VERSION_COMMAND = 'describe --always' 6 | const BRANCH_COMMAND = 'rev-parse --abbrev-ref HEAD' 7 | 8 | const defaultOpt = { 9 | lightweightTags:false, 10 | branch:false, 11 | commithashCommand:COMMITHASH_COMMAND, 12 | versionCommand:VERSION_COMMAND, 13 | branchCommand:BRANCH_COMMAND, 14 | } 15 | 16 | export interface ViteGitRevisionPlugin { 17 | // git work tree 18 | gitWorkTree?: any; 19 | // lightweight tags support. 20 | lightweightTags?: boolean; 21 | // branch name support 22 | branch?: boolean; 23 | //change the default git command used to read the value of COMMITHASH 24 | commithashCommand?: string; 25 | //change the default git command used to read the value of VERSION 26 | versionCommand?: string; 27 | //change the default git command used to read the value of BRANCH 28 | branchCommand?: string; 29 | } 30 | 31 | 32 | export default (options: ViteGitRevisionPlugin): Plugin => { 33 | options = Object.assign(defaultOpt,options?options:{}) 34 | if (options.versionCommand && options.lightweightTags) { 35 | throw new Error('lightweightTags can\'t be used together versionCommand') 36 | } 37 | 38 | return { 39 | name: 'vite:git-revision', 40 | config(config:any) { 41 | config.define.VERSION = JSON.stringify(runGitCommand(options.gitWorkTree,options.versionCommand)) 42 | } 43 | }; 44 | }; -------------------------------------------------------------------------------- /example/src/components/HelloWorld.vue: -------------------------------------------------------------------------------- 1 | 36 | 37 | 53 | 54 | 71 | -------------------------------------------------------------------------------- /example/README.md: -------------------------------------------------------------------------------- 1 | # Vue 3 + Typescript + Vite 2 | 3 | This template should help get you started developing with Vue 3 and Typescript in Vite. 4 | 5 | ## Recommended IDE Setup 6 | 7 | [VSCode](https://code.visualstudio.com/) + [Vetur](https://marketplace.visualstudio.com/items?itemName=octref.vetur). Make sure to enable `vetur.experimental.templateInterpolationService` in settings! 8 | 9 | ### If Using `