Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: vuepress/core
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: v2.0.0-beta.50
Choose a base ref
...
head repository: vuepress/core
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: v2.0.0-beta.51
Choose a head ref
  • 17 commits
  • 101 files changed
  • 2 contributors

Commits on Aug 23, 2022

  1. Copy the full SHA
    2a93513 View commit details
  2. Copy the full SHA
    84d48f3 View commit details
  3. Verified

    This commit was signed with the committer’s verified signature.
    vcunat Vladimír Čunát
    Copy the full SHA
    9f1afd3 View commit details
  4. Copy the full SHA
    e5238e1 View commit details
  5. Copy the full SHA
    1b63b02 View commit details
  6. Copy the full SHA
    b55fcaf View commit details
  7. build: bump peer-deps

    meteorlxy committed Aug 23, 2022
    Copy the full SHA
    4750c07 View commit details
  8. Copy the full SHA
    bdf2d15 View commit details

Commits on Aug 24, 2022

  1. Copy the full SHA
    b3565cb View commit details
  2. Copy the full SHA
    e418e02 View commit details

Commits on Aug 25, 2022

  1. Copy the full SHA
    6e69a9d View commit details

Commits on Aug 26, 2022

  1. Copy the full SHA
    697e7ae View commit details
  2. feat: support layouts option in client config (#1053)

    BREAKING CHANGE: theme API `layouts` has been removed, layouts should be set in client config instead of theme entry
    BREAKING CHANGE: `404` layout should be renamed to `NotFound` layout
    BREAKING CHANGE: node API `app.layouts` has been removed
    meteorlxy authored Aug 26, 2022
    Copy the full SHA
    a67a0bf View commit details
  3. Copy the full SHA
    99aa8c2 View commit details

Commits on Aug 28, 2022

  1. chore: improve logging

    meteorlxy committed Aug 28, 2022
    Copy the full SHA
    406fa67 View commit details
  2. Copy the full SHA
    ea0a2b2 View commit details
  3. Copy the full SHA
    0e06553 View commit details
Showing with 550 additions and 705 deletions.
  1. +29 −0 CHANGELOG.md
  2. +1 −1 docs/.vuepress/configs/meta.ts
  3. +2 −2 docs/advanced/architecture.md
  4. +16 −0 docs/advanced/cookbook/usage-of-client-config.md
  5. +34 −11 docs/advanced/theme.md
  6. +20 −3 docs/guide/migration.md
  7. +37 −55 docs/reference/default-theme/extending.md
  8. +2 −2 docs/reference/frontmatter.md
  9. +0 −10 docs/reference/node-api.md
  10. +0 −59 docs/reference/theme-api.md
  11. +2 −2 docs/zh/advanced/architecture.md
  12. +17 −1 docs/zh/advanced/cookbook/usage-of-client-config.md
  13. +34 −11 docs/zh/advanced/theme.md
  14. +20 −3 docs/zh/guide/migration.md
  15. +37 −55 docs/zh/reference/default-theme/extending.md
  16. +2 −2 docs/zh/reference/frontmatter.md
  17. +0 −10 docs/zh/reference/node-api.md
  18. +0 −59 docs/zh/reference/theme-api.md
  19. +1 −1 ecosystem/plugin-active-header-links/package.json
  20. +1 −1 ecosystem/plugin-back-to-top/package.json
  21. +1 −1 ecosystem/plugin-container/package.json
  22. +1 −1 ecosystem/plugin-docsearch/package.json
  23. +1 −1 ecosystem/plugin-external-link-icon/package.json
  24. +1 −1 ecosystem/plugin-external-link-icon/tests/node/externalLinkIconPlugin.spec.ts
  25. +1 −1 ecosystem/plugin-git/package.json
  26. +1 −1 ecosystem/plugin-google-analytics/package.json
  27. +1 −1 ecosystem/plugin-medium-zoom/package.json
  28. +1 −1 ecosystem/plugin-nprogress/package.json
  29. +1 −1 ecosystem/plugin-palette/package.json
  30. +1 −1 ecosystem/plugin-prismjs/package.json
  31. +1 −1 ecosystem/plugin-pwa-popup/package.json
  32. +1 −1 ecosystem/plugin-pwa/package.json
  33. +1 −1 ecosystem/plugin-register-components/package.json
  34. +1 −1 ecosystem/plugin-search/package.json
  35. +1 −1 ecosystem/plugin-shiki/package.json
  36. +1 −1 ecosystem/plugin-theme-data/package.json
  37. +1 −1 ecosystem/plugin-toc/package.json
  38. +2 −2 ecosystem/theme-default/package.json
  39. +1 −1 ecosystem/theme-default/src/client/composables/useSidebarItems.ts
  40. +7 −0 ecosystem/theme-default/src/client/config.ts
  41. 0 ecosystem/theme-default/src/client/layouts/{404.vue → NotFound.vue}
  42. +0 −2 ecosystem/theme-default/src/node/defaultTheme.ts
  43. +3 −3 ecosystem/vuepress-vite/package.json
  44. +2 −2 ecosystem/vuepress-webpack/package.json
  45. +1 −1 ecosystem/vuepress/package.json
  46. +1 −1 package.json
  47. +1 −1 packages/bundler-vite/package.json
  48. +13 −6 packages/bundler-vite/src/build/build.ts
  49. +10 −7 packages/bundler-vite/src/build/renderPage.ts
  50. +0 −1 packages/bundler-vite/src/build/renderPagePreloadLinks.ts
  51. +3 −2 packages/bundler-vite/src/dev.ts
  52. +7 −3 packages/bundler-vite/src/plugins/mainPlugin.ts
  53. +1 −1 packages/bundler-webpack/package.json
  54. +22 −7 packages/bundler-webpack/src/build/build.ts
  55. +10 −7 packages/bundler-webpack/src/build/renderPage.ts
  56. +1 −1 packages/bundler-webpack/src/config/handleEntry.ts
  57. +11 −0 packages/bundler-webpack/src/config/handleResolve.ts
  58. +1 −1 packages/cli/package.json
  59. +16 −10 packages/cli/src/commands/build/createBuild.ts
  60. +11 −8 packages/cli/src/commands/dev/createDev.ts
  61. +1 −1 packages/client/package.json
  62. +18 −8 packages/client/src/components/Vuepress.ts
  63. +3 −2 packages/client/src/helpers/defineClientConfig.ts
  64. +5 −0 packages/client/src/types/clientConfig.ts
  65. +0 −5 packages/client/src/types/internal/layoutComponents.d.ts
  66. +1 −1 packages/core/package.json
  67. +0 −4 packages/core/src/app/appPrepare.ts
  68. +1 −1 packages/core/src/app/createBaseApp.ts
  69. +0 −1 packages/core/src/app/index.ts
  70. +0 −1 packages/core/src/app/prepare/index.ts
  71. +0 −23 packages/core/src/app/prepare/prepareLayoutComponents.ts
  72. +1 −1 packages/core/src/app/resolveAppPages.ts
  73. +2 −2 packages/core/src/app/resolveAppVersion.ts
  74. +0 −3 packages/core/src/app/resolveThemeInfo.ts
  75. +0 −31 packages/core/src/app/resolveThemeLayouts.ts
  76. +1 −2 packages/core/src/app/setupAppThemeAndPlugins.ts
  77. +0 −7 packages/core/src/types/app/app.ts
  78. +0 −10 packages/core/src/types/theme.ts
  79. 0 packages/core/tests/__fixtures__/layouts/404.vue
  80. 0 packages/core/tests/__fixtures__/layouts/Bar.vue
  81. 0 packages/core/tests/__fixtures__/layouts/Foo.vue
  82. 0 packages/core/tests/__fixtures__/layouts/Layout.vue
  83. +0 −5 packages/core/tests/__fixtures__/themes/func-extends-grandparent.js
  84. +0 −5 packages/core/tests/__fixtures__/themes/func-extends-parent.js
  85. +0 −5 packages/core/tests/__fixtures__/themes/func.js
  86. +0 −5 packages/core/tests/__fixtures__/themes/obj-extends-grandparent.js
  87. +0 −5 packages/core/tests/__fixtures__/themes/obj-extends-parent.js
  88. +0 −5 packages/core/tests/__fixtures__/themes/obj.js
  89. +1 −1 packages/core/tests/app/resolveAppPages.spec.ts
  90. +0 −34 packages/core/tests/app/resolveThemeInfo.spec.ts
  91. +0 −57 packages/core/tests/app/resolveThemeLayouts.spec.ts
  92. +9 −9 packages/markdown/package.json
  93. +40 −40 packages/markdown/src/markdown.ts
  94. +2 −1 packages/shared/package.json
  95. +2 −6 packages/shared/src/types/page.ts
  96. +1 −1 packages/utils/package.json
  97. +7 −0 packages/utils/src/formatMs.ts
  98. +1 −0 packages/utils/src/index.ts
  99. +7 −5 packages/utils/src/withSpinner.ts
  100. +43 −41 pnpm-lock.yaml
  101. +8 −5 tsconfig.json
29 changes: 29 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,32 @@
# [2.0.0-beta.51](https://github.com/vuepress/vuepress-next/compare/v2.0.0-beta.50...v2.0.0-beta.51) (2022-08-28)


### Bug Fixes

* **bundler-vite:** do not change output entry of client bundle (close [#1043](https://github.com/vuepress/vuepress-next/issues/1043)) ([b3565cb](https://github.com/vuepress/vuepress-next/commit/b3565cba73d0e87540b563d86792bbd2bd219de0))
* **bundler-webpack:** add extensionAlias config ([697e7ae](https://github.com/vuepress/vuepress-next/commit/697e7aef4b27e4b4743895c84860d09681ad0e29))
* **core:** resolve app version correctly ([2a93513](https://github.com/vuepress/vuepress-next/commit/2a935136fca8980cf89146e6d6f1b0a42a50b700))


### Features

* **client:** make args of defineClientConfig optional ([e418e02](https://github.com/vuepress/vuepress-next/commit/e418e02b8c6bb179fd2aae2ce1abb9341038e2d0))
* support layouts option in client config ([#1053](https://github.com/vuepress/vuepress-next/issues/1053)) ([a67a0bf](https://github.com/vuepress/vuepress-next/commit/a67a0bfd806bda548532836ebf8ec1704b7bcb8a))


### Performance Improvements

* reduce memory usage during rendering ([ea0a2b2](https://github.com/vuepress/vuepress-next/commit/ea0a2b213a107c7972da63dededc163c716185d6))


### BREAKING CHANGES

* theme API `layouts` has been removed, layouts should be set in client config instead of theme entry
* `404` layout should be renamed to `NotFound` layout
* node API `app.layouts` has been removed



# [2.0.0-beta.50](https://github.com/vuepress/vuepress-next/compare/v2.0.0-beta.49...v2.0.0-beta.50) (2022-08-23)


2 changes: 1 addition & 1 deletion docs/.vuepress/configs/meta.ts
Original file line number Diff line number Diff line change
@@ -3,6 +3,6 @@ import { fs } from '@vuepress/utils'

const require = createRequire(import.meta.url)

export const version = fs.readJSONSync(
export const version = fs.readJsonSync(
require.resolve('@vuepress/core/package.json')
).version
4 changes: 2 additions & 2 deletions docs/advanced/architecture.md
Original file line number Diff line number Diff line change
@@ -6,13 +6,13 @@

The above figure shows a brief overview of the VuePress architecture:

- Node App will generate temp files, including the layouts, pages, routes, etc.
- Node App will generate temp files, including the pages, routes, etc.
- Bundler will handle Client App together with the temp files, just like a common Vue SPA.

As a developer, you must be aware of that VuePress has two main parts: **Node App** and **Client App**, which is important when developing plugins and themes:

- The entry file of a plugin or a theme will be loaded in Node App.
- Client files will be loaded in Client App, which will be handled by bundler. For example, layouts, components, app setup files, app enhance files, etc.
- Client files will be loaded in Client App, which will be handled by bundler. For example, components, client config files, etc.

## Core Process and Hooks

16 changes: 16 additions & 0 deletions docs/advanced/cookbook/usage-of-client-config.md
Original file line number Diff line number Diff line change
@@ -20,6 +20,7 @@ import { defineClientConfig } from '@vuepress/client'
export default defineClientConfig({
enhance({ app, router, siteData }){},
setup(){},
layouts: {},
rootComponents: [],
})
```
@@ -142,6 +143,21 @@ export default defineClientConfig({
})
```

## layouts

The `layouts` options is to set layout components. After layout components are registered here, users can use it via [layout](../../reference/frontmatter.md#layout) frontmatter.

```ts
import { defineClientConfig } from '@vuepress/client'
import MyLayout from './layouts/MyLayout.vue'

export default defineClientConfig({
layouts: {
MyLayout,
},
})
```

## rootComponents

The `rootComponents` is a components array to be placed directly into the root node of the client vue app.
45 changes: 34 additions & 11 deletions docs/advanced/theme.md
Original file line number Diff line number Diff line change
@@ -14,31 +14,54 @@ import { getDirname, path } from '@vuepress/utils'
const __dirname = getDirname(import.meta.url)

const fooTheme = (options) => {
// returns a theme object
return {
name: 'vuepress-theme-foo',
layouts: {
Layout: path.resolve(__dirname, 'layouts/Layout.vue'),
404: path.resolve(__dirname, 'layouts/404.vue'),
},
// ...

// path to the client config of your theme
clientConfigFile: path.resolve(__dirname, 'client.js'),

// set custom dev / build template
// if the template is not specified, the default template from `@vuepress/client` will be used
templateBuild: path.resolve(__dirname, 'templates/build.html'),
templateDev: path.resolve(__dirname, 'templates/dev.html'),

// use plugins
plugins: [
// ...
],

// other plugin APIs are also available
}
}

const barTheme = (options) => {
// returns a theme function
return (app) => {
return {
name: 'vuepress-theme-bar',
layouts: {
Layout: path.resolve(__dirname, 'layouts/Layout.vue'),
404: path.resolve(__dirname, 'layouts/404.vue'),
},
// ...
}
}
}
```

The `layouts` field declares the layouts provided by your theme. A theme must provide at least two layouts: `Layout` and `404`. The former is to provide default layout for common pages, while the latter is to provide layout for 404 page.
Then, create theme's client config file `client.js` :

```ts
import { defineClientConfig } from '@vuepress/client'
import Layout from './layouts/Layout.vue'
import NotFound from './layouts/NotFound.vue'

export default defineClientConfig({
layouts: {
Layout,
NotFound,
},
})
```

The `layouts` field declares the layouts provided by your theme. A theme must provide at least two layouts: `Layout` and `NotFound`. The former is to provide default layout for common pages, while the latter is to provide layout for 404-not-found page.

The `Layout` layout should contain the [Content](../reference/components.md#content) component to display the markdown content:

@@ -50,7 +73,7 @@ The `Layout` layout should contain the [Content](../reference/components.md#cont
</template>
```

The `404` layout will be used for the `404.html` page:
The `NotFound` layout will be used for the `404.html` page:

```vue
<template>
23 changes: 20 additions & 3 deletions docs/guide/migration.md
Original file line number Diff line number Diff line change
@@ -9,6 +9,7 @@ Some major changes and enhancements of VuePress v2:
- VuePress v2 is now using Vue 3, so make sure your components and other client files are compatible with Vue 3.
- VuePress v2 is developed with TypeScript, so it provides better TS support now. It's highly recommended to use TypeScript to develop plugins and themes. VuePress config file also supports TypeScript, and you can use `.vuepress/config.ts` directly.
- VuePress v2 supports both Webpack and Vite as bundler. Now Vite is the default bundler, while you can still choose to use Webpack. You can even use Vite in dev mode to get better development experience, and use Webpack in build mode to get better browser compatibility.
- VuePress v2 is now released as pure ESM packages, and CommonJS config files are no longer supported.

Core ideas and processes of VuePress v2 are the same with v1, while v2 API has been re-designed and becomes more normalized. So you might encounter breaking changes when migrating an existing v1 project to v2. This guide is here to help you migrating v1 sites / plugins / themes to v2.

@@ -20,6 +21,20 @@ Core ideas and processes of VuePress v2 are the same with v1, while v2 API has b

### User Config Change

Config file should be in ESM format, and CommonJS format config file is no longer supported.

```diff
// .vuepress/config.js

- module.exports = {
- // user config
- }

+ export default {
+ // user config
+ }
```

#### theme

Using a theme via string is not supported. Import the theme directly.
@@ -311,7 +326,7 @@ Some major breaking changes:
- There is no **conventional theme directory structure** anymore.
- The file `theme/enhanceApp.js` will not be used as client app enhance file implicitly. You need to specify it explicitly in `clientConfigFile` hook.
- Files in `theme/global-components/` directory will not be registered as Vue components automatically. You need to use [@vuepress/plugin-register-components](../reference/plugin/register-components.md), or register components manually in `clientConfigFile`.
- Files in `theme/layouts/` directory will not be registered as layout components automatically. You need to specify it explicitly in `layouts` option.
- Files in `theme/layouts/` directory will not be registered as layout components automatically. You need to specify it explicitly in `layouts` option in `clientConfigFile`.
- Files in `theme/templates/` directory will not be used as dev / ssr template automatically. You need to specify theme explicitly in `templateBuild` and `templateDev` option.
- Always provide a valid js entry file, and do not use `"main": "layouts/Layout.vue"` as the theme entry anymore.
- `themeConfig` is removed from user config and site data. To access the `themeConfig` as you would via `this.$site.themeConfig` in v1, we now recommend using the [@vuepress/plugin-theme-data](../reference/plugin/theme-data.md) plugin and its `useThemeData` composition API.
@@ -325,9 +340,11 @@ For more detailed guide about how to write a theme in v2, see [Advanced > Writin

#### layouts

Now you need to specify the layouts directory or layout components manually.
Removed.

Now you need to specify layout component in the client config file of your theme.

See [Theme API > layouts](../reference/theme-api.md#layouts).
See [Advanced > Writing a theme](../advanced/theme.md).

#### extend

92 changes: 37 additions & 55 deletions docs/reference/default-theme/extending.md
Original file line number Diff line number Diff line change
@@ -22,30 +22,20 @@ Default theme's `Layout` provides some slots:

With the help of them, you can add or replace content easily. Here comes an example to introduce how to extend default theme with layout slots.

Firstly, create your local theme `.vuepress/theme/index.ts`:
Firstly, create a client config file `.vuepress/client.ts`:

```ts
import type { Theme } from '@vuepress/core'
import { defaultTheme } from '@vuepress/theme-default'
import type { DefaultThemeOptions } from '@vuepress/theme-default'
import { getDirname, path } from '@vuepress/utils'

const __dirname = getDirname(import.meta.url)
import { defineClientConfig } from '@vuepress/client'
import Layout from './layouts/Layout.vue'

export const localTheme = (options: DefaultThemeOptions): Theme => {
return {
name: 'vuepress-theme-local',
extends: defaultTheme(options),
layouts: {
Layout: path.resolve(__dirname, 'layouts/Layout.vue'),
},
}
}
export default defineClientConfig({
layouts: {
Layout,
},
})
```

Then your theme will extend default theme, and override the `Layout` layout.

Next, create the `.vuepress/theme/layouts/Layout.vue`, and make use of the slots that provided by the `Layout` of default theme:
Next, create the `.vuepress/layouts/Layout.vue`, and make use of the slots that provided by the `Layout` of default theme:

```vue
<script setup>
@@ -67,21 +57,7 @@ import ParentLayout from '@vuepress/theme-default/layouts/Layout.vue'
</style>
```

Finally, remember to use your theme in the config file:

```ts
import { path } from '@vuepress/utils'
import { defineUserConfig } from 'vuepress'
import { localTheme } from './theme'

export default defineUserConfig({
theme: localTheme({
// default theme options
}),
})
```

You will add a custom footer to every normal pages in default theme (excluding homepage):
Then the default `Layout` layout has been overridden by your own local layout, which will add a custom footer to every normal pages in default theme (excluding homepage):

![extending-a-theme](/images/cookbook/extending-a-theme-01.png)

@@ -91,39 +67,45 @@ The layout slots are useful, but sometimes you might find it's not flexible enou

Default theme has registered [alias](../plugin-api.md#alias) for every [non-global components](https://github.com/vuepress/vuepress-next/tree/main/packages/%40vuepress/theme-default/src/client/components) with a `@theme` prefix. For example, the alias of `HomeFooter.vue` is `@theme/HomeFooter.vue`.

Then, if you want to replace the `HomeFooter.vue` component, just override the alias:
Then, if you want to replace the `HomeFooter.vue` component, just override the alias in your config file `.vuepress/config.ts`:

```ts
import type { Theme } from '@vuepress/core'
import { defaultTheme } from '@vuepress/theme-default'
import type { DefaultThemeOptions } from '@vuepress/theme-default'
import { getDirname, path } from '@vuepress/utils'
import { defaultTheme, defineUserConfig } from 'vuepress'

const __dirname = getDirname(import.meta.url)

export const localTheme = (options: DefaultThemeOptions): Theme => {
return {
name: 'vuepress-theme-local',
extends: defaultTheme(options),
alias: {
'@theme/HomeFooter.vue': path.resolve(__dirname, './components/MyHomeFooter.vue'),
},
}
}
export default defineUserConfig({
theme: defaultTheme(),
alias: {
'@theme/HomeFooter.vue': path.resolve(__dirname, './components/MyHomeFooter.vue'),
},
})
```

In fact, you can even use components replacement without extending default theme. The [alias](../plugin-api.md#alias) option is part of [Plugin API](../plugin-api.md), so you only need to set the aliases in your config file to replace components.
## Developing a Child Theme

Instead of extending the default theme directly in `.vuepress/config.ts` and `.vuepress/client.ts`, you can also develop your own theme extending the default theme:

```ts
import type { Theme } from '@vuepress/core'
import { defaultTheme, type DefaultThemeOptions } from '@vuepress/theme-default'
import { getDirname, path } from '@vuepress/utils'
import { defaultTheme, defineUserConfig } from 'vuepress'

const __dirname = getDirname(import.meta.url)

export default defineUserConfig({
theme: defaultTheme(),
alias: {
'@theme/HomeFooter.vue': path.resolve(__dirname, './components/MyHomeFooter.vue'),
},
})
export const childTheme = (options: DefaultThemeOptions): Theme => {
return {
name: 'vuepress-theme-child',
extends: defaultTheme(options),

// override layouts in child theme's client config file
clientConfigFile: path.resolve(__dirname, './client.js'),

// override component alias
alias: {
'@theme/HomeFooter.vue': path.resolve(__dirname, './components/MyHomeFooter.vue'),
},
}
}
```
4 changes: 2 additions & 2 deletions docs/reference/frontmatter.md
Original file line number Diff line number Diff line change
@@ -96,8 +96,8 @@ import { defineClientConfig } from '@vuepress/client'
import CustomLayout from './CustomLayout.vue'

export default defineClientConfig({
enhance({ app }) {
app.component('CustomLayout', CustomLayout)
layouts: {
CustomLayout,
},
})
```
10 changes: 0 additions & 10 deletions docs/reference/node-api.md
Original file line number Diff line number Diff line change
@@ -172,16 +172,6 @@ const dev = async () => {

It is only available in and after [onInitialized](./plugin-api.md#oninitialized) hook.

### layouts

- Type: `Record<string, string>`

- Details:

The layout components map, of which the key is the layout name, the value is the absolute file path of the layout component.

It is only available in and after [onInitialized](./plugin-api.md#oninitialized) hook.

### pages

- Type: `Page[]`
Loading