Skip to content

Commit 04f5750

Browse files
authored
feat: export build info to global in example and deploy to github pages (#513)
2 parents da9fbf1 + debae5f commit 04f5750

File tree

5 files changed

+33
-4
lines changed

5 files changed

+33
-4
lines changed

.github/workflows/ci.yml

+17
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,14 @@ on:
1111
jobs:
1212
build:
1313
runs-on: ubuntu-latest
14+
permissions:
15+
pages: write # to deploy to Pages
16+
id-token: write # to verify the deployment originates from an appropriate source
17+
1418
steps:
1519
- uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4
20+
with:
21+
fetch-depth: 0 # to fetch all history
1622

1723
- name: Setup pnpm
1824
uses: pnpm/action-setup@v2.4.0
@@ -34,3 +40,14 @@ jobs:
3440
3541
- name: Test
3642
run: pnpm test
43+
44+
- name: Upload pages artifacts
45+
# https://github.com/actions/upload-pages-artifact
46+
uses: actions/upload-pages-artifact@v3
47+
with:
48+
path: 'examples/vite/dist'
49+
50+
- name: Deploy to GitHub Pages
51+
if: github.ref == 'refs/heads/main'
52+
# https://github.com/actions/deploy-pages
53+
uses: actions/deploy-pages@v4

examples/vite/index.html

+5
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,11 @@
1818
font-style: normal;
1919
}
2020

21+
a {
22+
color: #0070f3;
23+
text-decoration: none;
24+
}
25+
2126
#app {
2227
display: flex;
2328
flex-direction: column;

examples/vite/main.ts

+9-3
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,7 @@ import { name, version } from '~build/package';
1919

2020
import { format } from 'date-fns';
2121

22-
console.log('Build time:', now);
23-
24-
const buildTime = document.querySelector('.container') as HTMLElement;
22+
const buildTime = document.querySelector<HTMLElement>('.container')!;
2523

2624
function append(key: string, value: string | number | null) {
2725
const p = document.createElement('div');
@@ -35,6 +33,11 @@ function append(key: string, value: string | number | null) {
3533
buildTime.appendChild(p);
3634
}
3735

36+
const h1 = document.createElement('h1');
37+
// use caution with `innerHTML`
38+
h1.innerHTML = `<a href="${github}" target="_blank">unplugin-info<a>`;
39+
buildTime.appendChild(h1);
40+
3841
append('Build time: ', format(now, 'yyyy-MM-dd hh:mm'));
3942
append('CI: ', CI ? CI : 'Not a CI env');
4043
append('Github: ', github ? github : 'Not a github');
@@ -54,3 +57,6 @@ append('Message: ', message);
5457

5558
append('Package name: ', name);
5659
append('Package version: ', version);
60+
append('', '');
61+
62+
append('You can also open console and play around with it.', '');

examples/vite/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"name": "playground",
2+
"name": "unplugin-info-vite-demo",
33
"version": "0.7.2",
44
"private": "true",
55
"type": "module",

examples/vite/vite.config.ts

+1
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,6 @@ import { defineConfig } from 'vite';
22
import BuildInfo from 'unplugin-info/vite';
33

44
export default defineConfig({
5+
base: './',
56
plugins: [BuildInfo({ meta: { message: 'This is set from vite.config.ts' } })]
67
});

0 commit comments

Comments
 (0)