Skip to content

Commit

Permalink
feat: support ifExport (#6)
Browse files Browse the repository at this point in the history
  • Loading branch information
ZhongxuYang authored Feb 29, 2024
1 parent 810bb97 commit 5e4bc34
Show file tree
Hide file tree
Showing 27 changed files with 873 additions and 79 deletions.
16 changes: 11 additions & 5 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,20 +1,26 @@
# CHANGELOG


## v0.0.11

* Support export version field in the entry file.

## v0.0.10

* Fix the bug that the `version` is not defined global after `ifGlobal: true`
* Fix the bug that the `version` is not defined global after `ifGlobal: true`.

## v0.0.9

* The ifGlobal setting mode is switched to vite.define, so that the node.js environment can read (by [@censujiang](https://github.com/ZhongxuYang/vite-plugin-version-mark/pull/4))
* The ifGlobal setting mode is switched to vite.define, so that the node.js environment can read. (by [@censujiang](https://github.com/ZhongxuYang/vite-plugin-version-mark/pull/4))

## v0.0.8

* Support provide a custom command to retrieve the version (by [@kgutwin](https://github.com/kgutwin))
* Support provide a custom command to retrieve the version. (by [@kgutwin](https://github.com/kgutwin))

## v0.0.5 - v0.0.7

* Optimizations & support Nuxt3+
* Optimizations & support Nuxt3+.

## v0.0.1 - v0.0.4

* First release & bug fixing
* First release & bug fixing.
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -91,10 +91,12 @@ Then you can use `vite-plugin-version-mark` ! 🎉
| version | application version | `string` | `version` in package.json | `0.0.1+` |
| ifGitSHA | use git commit SHA as the version | `boolean` | false | `0.0.1+` |
| ifShortSHA | use git commit short SHA as the version | `boolean` | true | `0.0.1+` |
| command | provide a custom command to retrieve the version <br/>For example: `git describe --tags` | `string` | git rev-parse --short HEAD | `0.0.8+` |
| ifLog | print info in the Console | `boolean` | true | `0.0.1+` |
| ifGlobal | set a variable named *\`\_\_${APPNAME}\_VERSION\_\_\`* in the window<br/>[For TypeScript users, make sure to add the type declarations in the env.d.ts or vite-env.d.ts file to get type checks and Intellisense.](https://vitejs.dev/config/shared-options.html#define) | `boolean` | true | `0.0.4+` |
| ifMeta | add \<meta name="application-name" content="{APPNAME_VERSION}: {version}"> in the \<head> | `boolean` | true | `0.0.1+` |
| command | provide a custom command to retrieve the version <br/>For example: `git describe --tags` | `string` | git rev-parse --short HEAD | `0.0.8+` |
| ifExport | export the version field in the entry file. This may be used when you use vite to build a `library mode`.<br/>Through `import { {APPNAME}_VERSION } from <your_library_name>` | `boolean` | false | `0.0.11+` |



## Other
Expand Down
3 changes: 2 additions & 1 deletion README_ZH.md
Original file line number Diff line number Diff line change
Expand Up @@ -92,10 +92,11 @@ export default defineNuxtConfig({
| version | 应用版本 | `string` |`package.json` 中定义的 `version` 属性 | `0.0.1+` |
| ifGitSHA | 使用git commitSHA作为版本号 | `boolean` | false | `0.0.1+` |
| ifShortSHA | 使用git的短commitSHA作为版本号 | `boolean` | true | `0.0.1+` |
| command | 提供自定义指令,以便自定义版本号的获取方式 <br/>例如使用git tag作为版本号: `git describe --tags` | `string` | git rev-parse --short HEAD | `0.0.8+` |
| ifLog | 在控制台打印版本信息 | `boolean` | true | `0.0.1+` |
| ifGlobal | 在window上定义变量 *\`\_\_${APPNAME}\_VERSION\_\_\`* <br/>[对于TypeScript使用者, 请确保您在 env.d.ts 或者 vite-env.d.ts 文件中定义该变量,以便通过类型检查。](https://vitejs.dev/config/shared-options.html#define) | `boolean` | true | `0.0.4+` |
| ifMeta |`<head>` 中添加 `<meta name="application-name" content="{APPNAME_VERSION}: {version}">` | `boolean` | true | `0.0.1+` |
| command | 提供自定义指令,以便自定义版本号的获取方式 <br/>例如使用git tag作为版本号: `git describe --tags` | `string` | git rev-parse --short HEAD | `0.0.8+` |
| ifExport | 在入口文件导出版本字段。这在您使用vite构建 `library mode`时或许会用到。<br />通过 `import { {APPNAME}_VERSION} from <your_library_name>` | `boolean` | false | `0.0.11+` |


## 其它
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "vite-plugin-version-mark",
"version": "0.0.10",
"version": "0.0.11",
"description": "Automatically insert the version or git_commit_sha in your Vite/Nuxt project.",
"keywords": [
"git",
Expand Down Expand Up @@ -44,6 +44,6 @@
"@types/node": "^18.11.3",
"tsup": "^6.3.0",
"typescript": "^4.8.4",
"vite": "^3.1.8"
"vite": "*"
}
}
24 changes: 24 additions & 0 deletions playground/vite-lib/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# Logs
logs
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*
pnpm-debug.log*
lerna-debug.log*

node_modules
dist
dist-ssr
*.local

# Editor directories and files
.vscode/*
!.vscode/extensions.json
.idea
.DS_Store
*.suo
*.ntvs*
*.njsproj
*.sln
*.sw?
1 change: 1 addition & 0 deletions playground/vite-lib/index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export function setupCounter(element: HTMLButtonElement): void
13 changes: 13 additions & 0 deletions playground/vite-lib/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<link rel="icon" type="image/svg+xml" href="/vite.svg" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Vite App</title>
</head>
<body>
<div id="app"></div>
<script type="module" src="/src/main.ts"></script>
</body>
</html>
26 changes: 26 additions & 0 deletions playground/vite-lib/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
{
"name": "vite-lib",
"private": true,
"version": "0.0.0",
"type": "module",
"files": [
"dist",
"index.d.ts"
],
"main": "./dist/counter.umd.cjs",
"module": "./dist/counter.js",
"types": "./index.d.ts",
"exports": {
"types": "./index.d.ts",
"import": "./dist/counter.js",
"require": "./dist/counter.umd.cjs"
},
"scripts": {
"dev": "vite",
"build": "tsc && vite build"
},
"devDependencies": {
"typescript": "^5.3.3",
"vite": "^5.0.10"
}
}
1 change: 1 addition & 0 deletions playground/vite-lib/public/vite.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
23 changes: 23 additions & 0 deletions playground/vite-lib/src/main.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import './style.css'
import typescriptLogo from './typescript.svg'
import { setupCounter } from '../lib/main'

document.querySelector<HTMLDivElement>('#app')!.innerHTML = `
<div>
<a href="https://vitejs.dev" target="_blank">
<img src="/vite.svg" class="logo" alt="Vite logo" />
</a>
<a href="https://www.typescriptlang.org/" target="_blank">
<img src="${typescriptLogo}" class="logo vanilla" alt="TypeScript logo" />
</a>
<h1>Vite + TypeScript</h1>
<div class="card">
<button id="counter" type="button"></button>
</div>
<p class="read-the-docs">
Click on the Vite and TypeScript logos to learn more
</p>
</div>
`

setupCounter(document.querySelector<HTMLButtonElement>('#counter')!)
95 changes: 95 additions & 0 deletions playground/vite-lib/src/style.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
:root {
font-family: Inter, system-ui, Avenir, Helvetica, Arial, sans-serif;
line-height: 1.5;
font-weight: 400;

color-scheme: light dark;
color: rgba(255, 255, 255, 0.87);
background-color: #242424;

font-synthesis: none;
text-rendering: optimizeLegibility;
-webkit-font-smoothing: antialiased;
-moz-osx-font-smoothing: grayscale;
}

a {
font-weight: 500;
color: #646cff;
text-decoration: inherit;
}
a:hover {
color: #535bf2;
}

body {
margin: 0;
display: flex;
place-items: center;
min-width: 320px;
min-height: 100vh;
}

h1 {
font-size: 3.2em;
line-height: 1.1;
}

#app {
max-width: 1280px;
margin: 0 auto;
padding: 2rem;
text-align: center;
}

.logo {
height: 6em;
padding: 1.5em;
will-change: filter;
}
.logo:hover {
filter: drop-shadow(0 0 2em #646cffaa);
}
.logo.vanilla:hover {
filter: drop-shadow(0 0 2em #3178c6aa);
}

.card {
padding: 2em;
}

.read-the-docs {
color: #888;
}

button {
border-radius: 8px;
border: 1px solid transparent;
padding: 0.6em 1.2em;
font-size: 1em;
font-weight: 500;
font-family: inherit;
background-color: #1a1a1a;
cursor: pointer;
transition: border-color 0.25s;
}
button:hover {
border-color: #646cff;
}
button:focus,
button:focus-visible {
outline: 4px auto -webkit-focus-ring-color;
}

@media (prefers-color-scheme: light) {
:root {
color: #213547;
background-color: #ffffff;
}
a:hover {
color: #747bff;
}
button {
background-color: #f9f9f9;
}
}
1 change: 1 addition & 0 deletions playground/vite-lib/src/typescript.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions playground/vite-lib/src/vite-env.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/// <reference types="vite/client" />
23 changes: 23 additions & 0 deletions playground/vite-lib/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{
"compilerOptions": {
"target": "ES2020",
"useDefineForClassFields": true,
"module": "ESNext",
"lib": ["ES2020", "DOM", "DOM.Iterable"],
"skipLibCheck": true,

/* Bundler mode */
"moduleResolution": "Bundler",
"allowImportingTsExtensions": true,
"resolveJsonModule": true,
"isolatedModules": true,
"noEmit": true,

/* Linting */
"strict": true,
"noUnusedLocals": true,
"noUnusedParameters": true,
"noFallthroughCasesInSwitch": true
},
"include": ["src"]
}
22 changes: 22 additions & 0 deletions playground/vite-lib/vite.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import { defineConfig } from 'vite'
import { vitePluginVersionMark } from '../../dist/vite/index'

export default defineConfig({
build: {
lib: {
entry: './lib/main.ts',
name: 'Counter',
fileName: 'counter'
}
},
plugins: [
vitePluginVersionMark({
ifGitSHA: true,
ifShortSHA: true,
ifMeta: true,
ifLog: true,
ifGlobal: true,
ifExport: true,
}),
],
})
Loading

0 comments on commit 5e4bc34

Please sign in to comment.