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

Commit 8ef662d

Browse files
committed
docs: add chakra-loader docs tooling
1 parent 43dbe62 commit 8ef662d

File tree

3 files changed

+172
-6
lines changed

3 files changed

+172
-6
lines changed

website/components/SideNavContent.vue

Lines changed: 50 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,41 @@
6767
{{ link.name }}
6868
</CPseudoBox>
6969
</CBox>
70+
<CHeading
71+
size="xs"
72+
color="gray.400"
73+
letter-spacing="wide"
74+
mt="4"
75+
mb="2"
76+
text-transform="uppercase"
77+
>
78+
Tooling
79+
</CHeading>
80+
<CPseudoBox
81+
v-for="(link, index) in toolingLinks"
82+
:key="`${index}-tooling`"
83+
as="nuxt-link"
84+
:to="link.path"
85+
outline="none"
86+
p="0.2rem"
87+
:_focus="{
88+
shadow: 'outline',
89+
}"
90+
:_hover="{
91+
textDecoration: 'none',
92+
transform: 'translateX(3px)'
93+
}"
94+
transition="background-color,transform 0.15s ease-in"
95+
d="block"
96+
rounded="md"
97+
font-weight="bold"
98+
font-size="sm"
99+
text-decoration="none"
100+
:bg="$route.path === link.path ? 'vue.50' : 'transparent'"
101+
:color="$route.path === link.path ? 'vue.700' : 'inherit'"
102+
>
103+
{{ link.name }}
104+
</CPseudoBox>
70105
<CHeading
71106
size="xs"
72107
color="gray.400"
@@ -108,7 +143,7 @@
108143
<script>
109144
import { CBox, CHeading, CPseudoBox } from '@chakra-ui/vue'
110145
import { stringToUrl } from '../utils'
111-
import { components as componentLinks, topNavLinks, aboutNavLinks } from '../utils/all-routes'
146+
import { components as componentLinks, topNavLinks, aboutNavLinks, toolingLinks } from '../utils/all-routes'
112147
113148
export default {
114149
name: 'SideNavContent',
@@ -130,15 +165,24 @@ export default {
130165
return this.$chakraColorMode()
131166
},
132167
topNavLinks () {
133-
return topNavLinks.map(link => ({ name: link, path: stringToUrl(link) }))
168+
return this.parsedLinks(topNavLinks)
134169
},
135170
componentLinks () {
136-
return componentLinks
137-
.filter(link => link !== 'Index')
138-
.map(link => ({ name: link, path: stringToUrl(link) }))
171+
return this.parsedLinks(
172+
componentLinks
173+
.filter(link => link !== 'Index')
174+
)
139175
},
140176
aboutNavLinks () {
141-
return aboutNavLinks.map(link => ({ name: link, path: stringToUrl(link) }))
177+
return this.parsedLinks(aboutNavLinks)
178+
},
179+
toolingLinks () {
180+
return this.parsedLinks(toolingLinks)
181+
},
182+
parsedLinks () {
183+
return value => Array.isArray(value)
184+
? value.map(link => ({ name: link, path: stringToUrl(link) }))
185+
: []
142186
}
143187
}
144188
}
Lines changed: 118 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,118 @@
1+
import SEO from '../components/SEO'
2+
3+
<SEO
4+
title="Auto-import Chakra components"
5+
description="Use the chakra-loader webpack plugin to automatically import and register Chakra components used in your templates"
6+
/>
7+
8+
# Auto-importing Chakra UI Vue components
9+
We know that it can be cumbersome to import every single Chakra component you want to use in your Vue templates. Chakra UI offers webpack plugin solution that allows
10+
you to directly consume Chakra UI Vue components without manually importing and globally registering all Chakra components.
11+
12+
This provides a better developer experience without sacrificing your applications bundle-size performance.
13+
14+
15+
## Installation
16+
With Yarn:
17+
18+
```bash
19+
yarn add chakra-loader -D
20+
```
21+
With NPM:
22+
23+
```bash
24+
npm install chakra-loader --save-dev
25+
```
26+
27+
## Usage
28+
If you're using webpack with Vue CLI or Nuxt.js for your Chakra project, import the `ChakraLoaderPlugin` from the `chakra-loader` package and add it to your `vue.config.js` file.
29+
30+
### With Vue CLI
31+
```js
32+
/* vue.config.js */
33+
34+
const { ChakraLoaderPlugin } = require('chakra-loader')
35+
36+
module.exports = {
37+
configureWebpack: {
38+
plugins: [
39+
new ChakraLoaderPlugin()
40+
]
41+
}
42+
}
43+
44+
```
45+
### With `webpack.config.js`
46+
```js
47+
/* webkack.config.js */
48+
49+
const VueLoaderPlugin = require('vue-loader/lib/plugin')
50+
const { ChakraLoaderPlugin } = require('chakra-loader')
51+
52+
module.exports = {
53+
// ... other options
54+
plugins: [
55+
new VueLoaderPlugin(),
56+
new ChakraLoaderPlugin()
57+
]
58+
}
59+
```
60+
61+
### With Nuxt.js
62+
```js
63+
/* nuxt.config.js */
64+
65+
import { ChakraLoaderPlugin } from 'chakra-loader'
66+
67+
export default {
68+
build: {
69+
extend(config) {
70+
config.plugins.push(
71+
new ChakraLoaderPlugin()
72+
)
73+
}
74+
}
75+
}
76+
```
77+
78+
## How it works
79+
`ChakraLoaderPlugin` will analyse your SFC template at during development and at build time, and scan it for all Chakra UI Vue components that you consume in it. The loader will then proceed to automatically import those components and register them while preserving treeshaking.
80+
81+
For example, consider the component below, `Component.vue` which uses Chakra's `CBox` and `CButton` components.
82+
```vue
83+
<template>
84+
<c-box p="3" m="auto" bg="tomato" font-weight="bold" color="white">
85+
Chakra UI Vue Box
86+
</c-box>
87+
<c-button>
88+
Hello world!
89+
</c-button>
90+
</template>
91+
```
92+
93+
Using `chakra-loader` will yield:
94+
```vue
95+
<template>
96+
<c-box p="3" m="auto" bg="tomato" font-weight="bold" color="white">
97+
Chakra UI Vue Box
98+
</c-box>
99+
<c-button>
100+
Hello world!
101+
</c-button>
102+
</template>
103+
104+
<script>
105+
// 👇🏽 Automatically imports and registers
106+
// the CBox and CButton components from Chakra UI Vue. 🎉
107+
108+
import { CBox, CButton } from '@chakra-ui/vue'
109+
110+
export default {
111+
name: 'App',
112+
components: {
113+
CBox,
114+
CButton
115+
}
116+
}
117+
</script>
118+
```

website/utils/all-routes.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,10 @@ export const aboutNavLinks = [
7979
'Storybook'
8080
]
8181

82+
export const toolingLinks = [
83+
'Auto-import components'
84+
]
85+
8286
export const footerLinks = [
8387
'Contributors'
8488
]

0 commit comments

Comments
 (0)