Skip to content

Commit 2c2d8f3

Browse files
committed
docs: remove cjs syntax
1 parent d283ffe commit 2c2d8f3

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

82 files changed

+442
-486
lines changed

docs/advanced/cookbook/making-a-theme-extendable.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,9 @@ First, set `alias` for replaceable components of you theme:
3030

3131
```ts
3232
import type { Theme } from '@vuepress/core'
33+
import { getDirname } from '@vuepress/utils'
34+
35+
const __dirname = getDirname(import.meta.url)
3336

3437
export const fooTheme = (options): Theme => {
3538
return {

docs/advanced/cookbook/passing-data-to-client-code.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ Plugin API provides a [define](../../reference/plugin-api.md#define) hook to def
88

99
First, define some constants in `define` hook:
1010

11-
```js
12-
module.exports = (options) => ({
11+
```ts
12+
export default (options) => ({
1313
define: {
1414
__FOO__: options.foo || 'str',
1515
__OBJ__: {
@@ -21,7 +21,7 @@ module.exports = (options) => ({
2121

2222
Then use them in client code directly:
2323

24-
```js
24+
```ts
2525
const foo = __FOO__
2626
const obj = __OBJ__
2727
```
@@ -39,8 +39,8 @@ If you need to achieve some more complex features, you can write temp files and
3939
4040
First, write a temp file `foo.js`, which will be generated in the [temp](../../reference/config.md#temp) directory:
4141
42-
```js
43-
module.exports = (options) => ({
42+
```ts
43+
export default (options) => ({
4444
async onPrepared(app) {
4545
// write temp file
4646
await app.writeTemp('foo.js', `export const foo = ${JSON.stringify(options.foo)}`)
@@ -50,7 +50,7 @@ module.exports = (options) => ({
5050

5151
Then, load the temp file via `@temp` alias in client code:
5252

53-
```js
53+
```ts
5454
import { foo } from '@temp/foo'
5555
```
5656

docs/advanced/cookbook/usage-of-client-config.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,9 @@
33
You can make use of the [client config file](../../guide/configuration.md#client-config-file) directly in your project, or specify the file path in your plugin or theme via [clientConfigFile](../../reference/plugin-api.md#clientconfigfile) hook:
44

55
```ts
6-
import { path } from '@vuepress/utils'
6+
import { getDirname, path } from '@vuepress/utils'
7+
8+
const __dirname = getDirname(import.meta.url)
79

810
const pluginOrTheme = {
911
clientConfigFile: path.resolve(__dirname, './path/to/clientConfig.ts'),

docs/advanced/plugin.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ Before reading this guide, you'd better learn the VuePress [architecture](./arch
88

99
A plugin should be a plain JavaScript object that satisfies the [Plugin API](../reference/plugin-api.md), which is called a *Plugin Object*:
1010

11-
```js
11+
```ts
1212
const fooPlugin = {
1313
name: 'vuepress-plugin-foo',
1414
// ...
@@ -17,7 +17,7 @@ const fooPlugin = {
1717

1818
A plugin could also be a function that receives the [app instace](../reference/node-api.md#app) as the param and returns a *Plugin Object*, which is called a *Plugin Function*:
1919

20-
```js
20+
```ts
2121
const barPlugin = (app) => {
2222
return {
2323
name: 'vuepress-plugin-bar',
@@ -28,7 +28,7 @@ const barPlugin = (app) => {
2828

2929
A plugin usually needs to allow user options, so we typically provide users with a function to receive options, and returns a *Plugin Object* or a *Plugin Function*. Then your plugin should be converted like this:
3030

31-
```js
31+
```ts
3232
const fooPlugin = (options) => {
3333
return {
3434
name: 'vuepress-plugin-foo',

docs/advanced/theme.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,10 @@ Before reading this guide, you'd better learn the guide of [Writing a Plugin](./
88

99
A VuePress theme is a special plugin, which should satisfy the [Theme API](../reference/theme-api.md). Like plugins, a theme should also be a *Theme Object* or a *Theme Function*, and could be wrapped with a function to receive options:
1010

11-
```js
12-
const { path } = require('@vuepress/utils')
11+
```ts
12+
import { getDirname, path } from '@vuepress/utils'
13+
14+
const __dirname = getDirname(import.meta.url)
1315

1416
const fooTheme = (options) => {
1517
return {

docs/guide/assets.md

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,8 +92,12 @@ npm install -D package-name
9292

9393
The path aliases that set in config file are also supported:
9494

95-
```js
96-
module.exports = {
95+
```ts
96+
import { getDirname, path } from '@vuepress/utils'
97+
98+
const __dirname = getDirname(import.meta.url)
99+
100+
export default {
97101
alias: {
98102
'@alias': path.resolve(__dirname, './path/to/some/dir'),
99103
},

docs/guide/bundler.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,11 +38,11 @@ Generally, you could use a bundler without extra configuration, because we have
3838

3939
You can configure bundler for advanced usage via the [bundler](../reference/config.md#bundler) option:
4040

41-
```js
42-
const { viteBundler } = require('vuepress')
43-
// const { webpackBundler } = require('vuepress-webpack')
41+
```ts
42+
import { viteBundler } from 'vuepress'
43+
// import { webpackBundler } from 'vuepress-webpack'
4444

45-
module.exports = {
45+
export default {
4646
bundler: viteBundler({
4747
vuePluginOptions: {
4848
template: {

docs/guide/configuration.md

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -34,21 +34,6 @@ vuepress dev docs --config my-config.js
3434

3535
A basic config file looks like this:
3636

37-
<CodeGroup>
38-
<CodeGroupItem title="JS" active>
39-
40-
```js
41-
module.exports = {
42-
lang: 'en-US',
43-
title: 'Hello, VuePress!',
44-
description: 'This is my first VuePress site',
45-
}
46-
```
47-
48-
</CodeGroupItem>
49-
50-
<CodeGroupItem title="TS">
51-
5237
```ts
5338
import { defineUserConfig } from 'vuepress'
5439

@@ -59,9 +44,6 @@ export default defineUserConfig({
5944
})
6045
```
6146

62-
</CodeGroupItem>
63-
</CodeGroup>
64-
6547
::: tip
6648
Check out the [Config Reference](../reference/config.md) for a full list of VuePress config.
6749
:::

docs/guide/i18n.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@ docs
1919

2020
Then, specify the `locales` option in your [config file](./configuration.md#config-file):
2121

22-
```js
23-
module.exports = {
22+
```ts
23+
export default {
2424
locales: {
2525
// The key is the path for the locale to be nested under.
2626
// As a special case, the default locale can use '/' as its path.
@@ -50,10 +50,10 @@ VuePress does not restrict how themes provide multi-language support, so each th
5050

5151
If you are using default theme, the multi-language support is the same as above:
5252

53-
```js
54-
const { defaultTheme } = require('vuepress')
53+
```ts
54+
import { defaultTheme } from 'vuepress'
5555

56-
module.exports = {
56+
export default {
5757
theme: defaultTheme({
5858
locales: {
5959
'/': {

docs/guide/markdown.md

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -339,8 +339,12 @@ Here is a complex example:
339339

340340
Notice that path aliases are not available in import code syntax. You can use following config to handle path alias yourself:
341341

342-
```js
343-
module.exports = {
342+
```ts
343+
import { getDirname, path } from '@vuepress/utils'
344+
345+
const __dirname = getDirname(import.meta.url)
346+
347+
export default {
344348
markdown: {
345349
importCode: {
346350
handleImportPath: (str) =>

0 commit comments

Comments
 (0)