Skip to content

Commit

Permalink
feat: add possibility to add additional meta info
Browse files Browse the repository at this point in the history
refactor: server injectors

feat: add head, bodyPrepend, bodyAppend injectors

refactor: create browserbuild through rollup replace (not separate entry)
  • Loading branch information
pimlie committed Sep 17, 2019
1 parent 0e49a9c commit 0ab76ee
Show file tree
Hide file tree
Showing 27 changed files with 378 additions and 376 deletions.
5 changes: 5 additions & 0 deletions examples/ssr/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -138,5 +138,10 @@ export default function createApp () {
</div>`
})

const { set } = app.$meta().addApp('custom')
set({
meta: [{ charset: 'utf-8' }]
})

return { app, router }
}
13 changes: 3 additions & 10 deletions examples/ssr/app.template.html
Original file line number Diff line number Diff line change
@@ -1,23 +1,16 @@
<!doctype html>
<html {{ htmlAttrs.text(true) }}>
<head {{ headAttrs.text() }}>
{{ title.text() }}
{{ meta.text() }}
{{ head(true) }}
<link rel="stylesheet" href="/global.css">
{{ link.text() }}
{{ style.text() }}
{{ script.text() }}
{{ noscript.text() }}
</head>
<body {{ bodyAttrs.text() }}>
{{ script.text({ pbody: true }) }}
{{ noscript.text({ pbody: true }) }}
{{ bodyPrepend(true) }}

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

<script src="/__build__/ssr.js"></script>
{{ script.text({ body: true }) }}
{{ noscript.text({ body: true }) }}
{{ bodyAppend(true) }}
</body>
</html>
17 changes: 10 additions & 7 deletions examples/vue-router/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,13 +64,6 @@ const router = new Router({

const App = {
router,
metaInfo () {
return {
meta: [
{ charset: 'utf=8' }
]
}
},
template: `
<div id="app">
<h1>vue-router</h1>
Expand All @@ -86,7 +79,17 @@ const App = {

const app = new Vue(App)

const { set, remove } = app.$meta().addApp('custom')

set({
meta: [
{ charset: 'utf=8' }
]
})
setTimeout(() => remove(), 3000)

app.$mount('#app')

/*
const waitFor = time => new Promise(r => setTimeout(r, time || 1000))
const o = {
Expand Down
14 changes: 7 additions & 7 deletions scripts/rollup.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ const banner = `/**
* (c) ${new Date().getFullYear()}
* - Declan de Wet
* - Sébastien Chopin (@Atinux)
* - All the amazing contributors
* - Pim (@pimlie)
* - All the amazing contributors
* @license MIT
*/
`
Expand All @@ -39,13 +40,16 @@ function rollupConfig({
...config
}) {

const isBrowserBuild = !config.output || !config.output.format || config.output.format === 'umd' || config.output.file.includes('.browser.')

const replaceConfig = {
exclude: 'node_modules/**',
delimiters: ['', ''],
values: {
// replaceConfig needs to have some values
'const polyfill = process.env.NODE_ENV === \'test\'': 'const polyfill = true',
'process.env.VERSION': `"${version}"`
'process.env.VERSION': `"${version}"`,
'process.server' : isBrowserBuild ? 'false' : 'true'
}
}

Expand All @@ -57,7 +61,7 @@ function rollupConfig({
}*/

return defaultsDeep({}, config, {
input: 'src/browser.js',
input: 'src/index.js',
output: {
name: 'VueMeta',
format: 'umd',
Expand Down Expand Up @@ -92,7 +96,6 @@ export default [
},
// common js build
{
input: 'src/index.js',
output: {
file: pkg.main,
format: 'cjs'
Expand All @@ -101,7 +104,6 @@ export default [
},
// esm build
{
input: 'src/index.js',
output: {
file: pkg.web.replace('.js', '.esm.js'),
format: 'es'
Expand All @@ -110,7 +112,6 @@ export default [
},
// browser esm build
{
input: 'src/browser.js',
output: {
file: pkg.web.replace('.js', '.esm.browser.js'),
format: 'es'
Expand All @@ -119,7 +120,6 @@ export default [
},
// minimized browser esm build
{
input: 'src/browser.js',
output: {
file: pkg.web.replace('.js', '.esm.browser.min.js'),
format: 'es'
Expand Down
37 changes: 0 additions & 37 deletions src/browser.js

This file was deleted.

29 changes: 0 additions & 29 deletions src/client/$meta.js

This file was deleted.

47 changes: 32 additions & 15 deletions src/client/refresh.js
Original file line number Diff line number Diff line change
@@ -1,32 +1,49 @@
import { clientSequences } from '../shared/escaping'
import { showWarningNotSupported } from '../shared/log'
import { getComponentMetaInfo } from '../shared/getComponentOption'
import { getAppsMetaInfo, clearAppsMetaInfo } from '../shared/additional-app'
import getMetaInfo from '../shared/getMetaInfo'
import { isFunction } from '../utils/is-type'
import updateClientMetaInfo from './updateClientMetaInfo'

export default function refresh (options = {}) {
/**
* When called, will update the current meta info with new meta info.
* Useful when updating meta info as the result of an asynchronous
* action that resolves after the initial render takes place.
*
* Credit to [Sébastien Chopin](https://github.com/Atinux) for the suggestion
* to implement this method.
*
* @return {Object} - new meta info
*/
/**
* When called, will update the current meta info with new meta info.
* Useful when updating meta info as the result of an asynchronous
* action that resolves after the initial render takes place.
*
* Credit to [Sébastien Chopin](https://github.com/Atinux) for the suggestion
* to implement this method.
*
* @return {Object} - new meta info
*/
export default function refresh (vm, options = {}) {
// make sure vue-meta was initiated
if (!vm.$root._vueMeta) {
showWarningNotSupported()
return {}
}

// collect & aggregate all metaInfo $options
const rawInfo = getComponentMetaInfo(options, this.$root)
const rawInfo = getComponentMetaInfo(options, vm.$root)

const metaInfo = getMetaInfo(options, rawInfo, clientSequences, this.$root)
const metaInfo = getMetaInfo(options, rawInfo, clientSequences, vm.$root)

const appId = this.$root._vueMeta.appId
const { appId } = vm.$root._vueMeta
const tags = updateClientMetaInfo(appId, options, metaInfo)

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

return { vm: this, metaInfo, tags }
const appsMetaInfo = getAppsMetaInfo()
if (appsMetaInfo) {
for (const additionalAppId in appsMetaInfo) {
updateClientMetaInfo(additionalAppId, options, appsMetaInfo[additionalAppId])
delete appsMetaInfo[additionalAppId]
}
clearAppsMetaInfo(true)
}

return { vm, metaInfo, tags }
}
6 changes: 3 additions & 3 deletions src/index.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { version } from '../package.json'
import createMixin from './shared/mixin'
import { setOptions } from './shared/options'
import $meta from './server/$meta'
import $meta from './shared/$meta'
import generate from './server/generate'
import { hasMetaInfo } from './shared/meta-helpers'

Expand All @@ -27,6 +27,6 @@ function install (Vue, options = {}) {
export default {
version,
install,
hasMetaInfo,
generate
generate: process.server ? generate : () => {},
hasMetaInfo
}
19 changes: 0 additions & 19 deletions src/server/$meta.js

This file was deleted.

4 changes: 3 additions & 1 deletion src/server/generate.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,7 @@ import generateServerInjector from './generateServerInjector'

export default function generate (rawInfo, options = {}) {
const metaInfo = getMetaInfo(setOptions(options), rawInfo, serverSequences)
return generateServerInjector(options, metaInfo)

const serverInjector = generateServerInjector(options, metaInfo)
return serverInjector.injectors
}

0 comments on commit 0ab76ee

Please sign in to comment.