-
Notifications
You must be signed in to change notification settings - Fork 668
Add renderToString method #435
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
Conversation
src/renderToString.js
Outdated
Vue.config.devtools = false | ||
|
||
export default function renderToString (component: Component, options: Options = {}): string { | ||
const renderer = require('vue-server-renderer').createRenderer() |
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.
Is there a reason why vue-server-renderer
gets imported using CommonJS and not ESM?
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.
ESM imports are hoisted to the top, so any ESM import will always be bundled.
vue-server-renderer relies on node modules, like path, which makes it difficult to compile with webpack. require is only run when the code runs, so putting it inside the renderToString means we only try and import vue-server-renderer when the renderToString function is run.
We should also add a warning that checks if the user is in node, and we can throw an error if they aren't to tell them renderToString needs to be run in node.
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.
Clear explanation, thank you very much!
I just did a Could you please update the release notes to explain that we need to install vue-server-renderer because of the added I did a |
@dotnetCarpenter thanks for finding this. I've created an issue to remove it as a peerDependency—#440. I think most users won't use |
@eddyerburgh That was not what I intended. If you have an API that has I have a laravel-mix project that does not use SSR, hence do not need vue-server-renderer and I got a nuxt project that already has vue-server-renderer. I prefer nuxt to handle versions of vue-server-renderer but in my laravel-mix project, I have installed it as a But if you want to put in the work to handle it in vue-test-utils, that is of course fine. But I was not aiming at that. 😄 I was just expecting a better explanation to why I have to install a package, I am not using. I think a small update to the release text will suffice. |
renderToString
(Testing server side code #427)