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: packages/docs/docs/plugin/README.md
+20-18
Original file line number
Diff line number
Diff line change
@@ -456,23 +456,27 @@ import { SOURCE_DIR } from '@dynamic/constans'
456
456
- Type: `Function`
457
457
- Default: `undefined`
458
458
459
-
A function that exports a plain object which will be merged into each page's data object. This function will be invoking once for each page at compile time.
459
+
A function used to extend or modify the [$page](../miscellaneous/global-computed.md#page)object. This function will be invoking once for each page at compile time
460
460
461
461
```js
462
462
module.exports= {
463
-
extendPageData ({
464
-
_filePath, // file's absolute path
465
-
_i18n, // access the client global mixins at build time, e.g _i18n.$localePath.
466
-
_content, // file's raw content string
467
-
_strippedContent, // file's content string without frontmatter
468
-
key, // page's unique hash key
469
-
frontmatter, // page's frontmatter object
470
-
regularPath, // current page's default link (follow the file hierarchy)
471
-
path, // current page's permalink
472
-
}) {
473
-
return {
474
-
// ...
475
-
}
463
+
extendPageData ($page) {
464
+
const {
465
+
_filePath, // file's absolute path
466
+
_i18n, // access the client global mixins at build time, e.g _i18n.$localePath.
467
+
_content, // file's raw content string
468
+
_strippedContent, // file's content string without frontmatter
469
+
key, // page's unique hash key
470
+
frontmatter, // page's frontmatter object
471
+
regularPath, // current page's default link (follow the file hierarchy)
Copy file name to clipboardExpand all lines: packages/docs/docs/zh/plugin/README.md
+62-47
Original file line number
Diff line number
Diff line change
@@ -10,10 +10,10 @@ sidebar: auto
10
10
11
11
Plugins usually add global-level functionality to VuePress. There is no strictly defined scope for a plugin - there are typically several types of plugins:
12
12
13
-
1. Extend the data generated at compile time. e.g. [@vuepress/plugin-last-updated](https://github.com/vuejs/vuepress/tree/next/packages/@vuepress/plugin-last-updated).
14
-
2. Generate extra files before or after compilation. e.g. [@vuepress/plugin-pwa](https://github.com/vuejs/vuepress/tree/next/packages/%40vuepress/plugin-pwa)
15
-
3. Add extra pages. e.g. [@vuepress/plugin-i18n-ui](https://github.com/vuejs/vuepress/tree/next/packages/@vuepress/plugin-i18n-ui)
16
-
4. Inject global UI. e.g. [@vuepress/plugin-back-to-top](https://github.com/vuejs/vuepress/tree/next/packages/%40vuepress/plugin-back-to-top).
13
+
1. Extend the data generated at compile time. e.g. [@vuepress/plugin-last-updated](https://github.com/vuejs/vuepress/tree/master/packages/@vuepress/plugin-last-updated).
14
+
2. Generate extra files before or after compilation. e.g. [@vuepress/plugin-pwa](https://github.com/vuejs/vuepress/tree/master/packages/%40vuepress/plugin-pwa)
15
+
3. Add extra pages. e.g. [@vuepress/plugin-i18n-ui](https://github.com/vuejs/vuepress/tree/master/packages/@vuepress/plugin-i18n-ui)
16
+
4. Inject global UI. e.g. [@vuepress/plugin-back-to-top](https://github.com/vuejs/vuepress/tree/master/packages/%40vuepress/plugin-back-to-top).
17
17
18
18
A plugin should export a `plain object`(`#1`). If the plugin needs to take options, it can be a function that exports a plain object(`#2`). The function will be called with the plugin's options as the first argument, along with [context](#plugin-context) which provides some compile-time metadata.
19
19
@@ -44,7 +44,7 @@ You can use plugins by doing some configuration at `.vuepress/config.js`:
44
44
```js
45
45
module.exports= {
46
46
plugins: [
47
-
require('./my-plugin.js')
47
+
require('./my-plugin.js')
48
48
]
49
49
}
50
50
```
@@ -123,7 +123,7 @@ VuePress also provides a simpler way to use plugins from a dependency:
123
123
```js
124
124
module.exports= {
125
125
plugins: {
126
-
'xxx': { /* options */ }
126
+
'xxx': { /* options */ }
127
127
}
128
128
}
129
129
```
@@ -135,7 +135,7 @@ The plugin can be disabled when `false` is explicitly passed as option.
135
135
136
136
```js
137
137
module.exports= {
138
-
plugins: [
138
+
plugins: [
139
139
[ 'xxx', false ] // disabled.
140
140
]
141
141
}
@@ -160,11 +160,12 @@ module.exports = {
160
160
- Type: `string`
161
161
- Default: undefined
162
162
163
-
The name of the plugin.
163
+
The name of the plugin.
164
164
165
165
Internally, vuepress will use the plugin's package name as the plugin name. When your plugin is a local plugin (i.e. using a pure plugin function directly), please be sure to configure this option, that is good for debug tracking.
166
166
167
167
```js
168
+
// .vuepress/config.js
168
169
module.exports= {
169
170
plugins: [
170
171
[
@@ -177,6 +178,24 @@ module.exports = {
177
178
}
178
179
```
179
180
181
+
### plugins
182
+
183
+
- Type: `array`
184
+
- Default: `undefined`
185
+
186
+
A plug-in can contain multiple plugins like a preset.
187
+
188
+
189
+
```js
190
+
// your plugin
191
+
module.exports= {
192
+
plugins: [
193
+
'tag',
194
+
'category'
195
+
]
196
+
}
197
+
```
198
+
180
199
### enabled
181
200
182
201
- Type: `boolean`
@@ -208,9 +227,9 @@ module.exports = {
208
227
```
209
228
210
229
::: tip
211
-
Since VuePress is a Vue-SSR based application, there will be two webpack configurations, `isServer` is used to determine whether the current webpack config is applied to the server or client.
230
+
Since VuePress is a Vue-SSR based application, there will be two webpack configurations, `isServer` is used to determine whether the current webpack config is applied to the server or client.
212
231
213
-
**Also see:**
232
+
**Also see:**
214
233
215
234
-[Vue SSR > Build Configuration](https://ssr.vuejs.org/guide/build-config.html)
216
235
:::
@@ -230,7 +249,7 @@ module.exports = {
230
249
SW_BASE_URL:JSON.stringify('/')
231
250
})
232
251
])
233
-
}
252
+
}
234
253
}
235
254
```
236
255
@@ -270,7 +289,7 @@ We can set aliases via [chainWebpack](chainwebpack):
Sometimes, you may want to generate some client modules at compile time.
419
438
420
-
```js
439
+
```js
421
440
module.exports= (options, context) => ({
422
441
clientDynamicModules() {
423
442
return {
@@ -434,34 +453,32 @@ Then you can use this module at client side code by:
434
453
import { SOURCE_DIR } from'@dynamic/constans'
435
454
```
436
455
437
-
::: tip Q & A
438
-
**Q**: Both `clientDynamicModules` and `enhanceAppFiles` can generate dynamic javascript code during build time, so what is the difference between the two?
439
-
440
-
**A**: The files generated by `clientDynamicModules` needs to be imported as `@dynamic/xxx` by the consumers themselves. But all the files generated by `enhanceAppFiles` will be loaded automatically when the APP is initialized on the client side.
441
-
:::
442
-
443
456
### extendPageData
444
457
445
458
- Type: `Function`
446
459
- Default: `undefined`
447
460
448
-
A function that exports a plain object which will be merged into each page's data object. This function will be invoking once for each page at compile time.
461
+
A function used to extend or modify the [$page](../miscellaneous/global-computed.md#page)object. This function will be invoking once for each page at compile time
449
462
450
-
```js
463
+
```js
451
464
module.exports= {
452
-
extendPageData ({
453
-
_filePath, // file's absolute path
454
-
_i18n, // access the client global mixins at build time, e.g _i18n.$localePath.
455
-
_content, // file's raw content string
456
-
_strippedContent, // file's content string without frontmatter
457
-
key, // page's unique hash key
458
-
frontmatter, // page's frontmatter object
459
-
regularPath, // current page's default link (follow the file hierarchy)
460
-
path, // current page's permalink
461
-
}) {
462
-
return {
463
-
// ...
464
-
}
465
+
extendPageData ($page) {
466
+
const {
467
+
_filePath, // file's absolute path
468
+
_i18n, // access the client global mixins at build time, e.g _i18n.$localePath.
469
+
_content, // file's raw content string
470
+
_strippedContent, // file's content string without frontmatter
471
+
key, // page's unique hash key
472
+
frontmatter, // page's frontmatter object
473
+
regularPath, // current page's default link (follow the file hierarchy)
@@ -533,7 +548,7 @@ Add a page with explicit content:
533
548
```js
534
549
module.exports= {
535
550
asyncadditionalPages () {
536
-
constrp=require('request-promise');
551
+
constrp=require('request-promise');
537
552
538
553
// VuePress doesn't have request library built-in
539
554
// you need to install it yourself.
@@ -593,7 +608,7 @@ Then, VuePress will automatically inject these components behind the theme conta
593
608
594
609
## Context
595
610
596
-
Starting with VuePress 1.x.x, VuePress provides an `AppContext` object that stores all the state of the current app and can be accessed through the plugin API.
611
+
Starting with VuePress 1.x.x, VuePress provides an `AppContext` object that stores all the state of the current app and can be accessed through the plugin API.
597
612
598
613
::: warning Note
599
614
Context of each plugin is a isolated context, they just inherit from the same app context.
0 commit comments