How to add ssr to a vue-cli 3 project?
See original GitHub issueIn all SSR tutorials with Vue that I found the webpack merge is used to create a configuration for the server. Could you explain quickly how I would do this in the design created by vue-cli 3? I am also using the PWA plugin.
My current code is:
factory.js
...
export default () => new Vue({
router,
store,
render: h => h(App)
})
server.js
const express = require('express')
const { resolve } = require('path')
const fs = require('fs')
global.Vue = require('vue')
const layout = fs.readFileSync(resolve(__dirname, './dist/index.html'), 'utf8')
const renderer = require('vue-server-renderer').createRenderer()
const app = express()
app.use('/dist', express.static(
resolve(__dirname, './dist')
))
app.get('/ssr', (req, res) => {
renderer.renderToString(
require(resolve(__dirname, './src/factory'))(),
(err, html) => {
if (err) {
console.error(err)
return res.status(500).send('Server error')
}
res.send(layout.replace('<div id="app"></div>', html))
}
)
})
app.get('*', (req, res) => {
res.send(layout)
})
app.listen(process.env.PORT || 3000, () => console.log('Running :3000'))
I do not understand how to do it, as it should not be taking the factory.js from the raw code, but compiled.
Issue Analytics
- State:
- Created 5 years ago
- Reactions:1
- Comments:6 (1 by maintainers)
Top Results From Across the Web
Adding server-side-rendering to existing vue 3 project
In this article we will see how to add server side rendering support to existing vue 3 project.I will be using one of...
Read more >Server-Side Rendering (SSR) - Vue.js
Let's take a look at the most bare-bones example of Vue SSR in action. Create a new directory and cd into it; Run...
Read more >How to add ssr to a vue-cli 3 project without webpack?
Step 1: Create a Vue instance const Vue = require('vue') const app ... createRenderer() // Step 3: Render the Vue instance to HTML...
Read more >Vue 3 Server Side Rendering (SSR)
A guide to building and running a server-side rendered Vue 3 application in a Node environment with routing, state, and meta.
Read more >Server Side Rendering with Vue.js 3 - YouTube
This video shows how to create and render a Vue 3 application, using Vue CLI 4.5, Express, and Webpack, on a server.
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Here’s an example project that does SSR and uses vue-cli 3—https://github.com/lentoo/vue-cli-ssr-example
Hi , I write a project for cli3-ssr-project example, see here