This repository has been archived by the owner on Sep 20, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 33
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: add padding and resolve colors for docs
- Loading branch information
1 parent
570818f
commit dcb6226
Showing
56 changed files
with
1,074 additions
and
161 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
node_modules | ||
.DS_Store | ||
dist | ||
dist-ssr | ||
*.local |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
# Vue 3 + Typescript + Vite | ||
|
||
This template should help get you started developing with Vue 3 and Typescript in Vite. | ||
|
||
## Recommended IDE Setup | ||
|
||
[VSCode](https://code.visualstudio.com/) + [Vetur](https://marketplace.visualstudio.com/items?itemName=octref.vetur). Make sure to enable `vetur.experimental.templateInterpolationService` in settings! | ||
|
||
### If Using `<script setup>` | ||
|
||
[`<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). | ||
|
||
## Type Support For `.vue` Imports in TS | ||
|
||
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: | ||
|
||
### If Using Volar | ||
|
||
Run `Volar: Switch TS Plugin on/off` from VSCode command palette. | ||
|
||
### If Using Vetur | ||
|
||
1. Install and add `@vuedx/typescript-plugin-vue` to the [plugins section](https://www.typescriptlang.org/tsconfig#plugins) in `tsconfig.json` | ||
2. Delete `src/shims-vue.d.ts` as it is no longer needed to provide module info to Typescript | ||
3. Open `src/main.ts` in VSCode | ||
4. Open the VSCode command palette | ||
5. Search and run "Select TypeScript version" -> "Use workspace version" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" href="/favicon.ico" /> | ||
<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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
{ | ||
"name": "chakra-ui-vue-ssr", | ||
"version": "0.0.0", | ||
"scripts": { | ||
"dev": "vite-ssr dev", | ||
"build": "echo \"⚡️ Done\"", | ||
"ssr:build": "vite-ssr build", | ||
"serve": "vite preview" | ||
}, | ||
"dependencies": { | ||
"@chakra-ui/vue-system": "^0.1.0-alpha.4", | ||
"@vueuse/head": "^0.6.0", | ||
"vite-plugin-components": "^0.12.2", | ||
"vite-plugin-pages": "^0.14.9", | ||
"vite-ssr": "^0.10.6", | ||
"vue": "3", | ||
"vue-router": "4" | ||
}, | ||
"devDependencies": { | ||
"@vitejs/plugin-vue": "^1.2.4", | ||
"@vue/compiler-sfc": "^3.0.5", | ||
"typescript": "^4.1.3", | ||
"vite": "^2.4.0", | ||
"vue-tsc": "^0.0.24" | ||
} | ||
} |
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
<template> | ||
<c-reset /> | ||
<h1>A small state test for rehydration: {{ count }}</h1> | ||
<button @click="count++">Add to count</button> | ||
<c-h-stack as="nav"> | ||
<router-link to="/">Go to Home</router-link> | ||
<router-link to="/component">Go to Component</router-link> | ||
<router-link to="/theme">Go to Theme</router-link> | ||
</c-h-stack> | ||
<h1>Below is the currently rendered route:</h1> | ||
<router-view v-slot="{ Component }"> | ||
<component :is="Component" /> | ||
</router-view> | ||
</template> | ||
|
||
<script lang="ts"> | ||
export default { | ||
name: 'App', | ||
data() { | ||
return { | ||
count: 0, | ||
} | ||
}, | ||
} | ||
</script> |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
<template> | ||
<h1>{{ msg }}</h1> | ||
|
||
<p> | ||
Recommended IDE setup: | ||
<a href="https://code.visualstudio.com/" target="_blank">VSCode</a> | ||
+ | ||
<a | ||
href="https://marketplace.visualstudio.com/items?itemName=octref.vetur" | ||
target="_blank" | ||
> | ||
Vetur | ||
</a> | ||
or | ||
<a href="https://github.com/johnsoncodehk/volar" target="_blank">Volar</a> | ||
(if using | ||
<code><script setup></code>) | ||
</p> | ||
|
||
<p>See <code>README.md</code> for more information.</p> | ||
|
||
<p> | ||
<a href="https://vitejs.dev/guide/features.html" target="_blank"> | ||
Vite Docs | ||
</a> | ||
| | ||
<a href="https://v3.vuejs.org/" target="_blank">Vue 3 Docs</a> | ||
</p> | ||
|
||
<button type="button" @click="count++">count is: {{ count }}</button> | ||
<p> | ||
Edit | ||
<code>components/HelloWorld.vue</code> to test hot module replacement. | ||
</p> | ||
</template> | ||
|
||
<script lang="ts"> | ||
import { ref, defineComponent } from 'vue' | ||
export default defineComponent({ | ||
name: 'HelloWorld', | ||
props: { | ||
msg: { | ||
type: String, | ||
required: true, | ||
}, | ||
}, | ||
setup: () => { | ||
const count = ref(0) | ||
return { count } | ||
}, | ||
}) | ||
</script> | ||
|
||
<style scoped> | ||
a { | ||
color: #42b983; | ||
} | ||
label { | ||
margin: 0 0.5em; | ||
font-weight: bold; | ||
} | ||
code { | ||
background-color: #eee; | ||
padding: 2px 4px; | ||
border-radius: 4px; | ||
color: #304455; | ||
} | ||
</style> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
import App from './App.vue' | ||
import viteSSR from 'vite-ssr' | ||
import { createHead } from '@vueuse/head' | ||
import routes from 'virtual:generated-pages' | ||
import Chakra, { chakra } from '@chakra-ui/vue-next' | ||
import { hydrate } from '@emotion/css' | ||
import { domElements } from '@chakra-ui/vue-system' | ||
import { extractCritical } from '@emotion/server' | ||
|
||
/** | ||
* | ||
* @param html Page HTML | ||
* @param ids Array of critical ids to hydrate | ||
* @param css Critical CSS string | ||
*/ | ||
const injectCritical = (html: string, ids: string[], css: string) => | ||
html | ||
.replace( | ||
'</title>\n', | ||
`</title>\n<script>window.$emotionSSRIds=${JSON.stringify( | ||
ids | ||
)}</script>\n` | ||
) | ||
.replace('</head>\n', `<style>${css}</style>\n</head>\n`) | ||
|
||
export default viteSSR(App, { routes }, ({ app, isClient }) => { | ||
/* custom logic */ | ||
/* const { app, router, initialState, ... } = context */ | ||
if (isClient) { | ||
// @ts-expect-error Need to add $emotionSSRIds to global namespace | ||
const ssrIds = window?.$emotionSSRIds || [] | ||
hydrate(ssrIds) | ||
} | ||
|
||
const head = createHead() | ||
app.use(head) | ||
console.log({ app }) | ||
|
||
/** Extract critical styles */ | ||
// const { ids, css } = extractCritical(html) | ||
// /** Append ssr ids to rendered HTML for hydration */ | ||
// return injectCritical(html, ids, css) | ||
|
||
app.use(Chakra) | ||
|
||
domElements.forEach((tag) => { | ||
app.component(`chakra.${tag}`, chakra(tag)) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
<template> | ||
<chakra.div bg="tomato" color="white"> | ||
<c-heading> Component </c-heading> | ||
</chakra.div> | ||
</template> | ||
|
||
<script setup lang="ts"></script> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
<template> | ||
<chakra.div bg="purple.700" color="white"> | ||
<c-heading> Home </c-heading> | ||
</chakra.div> | ||
</template> | ||
|
||
<script setup lang="ts"></script> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
<template> | ||
<chakra.div bg="pink" color="white"> | ||
<c-heading> Theme </c-heading> | ||
</chakra.div> | ||
</template> | ||
|
||
<script setup lang="ts"></script> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
declare module '*.vue' { | ||
import { DefineComponent } from 'vue' | ||
const component: DefineComponent<{}, {}, any> | ||
export default component | ||
} | ||
|
||
declare module 'virtual:generated-pages' { | ||
import { RouteRecordRaw } from 'vue-router' | ||
const routes: RouteRecordRaw[] | ||
export default routes | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
/// <reference types="vite/client" /> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
{ | ||
"compilerOptions": { | ||
"target": "esnext", | ||
"module": "esnext", | ||
"moduleResolution": "node", | ||
"strict": true, | ||
"jsx": "preserve", | ||
"sourceMap": true, | ||
"resolveJsonModule": true, | ||
"esModuleInterop": true, | ||
"lib": ["esnext", "dom"] | ||
}, | ||
"include": ["src/**/*.ts", "src/**/*.d.ts", "src/**/*.tsx", "src/**/*.vue"] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import { defineConfig } from 'vite' | ||
import vue from '@vitejs/plugin-vue' | ||
import viteSSR from 'vite-ssr/plugin.js' | ||
import Pages from 'vite-plugin-pages' | ||
import Components from 'vite-plugin-components' | ||
import { componentResolver } from '@chakra-ui/vue-auto-import' | ||
|
||
// https://vitejs.dev/config/ | ||
export default defineConfig({ | ||
plugins: [ | ||
vue(), | ||
viteSSR(), | ||
Pages({ | ||
pagesDir: 'src/pages', | ||
extensions: ['vue', 'ts', 'tsx'], | ||
}), | ||
Components({ | ||
customComponentResolvers: [componentResolver], | ||
}), | ||
], | ||
}) |
Oops, something went wrong.