Skip to content

Commit

Permalink
docs: declare that themePath/index.js is required
Browse files Browse the repository at this point in the history
When you want to publish your theme as an npm package, make sure the package has `index.js`, and set
`"main"` field at `package.json` to `index.js` so that VuePress can resolve and get the correct
themePath.
  • Loading branch information
ulivz committed Oct 17, 2018
1 parent 8b56f98 commit 7759d54
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 8 deletions.
16 changes: 13 additions & 3 deletions packages/docs/docs/theme/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ Just one `Layout.vue` might not be enough, and you might also want to define mor
So it's time to reorganize your theme, an agreed theme directory structure is as follows:

::: vue
theme
themePath
β”œβ”€β”€ `global-components` _(**Optional**)_
β”‚ └── xxx.vue
β”œβ”€β”€ `components` _(**Optional**)_
Expand All @@ -42,7 +42,7 @@ theme
β”œβ”€β”€ `templates` _(**Optional**)_
β”‚ Β  β”œβ”€β”€ dev.html
β”‚ Β  └── ssr.html
β”œβ”€β”€ `index.js` _(**Optional**)_
β”œβ”€β”€ `index.js` _(**Only required when you publish it as an npm package**)_
β”œβ”€β”€ `enhanceApp.js` _(**Optional**)_
└── package.json
:::
Expand All @@ -56,7 +56,17 @@ theme
- `theme/enhanceApp.js`: Theme level enhancements.

::: warning Note
Considering backward compatibility, Vue components located at theme root directory will also be automatically registered as layout components. But the recommended is placing them under `layouts` directory, which looks more clearer.
1. Considering backward compatibility, Vue components located at [themePath](../miscellaneous/glossary.md#theme-side) will also be automatically registered as layout components. But the recommended is placing them under `themePath/layouts` directory, which looks more clearer.
2. When you want to publish your theme as an npm package, make sure the package has `index.js`, and set `"main"` field at `package.json` to `index.js` so that VuePress can resolve and get the correct [themePath](../miscellaneous/glossary.md#theme-side).

```json
{
...
"main": "index.js"
...
}
```

:::

### Layout Component
Expand Down
2 changes: 1 addition & 1 deletion packages/docs/docs/zh/plugin/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ sidebar: auto

# Plugins

> To be translated soon.
> Translation are welcome!
## Writing a Plugin

Expand Down
20 changes: 16 additions & 4 deletions packages/docs/docs/zh/theme/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ sidebar: auto

# Theme

> Translation are welcome!
::: tip
Theme components are subject to the same [browser API access restrictions](../guide/using-vue.md#browser-api-access-restrictions).
:::
Expand All @@ -28,7 +30,7 @@ Just one `Layout.vue` might not be enough, and you might also want to define mor
So it's time to reorganize your theme, an agreed theme directory structure is as follows:

::: vue
theme
themePath
β”œβ”€β”€ `global-components` _(**Optional**)_
β”‚ └── xxx.vue
β”œβ”€β”€ `components` _(**Optional**)_
Expand All @@ -42,21 +44,31 @@ theme
β”œβ”€β”€ `templates` _(**Optional**)_
β”‚ Β  β”œβ”€β”€ dev.html
β”‚ Β  └── ssr.html
β”œβ”€β”€ `index.js` _(**Optional**)_
β”œβ”€β”€ `index.js` _(**Only required when you publish it as an npm package**)_
β”œβ”€β”€ `enhanceApp.js` _(**Optional**)_
└── package.json
:::

- `theme/global-components`: Components under this directory will be automatically registered as global components. For details, please refer to [@vuepress/plugin-register-components](https://github.com/vuejs/vuepress/tree/master/packages/@vuepress/plugin-register-components).
- `theme/components`: Your components.
- `theme/layouts`: Layout components of the theme, where `Layout.vue` is required.
- `theme/styles`: Global style and palette.
- `theme/styles`: Global style and palette.
- `theme/templates`: Modify default template.
- `theme/index.js`: Entry file of theme configuration.
- `theme/enhanceApp.js`: Theme level enhancements.

::: warning Note
Considering backward compatibility, Vue components located at theme root directory will also be automatically registered as layout components. But the recommended is placing them under `layouts` directory, which looks more clearer.
1. Considering backward compatibility, Vue components located at [themePath](../miscellaneous/glossary.md#theme-side) will also be automatically registered as layout components. But the recommended is placing them under `themePath/layouts` directory, which looks more clearer.
2. When you want to publish your theme as an npm package, make sure the package has `index.js`, and set `"main"` field at `package.json` to `index.js` so that VuePress can resolve and get the correct [themePath](../miscellaneous/glossary.md#theme-side).

```json
{
...
"main": "index.js"
...
}
```

:::

### Layout Component
Expand Down

0 comments on commit 7759d54

Please sign in to comment.