'How to launch Vue.JS instance via node console command and implement SSR?
I'm running node ssr.js <COMPONENT PATH> and I want to get a static html representation of it.
Now from the SingleFileComponent (*.vue) I get the html code from the template, but what is in the script is not executed and is not passed to the Vue instance.
Tell me, how can I launch a Vue instance through the console and display its render?
Import App from 'App.vue' not working, I'm getting error 'Unknown extension *.vue'
import fs from 'fs';
import compiler from 'vue-template-compiler'
import Vue from 'vue'
import render from 'vue-server-renderer'
const parsed = compiler.parseComponent(fs.readFileSync(process.argv[2], 'utf8'));
const app = new Vue({
template: parsed.template.content
})
// Шаг 2: Создаём рендерер
const renderer = render.createRenderer()
// Шаг 3: Рендерим экземпляр Vue в HTML
renderer.renderToString(app, (err, html) => {
if (err) {
throw err
}
console.log(JSON.stringify(html))
})
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
