-
-
Notifications
You must be signed in to change notification settings - Fork 33.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[feature] allow template to be function in vue-server-renderer #9324
[feature] allow template to be function in vue-server-renderer #9324
Conversation
Please see #9205 for use case It's great for head management, and actually makes the Example of new feature: const { createBundleRenderer } = require("vue-server-renderer")
const renderer = createBundleRenderer(serverbundle, {
async template (result, context){
return `<!DOCTYPE html>
<html>
<head>
${ context.renderStyles() }
</head>
<body>
${result}
</body>
</html>`
}
}) |
8268430
to
638fd27
Compare
Tests for But code works fine |
@yyx990803 will this be making 2.6? If so, I can assist in writing the documentation for this feature |
@@ -23,7 +23,7 @@ export type RenderOptions = { | |||
directives?: Object; | |||
isUnaryTag?: Function; | |||
cache?: RenderCache; | |||
template?: string; | |||
template?: string | (content: string, context: any) => string; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wouldn't (context, content)
be a better API, consistent with, for example, vuex actions, which have context
as their first argument?
…ejs#9324) Also allows return Promise for async handling
What kind of change does this PR introduce? (check at least one)
Does this PR introduce a breaking change? (check one)
If yes, please describe the impact and migration path for existing applications:
The PR fulfills these requirements:
dev
branch for v2.x (or to a previous version branch), not themaster
branchfix #xxx[,#xxx]
, where "xxx" is the issue number)If adding a new feature, the PR's description includes:
Other information:
@yyx990803 I've found a solution to #9205
It's a very simple addition, to the
vue-server-renderer
package that has tonnes of use-cases and actually makes thevue-server-renderer
much easier to use, as it provides a template function to the bundle renderer template compiler.This isn't a breaking change and doesn't really need any tests, as it is a user-provided function
It would be amazing if this could be added in 2.6, so I could use it in my package
Use cases
single file components
(see [ssr] Add Vue function to render VNode to html string #9205)template
optionvue-server-renderer
templater much easier to use, and allows users to use javascript interpolations. For example:<!--vue-ssr-outlet-->
becomes${result}
Bonus
I'm creating a serverside rendering templating engine for Vue that will use this feature. It includes:
<template>
, like native htmlThe package is aimed for users who want to start using Vue but want to keep express/koa routing which will make building serverside applications much easier for users, and will increase Vue adoption in the process