Open lodge-seven opened 5 years ago
You may have an error on your component, are you sure you can access it on a production server?
Firstly I use "prerender-spa-plugin": "^3.4.0", to solve this issue(Unable to prerender all routes), set 'headless' true or delete it.
configureWebpack: {
plugins: [
new PrerenderSPAPlugin({
// The path to generate the file can also be consistent with the webpakc package.
// This directory can only have one level, if the directory level is higher than one level, there will be no error prompt when it is generated, and it will only stick when it is pre-rendered.
staticDir: path.join(__dirname,'dist'),
// If you have parameters for your own routing file, such as about, you need to write / about/param1.
routes: ['/a','/b'],
// You have to configure or you won't precompile
renderer: new Renderer({
// ignoreJSErrors: true,
// headless: false,
// In main.js, document.dispatchEvent(new Event('render-event')) should correspond to the event name of both.
renderAfterDocumentEvent: 'render-event',
renderAfterTime: 5000
})
})
],
npm run build
succeeds locally, but fails when deployed to the server.
It is most likely related to the puppeteer used in prerender-spa-plugin 3.x. (Reference: https://qiita.com/pokotyan/items/11806b8b77f4a3527951)
Because the configuration on the CI was not authorized to change, I discarded version 3.
Later I used v2.1.0 which based on the PhantomJS and deployed successfully on the server.
vue-cli3 & "prerender-spa-plugin": "^2.1.0" vue.config.js
configureWebpack: {
plugins: [
new PrerenderSpaPlugin(
// Absolute path to compiled SPA
path.resolve(__dirname, './dist'),
// List of routes to prerender
['/a', '/b', '/c', '/d', '/e'],
{
// options
ignoreJSErrors: true,
}
)
],
}
用3.x的时候报这个错(Unable to prerender all routes),注释掉‘headless’或者设置为true后,本地能打包成功,但部署到服务器上时打包失败,原因很有可能跟插件版本3所使用的puppeteer有关。由于在ci上的配置我无权更改,故弃用版本三,改用基于PhantomJS.后成功部署在服务器上了。
routes: [ '/contest/home' ] just one route, error:Unable to prerender all routes, why?