fix(nitro): add body + body prepended scripts to template (#154)

This commit is contained in:
Daniel Roe 2021-05-19 16:34:44 +01:00 committed by GitHub
parent 0346d6e88a
commit c7328732fb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 18 additions and 5 deletions

View File

@ -4,8 +4,10 @@
{{ HEAD }} {{ HEAD }}
</head> </head>
<body {{ BODY_ATTRS }}> <body {{ BODY_ATTRS }}>
{{ BODY_SCRIPTS_PREPEND }}
<div id="__nuxt">{{ APP }}</div> <div id="__nuxt">{{ APP }}</div>
<% if (nuxtOptions.vite && nuxtOptions.dev) { %><script type="module" src="/@vite/client"></script> <% if (nuxtOptions.vite && nuxtOptions.dev) { %><script type="module" src="/@vite/client"></script>
<script type="module" src="/entry.client.mjs"></script><% } %> <script type="module" src="/entry.client.mjs"></script><% } %>
{{ BODY_SCRIPTS }}
</body> </body>
</html> </html>

View File

@ -84,7 +84,9 @@ function renderHTML (payload, rendered, ssrContext) {
bodyAttrs: '', bodyAttrs: '',
headAttrs: '', headAttrs: '',
headTags: '', headTags: '',
bodyTags: '' bodyTags: '',
bodyScriptsPrepend: '',
bodyScripts: ''
} }
// @vueuse/head // @vueuse/head
@ -100,21 +102,30 @@ function renderHTML (payload, rendered, ssrContext) {
}) })
meta.htmlAttrs += _meta.htmlAttrs.text() meta.htmlAttrs += _meta.htmlAttrs.text()
meta.headAttrs += _meta.headAttrs.text() meta.headAttrs += _meta.headAttrs.text()
meta.bodyAttrs += _meta.bodyAttrs.text()
meta.headTags += meta.headTags +=
_meta.title.text() + _meta.meta.text() + _meta.title.text() + _meta.meta.text() +
_meta.link.text() + _meta.style.text() + _meta.link.text() + _meta.style.text() +
_meta.script.text() + _meta.noscript.text() _meta.script.text() + _meta.noscript.text()
// TODO: Body prepend/append tags meta.bodyAttrs += _meta.bodyAttrs.text()
meta.bodyScriptsPrepend =
_meta.meta.text({ pbody: true }) + _meta.link.text({ pbody: true }) +
_meta.style.text({ pbody: true }) + _meta.script.text({ pbody: true }) +
_meta.noscript.text({ pbody: true })
meta.bodyScripts =
_meta.meta.text({ body: true }) + _meta.link.text({ body: true }) +
_meta.style.text({ body: true }) + _meta.script.text({ body: true }) +
_meta.noscript.text({ body: true })
} }
return htmlTemplate({ return htmlTemplate({
HTML_ATTRS: meta.htmlAttrs, HTML_ATTRS: meta.htmlAttrs,
HEAD_ATTRS: meta.headAttrs, HEAD_ATTRS: meta.headAttrs,
BODY_ATTRS: meta.bodyAttrs,
HEAD: meta.headTags + HEAD: meta.headTags +
rendered.renderResourceHints() + rendered.renderStyles() + (ssrContext.styles || ''), rendered.renderResourceHints() + rendered.renderStyles() + (ssrContext.styles || ''),
APP: _html + state + rendered.renderScripts() BODY_ATTRS: meta.bodyAttrs,
BODY_SCRIPTS_PREPEND: meta.bodyScriptsPrepend,
APP: _html + state + rendered.renderScripts(),
BODY_SCRIPTS: meta.bodyScripts
}) })
} }