mirror of
https://github.com/tenrok/vue-meta.git
synced 2026-06-21 11:40:33 +03:00
feat: add browser build without ssr code
This commit is contained in:
@@ -14,7 +14,7 @@ const banner = `/**
|
||||
`.replace(/ {4}/gm, '').trim()
|
||||
|
||||
const baseConfig = {
|
||||
input: 'src/index.js',
|
||||
input: 'src/browser.js',
|
||||
output: {
|
||||
file: pkg.web,
|
||||
format: 'umd',
|
||||
@@ -44,6 +44,7 @@ export default [{
|
||||
]
|
||||
}, {
|
||||
...baseConfig,
|
||||
input: 'src/index.js',
|
||||
output: {
|
||||
...baseConfig.output,
|
||||
file: pkg.main,
|
||||
|
||||
@@ -0,0 +1,20 @@
|
||||
import { version } from '../package.json'
|
||||
import createMixin from './shared/mixin'
|
||||
import setOptions from './shared/options'
|
||||
import $meta from './client/$meta'
|
||||
|
||||
/**
|
||||
* Plugin install function.
|
||||
* @param {Function} Vue - the Vue constructor.
|
||||
*/
|
||||
function VueMeta(Vue, options = {}) {
|
||||
options = setOptions(options)
|
||||
|
||||
Vue.prototype.$meta = $meta(options)
|
||||
|
||||
Vue.mixin(createMixin(options))
|
||||
}
|
||||
|
||||
VueMeta.version = version
|
||||
|
||||
export default VueMeta
|
||||
@@ -0,0 +1,14 @@
|
||||
import refresh from './refresh'
|
||||
|
||||
export default function _$meta(options = {}) {
|
||||
/**
|
||||
* Returns an injector for server-side rendering.
|
||||
* @this {Object} - the Vue instance (a root component)
|
||||
* @return {Object} - injector
|
||||
*/
|
||||
return function $meta() {
|
||||
return {
|
||||
refresh: refresh(options).bind(this)
|
||||
}
|
||||
}
|
||||
}
|
||||
+17
-3
@@ -1,6 +1,20 @@
|
||||
import { version } from '../package.json'
|
||||
import install from './shared/plugin'
|
||||
import createMixin from './shared/mixin'
|
||||
import setOptions from './shared/options'
|
||||
import $meta from './server/$meta'
|
||||
|
||||
install.version = version
|
||||
/**
|
||||
* Plugin install function.
|
||||
* @param {Function} Vue - the Vue constructor.
|
||||
*/
|
||||
function VueMeta(Vue, options = {}) {
|
||||
options = setOptions(options)
|
||||
|
||||
export default install
|
||||
Vue.prototype.$meta = $meta(options)
|
||||
|
||||
Vue.mixin(createMixin(options))
|
||||
}
|
||||
|
||||
VueMeta.version = version
|
||||
|
||||
export default VueMeta
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import inject from '../server/inject'
|
||||
import refresh from '../client/refresh'
|
||||
import inject from './inject'
|
||||
|
||||
export default function _$meta(options = {}) {
|
||||
/**
|
||||
@@ -1,48 +1,7 @@
|
||||
import batchUpdate from '../client/batchUpdate'
|
||||
import { isUndefined, isFunction, isObject } from '../shared/typeof'
|
||||
import $meta from './$meta'
|
||||
|
||||
import {
|
||||
keyName,
|
||||
attribute,
|
||||
ssrAttribute,
|
||||
tagIDKeyName,
|
||||
metaTemplateKeyName,
|
||||
contentKeyName
|
||||
} from './constants'
|
||||
|
||||
// automatic install
|
||||
if (!isUndefined(window) && !isUndefined(window.Vue)) {
|
||||
Vue.use(VueMeta)
|
||||
}
|
||||
|
||||
/**
|
||||
* Plugin install function.
|
||||
* @param {Function} Vue - the Vue constructor.
|
||||
*/
|
||||
export default function VueMeta(Vue, options = {}) {
|
||||
// set some default options
|
||||
const defaultOptions = {
|
||||
keyName,
|
||||
contentKeyName,
|
||||
metaTemplateKeyName,
|
||||
attribute,
|
||||
ssrAttribute,
|
||||
tagIDKeyName
|
||||
}
|
||||
|
||||
// combine options
|
||||
options = isObject('object') ? options : {}
|
||||
|
||||
for (const key in defaultOptions) {
|
||||
if (!options[key]) {
|
||||
options[key] = defaultOptions[key]
|
||||
}
|
||||
}
|
||||
|
||||
// bind the $meta method to this component instance
|
||||
Vue.prototype.$meta = $meta(options)
|
||||
import { isUndefined, isFunction } from '../shared/typeof'
|
||||
|
||||
export default function createMixin(options) {
|
||||
// store an id to keep track of DOM updates
|
||||
let batchID = null
|
||||
|
||||
@@ -55,7 +14,7 @@ export default function VueMeta(Vue, options = {}) {
|
||||
}
|
||||
|
||||
// watch for client side component updates
|
||||
Vue.mixin({
|
||||
return {
|
||||
beforeCreate() {
|
||||
// Add a marker to know if it uses metaInfo
|
||||
// _vnode is used to know that it's attached to a real component
|
||||
@@ -159,5 +118,5 @@ export default function VueMeta(Vue, options = {}) {
|
||||
}, 50)
|
||||
}
|
||||
}/**/
|
||||
})
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
import { isObject } from '../shared/typeof'
|
||||
import {
|
||||
keyName,
|
||||
attribute,
|
||||
ssrAttribute,
|
||||
tagIDKeyName,
|
||||
metaTemplateKeyName,
|
||||
contentKeyName
|
||||
} from './constants'
|
||||
|
||||
// set some default options
|
||||
const defaultOptions = {
|
||||
keyName,
|
||||
contentKeyName,
|
||||
metaTemplateKeyName,
|
||||
attribute,
|
||||
ssrAttribute,
|
||||
tagIDKeyName
|
||||
}
|
||||
|
||||
export default function setOptions(options) {
|
||||
// combine options
|
||||
options = isObject('object') ? options : {}
|
||||
|
||||
for (const key in defaultOptions) {
|
||||
if (!options[key]) {
|
||||
options[key] = defaultOptions[key]
|
||||
}
|
||||
}
|
||||
|
||||
return options
|
||||
}
|
||||
Reference in New Issue
Block a user