vue-cli v3, can't get it to work.. no errors but pre-rendered routes don't contain static html #215
Comments
still haven't figured it out. But I decided to try with a fresh vue-cli project (rc3) and that works fine you might like to use this repo to add another example https://github.com/vesper8/vue-cli-3-prerender-spa-plugin-demo Would still appreciate your thoughts on what might be causing this.. I will report back if I figure it out as well |
ok.. I found the guilty party.. it's this line
I tried both paths separately
This is pretty problematic... but let's see if I can work around it |
Yeah, I haven't figured out the ideal way to deal with webpack's various output modifying settings. However, you might also want to configure the renderer like so: new PrerenderSPAPlugin({
staticDir: path.join(__dirname, 'dist'),
routes: [
'/',
'/about'
],
renderer: new PrerenderSPAPlugin.PuppeteerRenderer({
renderAfterTime: 5000, // Wait five seconds for your app to start before rendering the page.
headless: false // Let's you watch what's happening.
})
}), |
If anyone has figured it out and can describe a workaround, that would be super awesome! I also have found this is a problem to use |
I've just had to do away with the dependency of the baseUrl.. which was a lot of work but made me realize this was the direction I should have taken all along. Previously I had my vue application served through a catchall route in Laravel which is why I needed all my files to load from the /public/baseUrl/ folder in my Laravel installation. Now I've completely decoupled by front-end from my back-end and no longer need to generate my files in a subfolder. It's probably different for you but.. chances are there's a way you can get around needing to use a subfolder |
Hey thanks for the explanation @vesper8. I think you're right, a URL prefix is not ideal. But in my case, i was not able to change that. I found a workaround by adding this to my vue router: Now the prerender works properly, but the only downside was that I have to manually move some assets around after I build. |
找到方法了 建议添加 google translate:
Prerender-spa-plugin started a service in the dist directory It is recommended to add
|
@Eunknight 老哥,你这是什么模板啊,webpack-simple么? |
@Eunknight 可以参考一下我的做法 |
If you use chainWebpack this might help in
|
@SHERlocked93 看这个issue标题,vue-cli v3 模板. |
Anyone else having issues with vue <router-link and prerender-spa-plugin in Vue-cli v3. In Vue History mode welcome If I remove prerender-spa-plugin from vue.config.js then all works as expected.
|
Hi guys, I'm using this with angular 6 but it seems that is not working there's no html code generated in specified routes... |
@BruneXX How are you dispatching the render event? I haven't used Angular 6 so I'm not sure exactly how that would work. |
Hi @tribex I'm using this configuration below:
But the code generated is the same as I got with the previous configuration, I can't see the "home" page html code generated after plugin configuration... Below tag I've only scripts and no html content.. |
@BruneXX It looks like you haven't set any render triggers. The basic usage example only works for basic pages with synchronous JavaScript. Try something more like this: new PrerenderSPAPlugin({
// Required - The path to the webpack-outputted app to prerender.
staticDir: path.join(__dirname, 'dist'),
// Required - Routes to render.
routes: [ '/' ],
// Renderer configuration
renderer: new Renderer({
// Wait to render until the specified event is dispatched on the document.
// eg, with `document.dispatchEvent(new Event('render-page'))`
renderAfterDocumentEvent: 'render-page',
})
}) You'll then need to fire |
Hi @tribex Excellent, I'll do that and I'll let you know the results soon! thanks a lot! |
@BruneXX One other thing, it looks like Angular (unlike Vue and React) doesn't support DOM hydration yet, so you may see a white flash between the time the prerendered page loads and when the JS finishes running. There's no real way around that, unfortunately. |
@tribex I've got the same result as before with the dispatchEvent.. I don't know why is not working.. |
I found a solution that works for me. It's not pretty, but it's working for me. First, set the
Next, in your
Finally, configure the SPA plugin like so:
As far as I can tell, all these settings really do is match up the directory structure with your routes (I'm barely knowledgeable about this stuff). To deploy your application, grab your contents from
Hope this helps. |
@Eunknight 老哥厉害,我一开始一直在修改routes里面的路径,后面发现是资源路径不对,却不知如何修改。终于,缘分让我们相聚:satisfied: |
yep I have seen a solution just now . i seems to give route-to a '/' ,and $route.push('/route') instandsof $route.push('rout') |
The plugin provides the solution, prerender-spa-cdn-plugin.
|
厉害厉害 |
Hi there.. I've been trying to follow the examples but I can't seem to get it to work.
This is my vue.config.js
This file contains the only change I've made to my app.. if I'm supposed to make other changes.. then sorry.. it seemed as though everything else is optional.
When I do npm run build, I don't get any errors or warnings, it does generate an about folder with an index.html in it.. as well as an index.html in the root. But those don't contain any of the static html from the view component.
Perhaps one thing that might be at play is how I import my components in the router and in the views. I use dynamic imports like this (my about route in my vue-router):
I am using history mode by the way
And through my application I use dynamic imports like this too
But to be honest I've done some tests where I just do a regular import and it doesn't make a difference
I'm pretty lost as to what I might be missing.. help would be much appreciated!
Even though the next two questions will make more sense once I actually get this to work.. I thought I might ask them now.. first.. is it required to have a trailing slash in order to load the pre-rendered html? And second.. these routes I want pre-rendered, such as the about page, they can be accessed both while my users are logged in and logged out.. and the header (menu) is different whether they are logged in or out. I really only care about pre-rendering the page for logged out users however.. because Google can't reach the logged-in page and once the user is logged in the SPA loads pages super fast anyway. Is there something I should do to take this into account?
Let me know if you need me to share anything else. Many Thanks!!
The text was updated successfully, but these errors were encountered: