You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/guide/custom-themes.md
+14Lines changed: 14 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -66,6 +66,20 @@ The compiled content of the current `.md` file being rendered will be available
66
66
</template>
67
67
```
68
68
69
+
## Theme Level Enhancements
70
+
71
+
Themes can extend the Vue app that VuePress uses by exposing an `index.js` file at the root of the theme. The file should `export default` a hook function which will receive an object containing some app level values. You can use this hook to install additional Vue plugins, register global components, or add additional router hooks:
72
+
73
+
```js
74
+
exportdefault ({
75
+
Vue, // the version of Vue being used in the VuePress app
76
+
options, // the options for the root Vue instance
77
+
router // the router instance for the app
78
+
}) => {
79
+
// ...apply enhancements to the app
80
+
}
81
+
```
82
+
69
83
## Using Theme from a Dependency
70
84
71
85
Themes can be published on npm in raw Vue SFC format as `vuepress-theme-xxx`.
Copy file name to clipboardExpand all lines: docs/guide/using-vue.md
+29Lines changed: 29 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -121,6 +121,35 @@ Inside any markdown file you can then directly use the components (names are inf
121
121
Make sure a custom component's name either contains a hyphen or is in PascalCase. Otherwise it will be treated as an inline element and wrapped inside a `<p>` tag, which will lead to hydration mismatch because `<p>` does not allow block elements to be placed inside it.
122
122
:::
123
123
124
+
### Using Pre-processors
125
+
126
+
VuePress has built-in webpack config for the following pre-processors: `sass`, `scss`, `less`, `stylus` and `pug`. All you need to do is installing the corresposnding dependencies. For example, to enable `sass`, install the following in your project:
127
+
128
+
```bash
129
+
yarn add -D sass-loader node-sass
130
+
```
131
+
132
+
Now you can use the following in markdown and theme components:
133
+
134
+
```vue
135
+
<style lang="sass">
136
+
.title
137
+
font-size: 20px
138
+
</style>
139
+
```
140
+
141
+
Using `<template lang="pug">` requires installing `pug` and `pug-plain-loader`:
142
+
143
+
```bash
144
+
yarn add -D pug pug-plain-loader
145
+
```
146
+
147
+
::: tip
148
+
If you are a Stylus user, you don't need to install `stylus` and `stylus-loader` in your project because VuePress uses Stylus internally.
149
+
150
+
For pre-processors that do not have built-in webpack config support, you will need to [extend the internal webpack config](../config/#configurewebpack) in addition to installing the necessary dependencies.
151
+
:::
152
+
124
153
## Script & Style Hoisting
125
154
126
155
Sometimes you may need to apply some JavaScript or CSS only to the current page. In those cases you can directly write root-level `<script>` or `<style>` blocks in the markdown file, and they will be hoisted out of the compiled HTML and used as the `<script>` and `<style>` blocks for the resulting Vue single-file component.
0 commit comments