Last active
June 11, 2020 10:04
-
-
Save nicooprat/a763d53c9954d9b8678e52969048a4e6 to your computer and use it in GitHub Desktop.
Example of vue-server-renderer usage
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const serverRenderer = require('vue-server-renderer') | |
const fs = require('fs') | |
const path = require('path') | |
// Don't need to create Vue components for MJML ones | |
Vue.config.ignoredElements = ['mjml', /^mj-/] | |
// Create a Vue instance | |
const app = new Vue({ | |
template: fs.readFileSync(path.resolve('./mjml.vue'), 'utf8'), | |
data() { | |
return { ... } | |
}, | |
}) | |
// Render Vue to HTML | |
// https://ssr.vuejs.org/guide/#rendering-a-vue-instance | |
const renderer = serverRenderer.createRenderer() | |
renderer.renderToString(app, (err, mjml) => { | |
// Let's go | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment