Skip to content

Commit 37c8fa4

Browse files
committed
update documentation
1 parent fa0a401 commit 37c8fa4

14 files changed

+302
-88
lines changed

Diff for: .changeset/forty-crabs-beg.md

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
'vue-types-nuxt': major
3+
---
4+
5+
- Remove Nuxt@2 support
6+
- Update vue-types dependency to v6

Diff for: .changeset/wet-bottles-drop.md

+50-5
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,61 @@
11
---
22
'vue-types': major
3-
'vue-types-nuxt': major
43
---
54

6-
## Major changes:
7-
8-
### Drop Vue 2 support
5+
#### Drop Vue 2 support
96

107
Vue 2 reached End of Life (EOL) on December 31st, 2023. By dropping Vue 2 compatibility we can deliver a smaller package and make the source code more maintainable.
118

129
If you're unable to update to Vue 3, please use [email protected]
1310

14-
### Package format review:
11+
#### Removed `VueTypes.extend` method
12+
13+
`VueTypes.extend` was deprecated in v5. In v6 this method has been removed. Please migrate your code to use ES6+ `extends` feature.
14+
15+
Example:
16+
17+
Using `VueTypes.extend` (old):
18+
19+
```js
20+
import VueTypes from 'vue-types';
21+
22+
export const VueTypesProject = VueTypes.extend([
23+
{
24+
name: 'maxLength',
25+
type: String,
26+
validator: (max, v) => v.length <= max,
27+
},
28+
{
29+
name: 'positive',
30+
getter: true,
31+
type: Number,
32+
validator: (v) => v > 0,
33+
},
34+
])
35+
```
36+
37+
Using ES6+ `extends` (new):
38+
39+
```js
40+
import VueTypes, { toType } from 'vue-types'
41+
42+
export class VueTypesProject extends VueTypes {
43+
static maxLength(max) {
44+
return toType('maxLength', {
45+
type: String,
46+
validator: (v) => String(v).length <= max,
47+
})
48+
}
49+
50+
static get positive() {
51+
return toType('positive', {
52+
type: Number,
53+
validator: (v) => v > 0,
54+
})
55+
}
56+
}
57+
```
58+
59+
#### Package format review:
1560
* ESM and CJS builds target is ESNext (browsers with support for the latest JavaScript features).
1661
* UMD builds target is ES2016 (aligned with [Vue 3 browser support](https://vuejs.org/about/faq#what-browsers-does-vue-support))

Diff for: packages/docs/.vitepress/config.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { defineConfig } from 'vitepress'
22
import container from 'markdown-it-container'
3+
import { tabsMarkdownPlugin } from 'vitepress-plugin-tabs'
34
import { version } from '../../core/package.json'
45

56
export default defineConfig({
@@ -8,6 +9,7 @@ export default defineConfig({
89
lastUpdated: true,
910
markdown: {
1011
config(md) {
12+
md.use(tabsMarkdownPlugin)
1113
md.use(container, 'ts', {
1214
render(tokens, idx) {
1315
const token = tokens[idx]
@@ -47,7 +49,6 @@ export default defineConfig({
4749
{ text: 'Using VueTypes', link: '/guide/validators' },
4850
{ text: 'Namespaced Usage', link: '/guide/namespaced' },
4951
{ text: 'Configuration', link: '/guide/configuration' },
50-
{ text: 'Troubleshooting', link: '/guide/troubleshooting' },
5152
],
5253
},
5354
{

Diff for: packages/docs/.vitepress/theme/index.js

-4
This file was deleted.

Diff for: packages/docs/.vitepress/theme/index.ts

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import type { Theme } from 'vitepress'
2+
import DefaultTheme from 'vitepress/theme'
3+
import { enhanceAppWithTabs } from 'vitepress-plugin-tabs/client'
4+
import './index.css'
5+
6+
export default {
7+
extends: DefaultTheme,
8+
enhanceApp({ app }) {
9+
enhanceAppWithTabs(app)
10+
},
11+
} satisfies Theme

Diff for: packages/docs/components/CodeExample.vue

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<script lang="ts">
2+
import { defineComponent, h, resolveComponent, useSlots } from 'vue'
3+
4+
export default defineComponent({
5+
setup() {
6+
const slots = useSlots()
7+
const PluginTabs = resolveComponent('PluginTabs')
8+
const PluginTabsTab = resolveComponent('PluginTabsTab')
9+
const [options, _hr, setup] = slots.default()
10+
11+
return () =>
12+
setup
13+
? h(
14+
PluginTabs,
15+
{
16+
sharedStateKey: 'code',
17+
},
18+
[
19+
h(PluginTabsTab, { label: 'Options API' }, options),
20+
h(PluginTabsTab, { label: 'Setup API' }, setup),
21+
],
22+
)
23+
: h(options)
24+
},
25+
})
26+
</script>

Diff for: packages/docs/guide/configuration.md

+11-4
Original file line numberDiff line numberDiff line change
@@ -7,16 +7,23 @@ Starting from version 4, VueTypes has a global configuration object that can be
77

88
The configuration is exposed both as a property of the default export, and as a named export:
99

10-
```ts
11-
// default exported instance
12-
import VueTypes from 'vue-types'
10+
::: code-group
1311

14-
// named export
12+
```ts [named export]
1513
import { config } from 'vue-types'
1614

1715
VueTypes.config === config
1816
```
1917

18+
```js [default export]
19+
import VueTypes from 'vue-types'
20+
21+
VueTypes.config === config
22+
```
23+
24+
:::
25+
26+
2027
## Configuration Options
2128

2229
- `silent`: (boolean, default `false`) set to `true` to prevent VueTypes from logging validation warnings.

Diff for: packages/docs/guide/installation.md

+12-37
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,9 @@
33
::: warning VERSION NOTE
44
This guide covers VueTypes 2+.
55

6-
- VueTypes 2 is compatible with **Vue 1 and 2**.
6+
- **VueTypes 6+ is compatible with Vue 3**.
77
- VueTypes 4+ is compatible with **Vue 2 and Vue 3**.
8+
- VueTypes 2 is compatible with **Vue 1 and 2**.
89
:::
910

1011
## NPM package
@@ -18,24 +19,24 @@ npm install vue-types --save
1819
Add the following script tags before your code
1920

2021
```html
21-
<script src="https://unpkg.com/vue-types@5"></script>
22+
<script src="https://unpkg.com/vue-types@6"></script>
2223

2324
<!-- Or -->
2425

25-
<script src="https://cdn.jsdelivr.net/npm/vue-types@5/dist/vue-types.umd.js"></script>
26+
<script src="https://cdn.jsdelivr.net/npm/vue-types@6/dist/index.umd.js"></script>
2627
```
2728

2829
In modern browsers [supporting ES Modules](https://caniuse.com/es6-module) you can import the library like this:
2930

3031
```html
3132
<script type="module">
32-
import { string, number } from 'https://unpkg.com/vue-types@5?module'
33+
import { string, number } from 'https://unpkg.com/vue-types@6?module'
3334
</script>
3435

3536
<!-- Or -->
3637

3738
<script type="module">
38-
import { string, number } from 'https://cdn.jsdelivr.net/npm/vue-types@5/+esm'
39+
import { string, number } from 'https://cdn.jsdelivr.net/npm/vue-types@6/+esm'
3940
</script>
4041
```
4142

@@ -49,17 +50,6 @@ Modern bundlers and tools should be able to automatically pick the correct entry
4950
import { string, oneOf } from 'vue-types' // or: import VueTypes from 'vue-types';
5051
```
5152

52-
::: details More details
53-
54-
For reference, here is the list of available entry points:
55-
56-
- `vue-types.modern.js`: ES module for environments [supporting it](https://caniuse.com/es6-module). This is the default entry point for Node 14+, Webpack 5+, Rollup and other tools with native support for ES Modules (like [Vite](https://vitejs.dev/), [Nuxt 3](https://nuxt.com/), Vue CLI 5 and [Snowpack](https://www.snowpack.dev/)).
57-
- `vue-types.m.js`: ES5 compiled version exported as ES module. This is the default entry point for Webpack 4 and frameworks like [Nuxt 2](https://nuxtjs.org/) and [Vue CLI 4](https://cli.vuejs.org/)
58-
- `vue-types.cjs`: ES5 compiled version exported as CommonJS module. This is the default entry point for Node 12 and older and tools not supporting ES Modules.
59-
- `vue-types.umd.js`: ES5 compiled version bundled as UMD module. This entry point can be used when loading VueTypes from a `<script src="...">` tag or from a CDN. It's the default entry point for [unpkg](https://unpkg.com/).
60-
61-
:::
62-
6353
## Production build
6454

6555
Vue.js does not validate components' props when used in a production build. If you're using a bundler such as Webpack or rollup, you can shrink VueTypes file size by around **70%** (minified and gzipped) by removing the validation logic while preserving the library's API methods. To achieve that result, VueTypes ships with a `vue-types/shim` module that can be used as alias in production builds.
@@ -76,12 +66,11 @@ See below for common configuration scenarios.
7666

7767
For reference, here is a table showing the full and shim versions of the library for each module system.
7868

79-
| Module system | Full Library entry point | Shim entry point |
80-
| ------------- | ------------------------ | ---------------------- |
81-
| Modern ES | `vue-types.modern.js` | `shim/index.modern.js` |
82-
| ES5 ES | `vue-types.m.js` | `shim/index.m.js` |
83-
| CommonJS | `vue-types.cjs` | `shim/index.cjs.js` |
84-
| UMD | `vue-types.umd.js` | `shim/index.umd.js` |
69+
| Module system | Full Library entry point | Shim entry point |
70+
| ------------- | ------------------------ | ------------------- |
71+
| ES5 ES | `index.mjs` | `shim/index.mjs` |
72+
| CommonJS | `index.cjs` | `shim/index.cjs` |
73+
| UMD | `index.umd.js` | `shim/index.umd.js` |
8574

8675
:::
8776

@@ -90,7 +79,7 @@ For reference, here is a table showing the full and shim versions of the library
9079
If you're including the library via a `script` tag, use the dedicated shim build file:
9180

9281
```html
93-
<script src="https://unpkg.com/vue-types@5/shim/index.umd.js"></script>
82+
<script src="https://unpkg.com/vue-types@6/shim.umd.js"></script>
9483
```
9584

9685
### Vite
@@ -177,20 +166,6 @@ export default {
177166
}
178167
```
179168

180-
::: warning
181-
In projects using Nuxt 2, use the `buildModules` options:
182-
183-
```js
184-
// nuxt.config.js
185-
186-
export default {
187-
// ...
188-
buildModules: ['vue-types-nuxt'],
189-
}
190-
```
191-
192-
:::
193-
194169
The modules accepts a `shim` boolean option to forcefully enable / disable the shim:
195170

196171
```ts

Diff for: packages/docs/guide/troubleshooting.md

-17
This file was deleted.

0 commit comments

Comments
 (0)