Skip to content

Commit 3029406

Browse files
committed
actions: add docs build workflow config
1 parent d6e86c5 commit 3029406

10 files changed

Lines changed: 338 additions & 267 deletions

File tree

.eslintrc.cjs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,16 @@ module.exports = {
22
root: true,
33
env: { browser: true, es2020: true },
44
extends: [
5-
'eslint:recommended',
6-
'plugin:@typescript-eslint/recommended',
7-
'plugin:react-hooks/recommended',
5+
"eslint:recommended",
6+
"plugin:@typescript-eslint/recommended",
7+
"plugin:react-hooks/recommended",
88
],
9-
ignorePatterns: ['dist', '.eslintrc.cjs'],
10-
parser: '@typescript-eslint/parser',
11-
plugins: ['react-refresh'],
9+
ignorePatterns: ["dist", "docs", ".eslintrc.cjs"],
10+
parser: "@typescript-eslint/parser",
11+
plugins: ["react-refresh"],
1212
rules: {
13-
'react-refresh/only-export-components': [
14-
'warn',
13+
"react-refresh/only-export-components": [
14+
"warn",
1515
{ allowConstantExport: true },
1616
],
1717
},

.github/workflows/docs.yml

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
name: Build and Deploy
2+
on:
3+
push:
4+
paths: ["src/**"] # Trigger the action only when files change in the folders defined here
5+
jobs:
6+
build-and-deploy:
7+
runs-on: ubuntu-latest
8+
steps:
9+
- name: Checkout 🛎️
10+
uses: actions/checkout@v3
11+
with:
12+
persist-credentials: false
13+
- name: Install and Build 🔧
14+
run: | # Install packages and build the demo project
15+
yarn install
16+
yarn build-docs
17+
- name: Get commit info
18+
shell: bash
19+
run: |
20+
echo "sha_short=$(git rev-parse --short "$GITHUB_SHA")" >> "$GITHUB_ENV"
21+
- name: Deploy 🚀
22+
uses: crazy-max/ghaction-github-pages@v3
23+
with:
24+
target_branch: docs
25+
build_dir: docs
26+
commit_message: "Deploying to docs from ${{ env.sha_short }}"
27+
keep_history: false
28+
jekyll: false
29+
env:
30+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ pnpm-debug.log*
88
lerna-debug.log*
99

1010
node_modules
11+
docs
1112
dist
1213
dist-ssr
1314
*.local

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,8 @@
2929
},
3030
"scripts": {
3131
"dev": "vite",
32-
"build": "tsc --p ./tsconfig-build.json && vite build",
32+
"build": "tsc --p ./tsconfig-build.json && vite build --mode production",
33+
"build-docs": "tsc --p ./tsconfig-build-docs.json && vite build --mode docs",
3334
"lint": "eslint . --ext ts,tsx --report-unused-disable-directives --max-warnings 0",
3435
"preview": "vite preview",
3536
"prepublishOnly": "yarn build"

src/App.css

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,29 @@
1+
:root {
2+
font-family: Inter, system-ui, Avenir, Helvetica, Arial, sans-serif;
3+
font-weight: 400;
4+
font-synthesis: none;
5+
text-rendering: optimizeLegibility;
6+
-webkit-font-smoothing: antialiased;
7+
-moz-osx-font-smoothing: grayscale;
8+
}
9+
* {
10+
box-sizing: border-box;
11+
}
12+
body {
13+
margin: 0;
14+
display: flex;
15+
place-items: center;
16+
min-width: 320px;
17+
min-height: 100vh;
18+
}
19+
20+
#root {
21+
width: 100%;
22+
display: flex;
23+
justify-content: center;
24+
align-items: center;
25+
}
26+
127
.full-width {
228
width: 100%;
329
}

src/index.css

Lines changed: 0 additions & 25 deletions
This file was deleted.

src/main.tsx

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
1-
import React from 'react'
2-
import ReactDOM from 'react-dom/client'
3-
import App from './App.tsx'
4-
import './index.css'
1+
import React from "react"
2+
import ReactDOM from "react-dom/client"
3+
import App from "./App.tsx"
54

6-
ReactDOM.createRoot(document.getElementById('root')!).render(
5+
ReactDOM.createRoot(document.getElementById("root")!).render(
76
<React.StrictMode>
87
<App />
9-
</React.StrictMode>,
8+
</React.StrictMode>
109
)

tsconfig-build-docs.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"extends": "./tsconfig.json",
3+
"exclude": ["lib"]
4+
}

vite.config.ts

Lines changed: 57 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -6,34 +6,63 @@ import react from "@vitejs/plugin-react-swc"
66
import dts from "vite-plugin-dts"
77

88
// https://vitejs.dev/config/
9-
export default defineConfig({
10-
plugins: [react(), dts({ include: ["lib"] })],
11-
build: {
12-
lib: {
13-
entry: resolve(__dirname, "lib/main.ts"),
14-
formats: ["es"],
15-
},
16-
rollupOptions: {
17-
external: ["react", "react/jsx-runtime"],
18-
input: Object.fromEntries(
19-
// https://rollupjs.org/configuration-options/#input
20-
glob.sync("lib/**/*.{ts,tsx}").map((file) => [
21-
// 1. The name of the entry point
22-
// lib/nested/foo.js becomes nested/foo
23-
relative("lib", file.slice(0, file.length - extname(file).length)),
24-
// 2. The absolute path to the entry file
25-
// lib/nested/foo.ts becomes /project/lib/nested/foo.ts
26-
fileURLToPath(new URL(file, import.meta.url)),
27-
])
28-
),
29-
output: {
30-
// assetFileNames: '[name][extname]',
31-
assetFileNames: (assetInfo) => {
32-
const assetName = assetInfo.name?.split(".").at(0)
33-
return `${assetName === "style" ? "index" : "[name]"}[extname]`
9+
export default defineConfig(({ mode }) => {
10+
if (mode === "docs") {
11+
return {
12+
plugins: [react(), dts({ exclude: ["lib"] })],
13+
build: { outDir: "docs" },
14+
/* build: {
15+
rollupOptions: {
16+
external: ["react", "react/jsx-runtime"],
17+
input: resolve(__dirname, "index.html"),
18+
output: {
19+
dir: resolve(__dirname, "docs"),
20+
// assetFileNames: '[name][extname]',
21+
assetFileNames: (assetInfo) => {
22+
const assetName = assetInfo.name?.split(".").at(0)
23+
return `${assetName === "style" ? "index" : "[name]"}[extname]`
24+
},
25+
entryFileNames: "[name].js",
26+
},
27+
},
28+
},*/
29+
}
30+
}
31+
if (mode === "production") {
32+
return {
33+
plugins: [react(), dts({ include: ["lib"] })],
34+
build: {
35+
lib: {
36+
entry: resolve(__dirname, "lib/main.ts"),
37+
formats: ["es"],
38+
},
39+
rollupOptions: {
40+
external: ["react", "react/jsx-runtime"],
41+
input: Object.fromEntries(
42+
// https://rollupjs.org/configuration-options/#input
43+
glob.sync("lib/**/*.{ts,tsx}").map((file) => [
44+
// 1. The name of the entry point
45+
// lib/nested/foo.js becomes nested/foo
46+
relative(
47+
"lib",
48+
file.slice(0, file.length - extname(file).length)
49+
),
50+
// 2. The absolute path to the entry file
51+
// lib/nested/foo.ts becomes /project/lib/nested/foo.ts
52+
fileURLToPath(new URL(file, import.meta.url)),
53+
])
54+
),
55+
output: {
56+
// assetFileNames: '[name][extname]',
57+
assetFileNames: (assetInfo) => {
58+
const assetName = assetInfo.name?.split(".").at(0)
59+
return `${assetName === "style" ? "index" : "[name]"}[extname]`
60+
},
61+
entryFileNames: "[name].js",
62+
},
3463
},
35-
entryFileNames: "[name].js",
3664
},
37-
},
38-
},
65+
}
66+
}
67+
return {}
3968
})

0 commit comments

Comments
 (0)