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

Commit

Permalink
chore: add padding and resolve colors for docs
Browse files Browse the repository at this point in the history
  • Loading branch information
codebender828 committed Jul 9, 2021
1 parent 570818f commit dcb6226
Show file tree
Hide file tree
Showing 56 changed files with 1,074 additions and 161 deletions.
4 changes: 2 additions & 2 deletions babel.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ const baseConfig = function (api) {
],
'@babel/preset-typescript',
]
const plugins = ['@vue/babel-plugin-jsx', '@babel/plugin-transform-runtime']
const plugins = ['@vue/babel-plugin-jsx']

return {
presets,
Expand All @@ -39,7 +39,7 @@ const testConfig = {
},
],
],
plugins: ['@vue/babel-plugin-jsx', '@babel/plugin-transform-runtime'],
plugins: ['@vue/babel-plugin-jsx'],
},
},
}
Expand Down
5 changes: 5 additions & 0 deletions examples/vue-ssr/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
node_modules
.DS_Store
dist
dist-ssr
*.local
27 changes: 27 additions & 0 deletions examples/vue-ssr/README.md
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"
13 changes: 13 additions & 0 deletions examples/vue-ssr/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" 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>
26 changes: 26 additions & 0 deletions examples/vue-ssr/package.json
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 added examples/vue-ssr/public/favicon.ico
Binary file not shown.
25 changes: 25 additions & 0 deletions examples/vue-ssr/src/App.vue
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>
Binary file added examples/vue-ssr/src/assets/logo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
70 changes: 70 additions & 0 deletions examples/vue-ssr/src/components/HelloWorld.vue
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>&lt;script setup&gt;</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>
49 changes: 49 additions & 0 deletions examples/vue-ssr/src/main.ts
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))
})
})
7 changes: 7 additions & 0 deletions examples/vue-ssr/src/pages/component.vue
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>
7 changes: 7 additions & 0 deletions examples/vue-ssr/src/pages/index.vue
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>
7 changes: 7 additions & 0 deletions examples/vue-ssr/src/pages/theme.vue
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>
11 changes: 11 additions & 0 deletions examples/vue-ssr/src/shims-vue.d.ts
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
}
1 change: 1 addition & 0 deletions examples/vue-ssr/src/vite-env.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/// <reference types="vite/client" />
14 changes: 14 additions & 0 deletions examples/vue-ssr/tsconfig.json
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"]
}
21 changes: 21 additions & 0 deletions examples/vue-ssr/vite.config.ts
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],
}),
],
})
Loading

0 comments on commit dcb6226

Please sign in to comment.