@@ -5,33 +5,39 @@ const loader = require('../cli/loader');
5
5
const getRemoteOriginUrl = require ( '../utils/getRemoteOriginUrl' ) ;
6
6
const { build : webpackBuild } = require ( '../webpack' ) ;
7
7
const deleteDir = require ( '../utils/deleteDir' ) ;
8
+ const fileServer = require ( '../utils/fileServer' ) ;
8
9
9
10
async function createOgImage ( outputDirPath ) {
10
- const url = require ( 'url' ) ;
11
11
const puppeteer = require ( 'puppeteer' ) ;
12
12
13
- const browser = await puppeteer . launch ( ) ;
13
+ const port = 5445 ;
14
+ const browser = await puppeteer . launch ( {
15
+ chromeWebSecurity : false ,
16
+ args : [ '--no-sandbox' , '--disable-setuid-sandbox' ] ,
17
+ } ) ;
14
18
const page = await browser . newPage ( ) ;
15
- const outputPath = join ( outputDirPath , 'thumbnail.png' ) ;
19
+ const outputFilePath = join ( outputDirPath , 'thumbnail.png' ) ;
16
20
17
21
// https://www.kapwing.com/resources/what-is-an-og-image-make-and-format-og-images-for-your-blog-or-webpage/
18
22
await page . setViewport ( {
19
23
width : 1200 ,
20
24
height : 630 ,
21
25
} ) ;
22
- await page . goto ( url . pathToFileURL ( join ( outputDirPath , 'index.html' ) ) , {
23
- waitUntil : 'networkidle2' ,
26
+ const app = await fileServer ( outputDirPath , port ) ;
27
+ await page . goto ( `http://localhost:${ port } ` , {
28
+ waitUntil : [ 'load' , 'networkidle2' ] ,
24
29
} ) ;
25
- await page . screenshot ( { path : outputPath } ) ;
30
+ await page . screenshot ( { path : outputFilePath } ) ;
31
+ await page . close ( ) ;
26
32
await browser . close ( ) ;
33
+ app . close ( ) ;
27
34
28
- return outputPath ;
35
+ return outputFilePath ;
29
36
}
30
37
31
38
async function build ( config , isConsoleOutput = true ) {
32
39
const spinner = loader ( 'Rendering components to HTML...' ) . start ( ) ;
33
- const { basePath, outputDir } = config . internal ;
34
- const outputDirPath = join ( basePath , outputDir ) ;
40
+ const { outputDirPath } = config . internal ;
35
41
const remoteOrigin = await getRemoteOriginUrl ( ) ;
36
42
37
43
if ( process . env . NODE_ENV === undefined ) {
0 commit comments