mirror of
https://github.com/nuxt/nuxt.git
synced 2024-11-27 08:02:01 +00:00
parent
e6ca79969a
commit
7831e57943
@ -23,6 +23,7 @@ import {
|
|||||||
createRoutes,
|
createRoutes,
|
||||||
relativeTo,
|
relativeTo,
|
||||||
waitFor,
|
waitFor,
|
||||||
|
serializeFunction,
|
||||||
determineGlobals,
|
determineGlobals,
|
||||||
stripWhitespace,
|
stripWhitespace,
|
||||||
isString
|
isString
|
||||||
@ -440,6 +441,7 @@ export default class Builder {
|
|||||||
const templateOptions = {
|
const templateOptions = {
|
||||||
imports: {
|
imports: {
|
||||||
serialize,
|
serialize,
|
||||||
|
serializeFunction,
|
||||||
devalue,
|
devalue,
|
||||||
hash,
|
hash,
|
||||||
r,
|
r,
|
||||||
|
@ -2,6 +2,7 @@ import path from 'path'
|
|||||||
import escapeRegExp from 'lodash/escapeRegExp'
|
import escapeRegExp from 'lodash/escapeRegExp'
|
||||||
import get from 'lodash/get'
|
import get from 'lodash/get'
|
||||||
import consola from 'consola'
|
import consola from 'consola'
|
||||||
|
import serialize from 'serialize-javascript'
|
||||||
|
|
||||||
export const encodeHtml = function encodeHtml(str) {
|
export const encodeHtml = function encodeHtml(str) {
|
||||||
return str.replace(/</g, '<').replace(/>/g, '>')
|
return str.replace(/</g, '<').replace(/>/g, '>')
|
||||||
@ -457,3 +458,20 @@ export function defineAlias(src, target, prop, opts = {}) {
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function serializeFunction(func) {
|
||||||
|
let open = false
|
||||||
|
return serialize(func)
|
||||||
|
.replace(/^(\s*):(\w+)\(/gm, (_, spaces) => {
|
||||||
|
return `${spaces}:function(`
|
||||||
|
})
|
||||||
|
.replace(/^(\s*)(\w+)\s*\((.*?)\)\s*\{/gm, (_, spaces, name, args) => {
|
||||||
|
if (open) {
|
||||||
|
return `${spaces}${name}:function(${args}) {`
|
||||||
|
} else {
|
||||||
|
open = true
|
||||||
|
return _
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.replace(`${func.name}(`, 'function(')
|
||||||
|
}
|
||||||
|
@ -18,7 +18,7 @@ const layouts = { <%= Object.keys(layouts).map(key => `"_${key}": _${hash(key)}`
|
|||||||
|
|
||||||
export default {
|
export default {
|
||||||
<%= isTest ? '/* eslint-disable quotes, semi, indent, comma-spacing, key-spacing, object-curly-spacing, object-property-newline, arrow-parens */' : '' %>
|
<%= isTest ? '/* eslint-disable quotes, semi, indent, comma-spacing, key-spacing, object-curly-spacing, object-property-newline, arrow-parens */' : '' %>
|
||||||
head: <%= serialize(head).replace(/:\w+\(/gm, ':function(').replace('head(', 'function(') %>,
|
head: <%= serializeFunction(head) %>,
|
||||||
<%= isTest ? '/* eslint-enable quotes, semi, indent, comma-spacing, key-spacing, object-curly-spacing, object-property-newline, arrow-parens */' : '' %>
|
<%= isTest ? '/* eslint-enable quotes, semi, indent, comma-spacing, key-spacing, object-curly-spacing, object-property-newline, arrow-parens */' : '' %>
|
||||||
render(h, props) {
|
render(h, props) {
|
||||||
<% if (loading) { %>const loadingEl = h('NuxtLoading', { ref: 'loading' })<% } %>
|
<% if (loading) { %>const loadingEl = h('NuxtLoading', { ref: 'loading' })<% } %>
|
||||||
|
2
test/fixtures/basic/nuxt.config.js
vendored
2
test/fixtures/basic/nuxt.config.js
vendored
@ -39,7 +39,7 @@ export default {
|
|||||||
},
|
},
|
||||||
head() {
|
head() {
|
||||||
return {
|
return {
|
||||||
titleTemplate: (titleChunk) => {
|
titleTemplate(titleChunk) {
|
||||||
return titleChunk ? `${titleChunk} - Nuxt.js` : 'Nuxt.js'
|
return titleChunk ? `${titleChunk} - Nuxt.js` : 'Nuxt.js'
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user