Skip to content

Commit 0ab76ee

Browse files
committed
feat: add possibility to add additional meta info
refactor: server injectors feat: add head, bodyPrepend, bodyAppend injectors refactor: create browserbuild through rollup replace (not separate entry)
1 parent 0e49a9c commit 0ab76ee

27 files changed

+378
-376
lines changed

examples/ssr/App.js

+5
Original file line numberDiff line numberDiff line change
@@ -138,5 +138,10 @@ export default function createApp () {
138138
</div>`
139139
})
140140

141+
const { set } = app.$meta().addApp('custom')
142+
set({
143+
meta: [{ charset: 'utf-8' }]
144+
})
145+
141146
return { app, router }
142147
}

examples/ssr/app.template.html

+3-10
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,16 @@
11
<!doctype html>
22
<html {{ htmlAttrs.text(true) }}>
33
<head {{ headAttrs.text() }}>
4-
{{ title.text() }}
5-
{{ meta.text() }}
4+
{{ head(true) }}
65
<link rel="stylesheet" href="/global.css">
7-
{{ link.text() }}
8-
{{ style.text() }}
9-
{{ script.text() }}
10-
{{ noscript.text() }}
116
</head>
127
<body {{ bodyAttrs.text() }}>
13-
{{ script.text({ pbody: true }) }}
14-
{{ noscript.text({ pbody: true }) }}
8+
{{ bodyPrepend(true) }}
159

1610
<a href="/">&larr; Examples index</a>
1711
{{ app }}
1812

1913
<script src="/__build__/ssr.js"></script>
20-
{{ script.text({ body: true }) }}
21-
{{ noscript.text({ body: true }) }}
14+
{{ bodyAppend(true) }}
2215
</body>
2316
</html>

examples/vue-router/app.js

+10-7
Original file line numberDiff line numberDiff line change
@@ -64,13 +64,6 @@ const router = new Router({
6464

6565
const App = {
6666
router,
67-
metaInfo () {
68-
return {
69-
meta: [
70-
{ charset: 'utf=8' }
71-
]
72-
}
73-
},
7467
template: `
7568
<div id="app">
7669
<h1>vue-router</h1>
@@ -86,7 +79,17 @@ const App = {
8679

8780
const app = new Vue(App)
8881

82+
const { set, remove } = app.$meta().addApp('custom')
83+
84+
set({
85+
meta: [
86+
{ charset: 'utf=8' }
87+
]
88+
})
89+
setTimeout(() => remove(), 3000)
90+
8991
app.$mount('#app')
92+
9093
/*
9194
const waitFor = time => new Promise(r => setTimeout(r, time || 1000))
9295
const o = {

scripts/rollup.config.js

+7-7
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@ const banner = `/**
1515
* (c) ${new Date().getFullYear()}
1616
* - Declan de Wet
1717
* - Sébastien Chopin (@Atinux)
18-
* - All the amazing contributors
18+
* - Pim (@pimlie)
19+
* - All the amazing contributors
1920
* @license MIT
2021
*/
2122
`
@@ -39,13 +40,16 @@ function rollupConfig({
3940
...config
4041
}) {
4142

43+
const isBrowserBuild = !config.output || !config.output.format || config.output.format === 'umd' || config.output.file.includes('.browser.')
44+
4245
const replaceConfig = {
4346
exclude: 'node_modules/**',
4447
delimiters: ['', ''],
4548
values: {
4649
// replaceConfig needs to have some values
4750
'const polyfill = process.env.NODE_ENV === \'test\'': 'const polyfill = true',
48-
'process.env.VERSION': `"${version}"`
51+
'process.env.VERSION': `"${version}"`,
52+
'process.server' : isBrowserBuild ? 'false' : 'true'
4953
}
5054
}
5155

@@ -57,7 +61,7 @@ function rollupConfig({
5761
}*/
5862

5963
return defaultsDeep({}, config, {
60-
input: 'src/browser.js',
64+
input: 'src/index.js',
6165
output: {
6266
name: 'VueMeta',
6367
format: 'umd',
@@ -92,7 +96,6 @@ export default [
9296
},
9397
// common js build
9498
{
95-
input: 'src/index.js',
9699
output: {
97100
file: pkg.main,
98101
format: 'cjs'
@@ -101,7 +104,6 @@ export default [
101104
},
102105
// esm build
103106
{
104-
input: 'src/index.js',
105107
output: {
106108
file: pkg.web.replace('.js', '.esm.js'),
107109
format: 'es'
@@ -110,7 +112,6 @@ export default [
110112
},
111113
// browser esm build
112114
{
113-
input: 'src/browser.js',
114115
output: {
115116
file: pkg.web.replace('.js', '.esm.browser.js'),
116117
format: 'es'
@@ -119,7 +120,6 @@ export default [
119120
},
120121
// minimized browser esm build
121122
{
122-
input: 'src/browser.js',
123123
output: {
124124
file: pkg.web.replace('.js', '.esm.browser.min.js'),
125125
format: 'es'

src/browser.js

-37
This file was deleted.

src/client/$meta.js

-29
This file was deleted.

src/client/refresh.js

+32-15
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,49 @@
11
import { clientSequences } from '../shared/escaping'
2+
import { showWarningNotSupported } from '../shared/log'
23
import { getComponentMetaInfo } from '../shared/getComponentOption'
4+
import { getAppsMetaInfo, clearAppsMetaInfo } from '../shared/additional-app'
35
import getMetaInfo from '../shared/getMetaInfo'
46
import { isFunction } from '../utils/is-type'
57
import updateClientMetaInfo from './updateClientMetaInfo'
68

7-
export default function refresh (options = {}) {
8-
/**
9-
* When called, will update the current meta info with new meta info.
10-
* Useful when updating meta info as the result of an asynchronous
11-
* action that resolves after the initial render takes place.
12-
*
13-
* Credit to [Sébastien Chopin](https://github.com/Atinux) for the suggestion
14-
* to implement this method.
15-
*
16-
* @return {Object} - new meta info
17-
*/
9+
/**
10+
* When called, will update the current meta info with new meta info.
11+
* Useful when updating meta info as the result of an asynchronous
12+
* action that resolves after the initial render takes place.
13+
*
14+
* Credit to [Sébastien Chopin](https://github.com/Atinux) for the suggestion
15+
* to implement this method.
16+
*
17+
* @return {Object} - new meta info
18+
*/
19+
export default function refresh (vm, options = {}) {
20+
// make sure vue-meta was initiated
21+
if (!vm.$root._vueMeta) {
22+
showWarningNotSupported()
23+
return {}
24+
}
25+
1826
// collect & aggregate all metaInfo $options
19-
const rawInfo = getComponentMetaInfo(options, this.$root)
27+
const rawInfo = getComponentMetaInfo(options, vm.$root)
2028

21-
const metaInfo = getMetaInfo(options, rawInfo, clientSequences, this.$root)
29+
const metaInfo = getMetaInfo(options, rawInfo, clientSequences, vm.$root)
2230

23-
const appId = this.$root._vueMeta.appId
31+
const { appId } = vm.$root._vueMeta
2432
const tags = updateClientMetaInfo(appId, options, metaInfo)
2533

2634
// emit "event" with new info
2735
if (tags && isFunction(metaInfo.changed)) {
2836
metaInfo.changed(metaInfo, tags.addedTags, tags.removedTags)
2937
}
3038

31-
return { vm: this, metaInfo, tags }
39+
const appsMetaInfo = getAppsMetaInfo()
40+
if (appsMetaInfo) {
41+
for (const additionalAppId in appsMetaInfo) {
42+
updateClientMetaInfo(additionalAppId, options, appsMetaInfo[additionalAppId])
43+
delete appsMetaInfo[additionalAppId]
44+
}
45+
clearAppsMetaInfo(true)
46+
}
47+
48+
return { vm, metaInfo, tags }
3249
}

src/index.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { version } from '../package.json'
22
import createMixin from './shared/mixin'
33
import { setOptions } from './shared/options'
4-
import $meta from './server/$meta'
4+
import $meta from './shared/$meta'
55
import generate from './server/generate'
66
import { hasMetaInfo } from './shared/meta-helpers'
77

@@ -27,6 +27,6 @@ function install (Vue, options = {}) {
2727
export default {
2828
version,
2929
install,
30-
hasMetaInfo,
31-
generate
30+
generate: process.server ? generate : () => {},
31+
hasMetaInfo
3232
}

src/server/$meta.js

-19
This file was deleted.

src/server/generate.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,7 @@ import generateServerInjector from './generateServerInjector'
55

66
export default function generate (rawInfo, options = {}) {
77
const metaInfo = getMetaInfo(setOptions(options), rawInfo, serverSequences)
8-
return generateServerInjector(options, metaInfo)
8+
9+
const serverInjector = generateServerInjector(options, metaInfo)
10+
return serverInjector.injectors
911
}

0 commit comments

Comments
 (0)