Skip to content

Commit df9c846

Browse files
authored
feat: @unhead/bundler and /vite subpath exports (#726)
* feat: unified vite plugin per framework, rename @unhead/addons to @unhead/bundler Adds `./vite` export to each framework package (@unhead/vue, @unhead/react, @unhead/svelte, @unhead/solid-js) that composes build optimizations and streaming SSR into a single plugin call. Before: import Unhead from '@unhead/addons/vite' import { unheadVuePlugin } from '@unhead/vue/stream/vite' plugins: [vue(), Unhead(), unheadVuePlugin()] After: import unhead from '@unhead/vue/vite' plugins: [vue(), unhead()] Other changes: - Rename @unhead/addons to @unhead/bundler - Deprecated @unhead/addons alias in packages-aliased/ - Normalize plugin options: all accept `false` to disable - Streaming is opt-in (`streaming: true`) - Deprecate `treeshake.enabled` in favor of `treeshake: false` - Add `moduleType: 'js'` to streaming load hooks for Rolldown compat - Use hook filter objects on resolveId/load for Rolldown performance - Remove stale Vite 4 compat code * docs: update install guides to use unified vite plugin Replace duplicated tree-shaking snippets in schema-org install docs with framework-specific examples using the new unified plugin. Rewrite the main Vite Plugin guide as the canonical reference for all frameworks. Update minify docs to reference the unified plugin. * docs: use generic wording for vite plugin recommendation Focus on the primary benefits (tree-shaking server code, transforming head composables) rather than the niche schema-org stripping.
1 parent 093a277 commit df9c846

File tree

68 files changed

+707
-704
lines changed

Some content is hidden

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

68 files changed

+707
-704
lines changed

bench/ssr-harlanzw-com-e2e.bench.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import type { Head } from 'unhead/types'
2-
import { InferSeoMetaPlugin } from '@unhead/addons'
2+
import { InferSeoMetaPlugin } from '@unhead/bundler'
33
import { definePerson, defineWebPage, defineWebSite, useSchemaOrg } from '@unhead/schema-org/vue'
44
import { bench, describe } from 'vitest'
55
import { useHead, useSeoMeta, useServerHead } from '../packages/vue/src'

bench/ssr-harlanzw-com-e2e.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import type { Head } from 'unhead/types'
2-
import { InferSeoMetaPlugin } from '@unhead/addons'
2+
import { InferSeoMetaPlugin } from '@unhead/bundler'
33
import { definePerson, defineWebPage, defineWebSite, useSchemaOrg } from '@unhead/schema-org/vue'
44
import { TemplateParamsPlugin } from 'unhead/plugins'
55
import { describe, it } from 'vitest'

bench/ssr-harlanzw-no-schema-e2e.bench.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import type { Head } from 'unhead/types'
2-
import { InferSeoMetaPlugin } from '@unhead/addons'
2+
import { InferSeoMetaPlugin } from '@unhead/bundler'
33
import { bench, describe } from 'vitest'
44
import { useHead, useSeoMeta } from '../packages/vue/src'
55
import { createHead as createServerHead, renderSSRHead } from '../packages/vue/src/server'

bench/vitest.config.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ export default defineProject({
88
'unhead/server': resolve(__dirname, '../packages/unhead/src/server'),
99
'unhead/types': resolve(__dirname, '../packages/unhead/src/types'),
1010
'unhead': resolve(__dirname, '../packages/unhead/src'),
11-
'@unhead/addons': resolve(__dirname, '../packages/addons/src'),
11+
'@unhead/bundler': resolve(__dirname, '../packages/bundler/src'),
1212
'@unhead/schema-org': resolve(__dirname, '../packages/schema-org/src'),
1313
'@unhead/vue': resolve(__dirname, '../packages/vue/src'),
1414
},

docs/0.angular/schema-org/guides/get-started/0.installation.md

Lines changed: 2 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -67,22 +67,9 @@ useSchemaOrg([
6767
])
6868
```
6969

70-
## Recommended: Tree-shaking for SSR
70+
## Recommended: Vite Plugin
7171

72-
If you're using Vite SSR, it's highly recommended to add the [Unhead tree-shaking plugin](/docs/head/guides/advanced/vite-plugin).
73-
74-
This will remove the `@unhead/schema-org` dependency from your client bundle, and only include it in your server bundle.
75-
76-
```ts [@unhead/schema-org]
77-
import UnheadVite from '@unhead/addons/vite'
78-
import { defineConfig } from 'vite'
79-
80-
export default defineConfig({
81-
plugins: [
82-
UnheadVite(),
83-
]
84-
})
85-
```
72+
If you're using Vite, the [Vite plugin](/docs/head/guides/advanced/vite-plugin) optimizes your production bundle by tree-shaking server-only code and transforming head composables at build time. See the [Vite Plugin guide](/docs/head/guides/advanced/vite-plugin) for framework-specific setup.
8673

8774
## Optional: Auto-Imports
8875

docs/0.react/schema-org/guides/get-started/0.installation.md

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -65,20 +65,16 @@ useSchemaOrg([
6565
])
6666
```
6767

68-
## Recommended: Tree-shaking for SSR
68+
## Recommended: Vite Plugin
6969

70-
If you're using Vite SSR, it's highly recommended to add the [Unhead tree-shaking plugin](/docs/head/guides/advanced/vite-plugin).
70+
If you're using Vite, the [Vite plugin](/docs/head/guides/advanced/vite-plugin) optimizes your production bundle by tree-shaking server-only code and transforming head composables at build time:
7171

72-
This will remove the `@unhead/schema-org` dependency from your client bundle, and only include it in your server bundle.
73-
74-
```ts [@unhead/schema-org]
75-
import UnheadVite from '@unhead/addons/vite'
76-
import { defineConfig } from 'vite'
72+
```ts
73+
import react from '@vitejs/plugin-react'
74+
import unhead from '@unhead/react/vite'
7775

7876
export default defineConfig({
79-
plugins: [
80-
UnheadVite(),
81-
]
77+
plugins: [react(), unhead()],
8278
})
8379
```
8480

docs/0.solid-js/schema-org/guides/get-started/0.installation.md

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -115,25 +115,19 @@ const head = createHead({
115115

116116
See the [Schema.org Params](/docs/schema-org/guides/core-concepts/params) for all available options.
117117

118-
## Recommended: Tree-shaking for SSR
118+
## Recommended: Vite Plugin
119119

120-
If you're using Vite SSR with Solid.js, it's highly recommended to add the [Unhead tree-shaking plugin](/docs/head/guides/advanced/vite-plugin):
120+
If you're using Vite, the [Vite plugin](/docs/head/guides/advanced/vite-plugin) optimizes your production bundle by tree-shaking server-only code and transforming head composables at build time:
121121

122122
```ts [vite.config.ts]
123-
import UnheadVite from '@unhead/addons/vite'
124-
import { defineConfig } from 'vite'
125-
import solidPlugin from 'vite-plugin-solid'
123+
import solid from 'vite-plugin-solid'
124+
import unhead from '@unhead/solid-js/vite'
126125

127126
export default defineConfig({
128-
plugins: [
129-
solidPlugin(),
130-
UnheadVite(),
131-
]
127+
plugins: [unhead(), solid()],
132128
})
133129
```
134130

135-
This will remove the `@unhead/schema-org` dependency from your client bundle, and only include it in your server bundle.
136-
137131
## Optional: Auto-Imports
138132

139133
If you're using Vite with [unplugin-auto-import](https://github.com/antfu/unplugin-auto-import), you can configure automatic imports for Schema.org composables:

docs/0.svelte/schema-org/guides/get-started/0.installation.md

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -65,20 +65,16 @@ useSchemaOrg([
6565
])
6666
```
6767

68-
## Recommended: Tree-shaking for SSR
68+
## Recommended: Vite Plugin
6969

70-
If you're using Vite SSR, it's highly recommended to add the [Unhead tree-shaking plugin](/docs/head/guides/advanced/vite-plugin).
70+
If you're using Vite, the [Vite plugin](/docs/head/guides/advanced/vite-plugin) optimizes your production bundle by tree-shaking server-only code and transforming head composables at build time:
7171

72-
This will remove the `@unhead/schema-org` dependency from your client bundle, and only include it in your server bundle.
73-
74-
```ts [@unhead/schema-org]
75-
import UnheadVite from '@unhead/addons/vite'
76-
import { defineConfig } from 'vite'
72+
```ts
73+
import { svelte } from '@sveltejs/vite-plugin-svelte'
74+
import unhead from '@unhead/svelte/vite'
7775

7876
export default defineConfig({
79-
plugins: [
80-
UnheadVite(),
81-
]
77+
plugins: [unhead(), svelte()],
8278
})
8379
```
8480

docs/0.typescript/schema-org/guides/get-started/0.installation.md

Lines changed: 2 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -65,22 +65,9 @@ useSchemaOrg([
6565
])
6666
```
6767

68-
## Recommended: Tree-shaking for SSR
68+
## Recommended: Vite Plugin
6969

70-
If you're using Vite SSR, it's highly recommended to add the [Unhead tree-shaking plugin](/docs/head/guides/advanced/vite-plugin).
71-
72-
This will remove the `@unhead/schema-org` dependency from your client bundle, and only include it in your server bundle.
73-
74-
```ts [@unhead/schema-org]
75-
import UnheadVite from '@unhead/addons/vite'
76-
import { defineConfig } from 'vite'
77-
78-
export default defineConfig({
79-
plugins: [
80-
UnheadVite(),
81-
]
82-
})
83-
```
70+
If you're using Vite, the [Vite plugin](/docs/head/guides/advanced/vite-plugin) optimizes your production bundle by tree-shaking server-only code and transforming head composables at build time. See the [Vite Plugin guide](/docs/head/guides/advanced/vite-plugin) for framework-specific setup.
8471

8572
## Optional: Auto-Imports
8673

docs/0.vue/schema-org/guides/0.get-started/0.installation.md

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -69,20 +69,16 @@ useSchemaOrg([
6969
])
7070
```
7171

72-
## Recommended: Tree-shaking for SSR
72+
## Recommended: Vite Plugin
7373

74-
If you're using Vite SSR, it's highly recommended to add the [Unhead tree-shaking plugin](/docs/head/guides/advanced/vite-plugin).
74+
If you're using Vite, the [Vite plugin](/docs/head/guides/advanced/vite-plugin) optimizes your production bundle by tree-shaking server-only code and transforming head composables at build time:
7575

76-
This will remove the `@unhead/schema-org` dependency from your client bundle, and only include it in your server bundle.
77-
78-
```ts [@unhead/schema-org]
79-
import UnheadVite from '@unhead/addons/vite'
80-
import { defineConfig } from 'vite'
76+
```ts
77+
import vue from '@vitejs/plugin-vue'
78+
import unhead from '@unhead/vue/vite'
8179

8280
export default defineConfig({
83-
plugins: [
84-
UnheadVite(),
85-
]
81+
plugins: [vue(), unhead()],
8682
})
8783
```
8884

0 commit comments

Comments
 (0)