Skip to content
This repository was archived by the owner on Sep 20, 2024. It is now read-only.

Commit dcb6226

Browse files
committed
chore: add padding and resolve colors for docs
1 parent 570818f commit dcb6226

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

56 files changed

+1074
-161
lines changed

babel.config.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ const baseConfig = function (api) {
2020
],
2121
'@babel/preset-typescript',
2222
]
23-
const plugins = ['@vue/babel-plugin-jsx', '@babel/plugin-transform-runtime']
23+
const plugins = ['@vue/babel-plugin-jsx']
2424

2525
return {
2626
presets,
@@ -39,7 +39,7 @@ const testConfig = {
3939
},
4040
],
4141
],
42-
plugins: ['@vue/babel-plugin-jsx', '@babel/plugin-transform-runtime'],
42+
plugins: ['@vue/babel-plugin-jsx'],
4343
},
4444
},
4545
}

examples/vue-ssr/.gitignore

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
node_modules
2+
.DS_Store
3+
dist
4+
dist-ssr
5+
*.local

examples/vue-ssr/README.md

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
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 `<script setup>`
10+
11+
[`<script setup>`](https://github.com/vuejs/rfcs/pull/227) is a feature that is currently in RFC stage. To get proper IDE support for the syntax, use [Volar](https://marketplace.visualstudio.com/items?itemName=johnsoncodehk.volar) instead of Vetur (and disable Vetur).
12+
13+
## Type Support For `.vue` Imports in TS
14+
15+
Since TypeScript cannot handle type information for `.vue` imports, they are shimmed to be a generic Vue component type by default. In most cases this is fine if you don't really care about component prop types outside of templates. However, if you wish to get actual prop types in `.vue` imports (for example to get props validation when using manual `h(...)` calls), you can use the following:
16+
17+
### If Using Volar
18+
19+
Run `Volar: Switch TS Plugin on/off` from VSCode command palette.
20+
21+
### If Using Vetur
22+
23+
1. Install and add `@vuedx/typescript-plugin-vue` to the [plugins section](https://www.typescriptlang.org/tsconfig#plugins) in `tsconfig.json`
24+
2. Delete `src/shims-vue.d.ts` as it is no longer needed to provide module info to Typescript
25+
3. Open `src/main.ts` in VSCode
26+
4. Open the VSCode command palette
27+
5. Search and run "Select TypeScript version" -> "Use workspace version"

examples/vue-ssr/index.html

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="UTF-8" />
5+
<link rel="icon" href="/favicon.ico" />
6+
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
7+
<title>Vite App</title>
8+
</head>
9+
<body>
10+
<div id="app"></div>
11+
<script type="module" src="/src/main.ts"></script>
12+
</body>
13+
</html>

examples/vue-ssr/package.json

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
{
2+
"name": "chakra-ui-vue-ssr",
3+
"version": "0.0.0",
4+
"scripts": {
5+
"dev": "vite-ssr dev",
6+
"build": "echo \"⚡️ Done\"",
7+
"ssr:build": "vite-ssr build",
8+
"serve": "vite preview"
9+
},
10+
"dependencies": {
11+
"@chakra-ui/vue-system": "^0.1.0-alpha.4",
12+
"@vueuse/head": "^0.6.0",
13+
"vite-plugin-components": "^0.12.2",
14+
"vite-plugin-pages": "^0.14.9",
15+
"vite-ssr": "^0.10.6",
16+
"vue": "3",
17+
"vue-router": "4"
18+
},
19+
"devDependencies": {
20+
"@vitejs/plugin-vue": "^1.2.4",
21+
"@vue/compiler-sfc": "^3.0.5",
22+
"typescript": "^4.1.3",
23+
"vite": "^2.4.0",
24+
"vue-tsc": "^0.0.24"
25+
}
26+
}

examples/vue-ssr/public/favicon.ico

4.19 KB
Binary file not shown.

examples/vue-ssr/src/App.vue

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
<template>
2+
<c-reset />
3+
<h1>A small state test for rehydration: {{ count }}</h1>
4+
<button @click="count++">Add to count</button>
5+
<c-h-stack as="nav">
6+
<router-link to="/">Go to Home</router-link>
7+
<router-link to="/component">Go to Component</router-link>
8+
<router-link to="/theme">Go to Theme</router-link>
9+
</c-h-stack>
10+
<h1>Below is the currently rendered route:</h1>
11+
<router-view v-slot="{ Component }">
12+
<component :is="Component" />
13+
</router-view>
14+
</template>
15+
16+
<script lang="ts">
17+
export default {
18+
name: 'App',
19+
data() {
20+
return {
21+
count: 0,
22+
}
23+
},
24+
}
25+
</script>

examples/vue-ssr/src/assets/logo.png

6.69 KB
Loading
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
<template>
2+
<h1>{{ msg }}</h1>
3+
4+
<p>
5+
Recommended IDE setup:
6+
<a href="https://code.visualstudio.com/" target="_blank">VSCode</a>
7+
+
8+
<a
9+
href="https://marketplace.visualstudio.com/items?itemName=octref.vetur"
10+
target="_blank"
11+
>
12+
Vetur
13+
</a>
14+
or
15+
<a href="https://github.com/johnsoncodehk/volar" target="_blank">Volar</a>
16+
(if using
17+
<code>&lt;script setup&gt;</code>)
18+
</p>
19+
20+
<p>See <code>README.md</code> for more information.</p>
21+
22+
<p>
23+
<a href="https://vitejs.dev/guide/features.html" target="_blank">
24+
Vite Docs
25+
</a>
26+
|
27+
<a href="https://v3.vuejs.org/" target="_blank">Vue 3 Docs</a>
28+
</p>
29+
30+
<button type="button" @click="count++">count is: {{ count }}</button>
31+
<p>
32+
Edit
33+
<code>components/HelloWorld.vue</code> to test hot module replacement.
34+
</p>
35+
</template>
36+
37+
<script lang="ts">
38+
import { ref, defineComponent } from 'vue'
39+
export default defineComponent({
40+
name: 'HelloWorld',
41+
props: {
42+
msg: {
43+
type: String,
44+
required: true,
45+
},
46+
},
47+
setup: () => {
48+
const count = ref(0)
49+
return { count }
50+
},
51+
})
52+
</script>
53+
54+
<style scoped>
55+
a {
56+
color: #42b983;
57+
}
58+
59+
label {
60+
margin: 0 0.5em;
61+
font-weight: bold;
62+
}
63+
64+
code {
65+
background-color: #eee;
66+
padding: 2px 4px;
67+
border-radius: 4px;
68+
color: #304455;
69+
}
70+
</style>

examples/vue-ssr/src/main.ts

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
import App from './App.vue'
2+
import viteSSR from 'vite-ssr'
3+
import { createHead } from '@vueuse/head'
4+
import routes from 'virtual:generated-pages'
5+
import Chakra, { chakra } from '@chakra-ui/vue-next'
6+
import { hydrate } from '@emotion/css'
7+
import { domElements } from '@chakra-ui/vue-system'
8+
import { extractCritical } from '@emotion/server'
9+
10+
/**
11+
*
12+
* @param html Page HTML
13+
* @param ids Array of critical ids to hydrate
14+
* @param css Critical CSS string
15+
*/
16+
const injectCritical = (html: string, ids: string[], css: string) =>
17+
html
18+
.replace(
19+
'</title>\n',
20+
`</title>\n<script>window.$emotionSSRIds=${JSON.stringify(
21+
ids
22+
)}</script>\n`
23+
)
24+
.replace('</head>\n', `<style>${css}</style>\n</head>\n`)
25+
26+
export default viteSSR(App, { routes }, ({ app, isClient }) => {
27+
/* custom logic */
28+
/* const { app, router, initialState, ... } = context */
29+
if (isClient) {
30+
// @ts-expect-error Need to add $emotionSSRIds to global namespace
31+
const ssrIds = window?.$emotionSSRIds || []
32+
hydrate(ssrIds)
33+
}
34+
35+
const head = createHead()
36+
app.use(head)
37+
console.log({ app })
38+
39+
/** Extract critical styles */
40+
// const { ids, css } = extractCritical(html)
41+
// /** Append ssr ids to rendered HTML for hydration */
42+
// return injectCritical(html, ids, css)
43+
44+
app.use(Chakra)
45+
46+
domElements.forEach((tag) => {
47+
app.component(`chakra.${tag}`, chakra(tag))
48+
})
49+
})

0 commit comments

Comments
 (0)