Skip to content

Commit

Permalink
feat: add chrome-executable parameter to export (#677)
Browse files Browse the repository at this point in the history
  • Loading branch information
fabianhauser committed Aug 11, 2022
1 parent 04ab103 commit 216f33f
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
6 changes: 6 additions & 0 deletions packages/slidev/node/cli.ts
Expand Up @@ -322,6 +322,10 @@ cli.command(
type: 'boolean',
describe: 'export pages for every clicks',
})
.option('executable-path', {
type: 'string',
describe: 'executable to override playwright bundled browser',
})
.strict()
.help(),
async ({
Expand All @@ -333,6 +337,7 @@ cli.command(
range,
dark,
'with-clicks': withClicks,
'executable-path': executablePath,
}) => {
process.env.NODE_ENV = 'production'
const { exportSlides } = await import('./export')
Expand Down Expand Up @@ -364,6 +369,7 @@ cli.command(
width,
height,
withClicks,
executablePath,
})
console.log(`${green(' ✓ ')}${dim('exported to ')}./${output}\n`)
server.close()
Expand Down
6 changes: 5 additions & 1 deletion packages/slidev/node/export.ts
Expand Up @@ -20,6 +20,7 @@ export interface ExportOptions {
width?: number
height?: number
withClicks?: boolean
executablePath?: string
}

function createSlidevProgress(indeterminate = false) {
Expand Down Expand Up @@ -72,14 +73,17 @@ export async function exportSlides({
width = 1920,
height = 1080,
withClicks = false,
executablePath = undefined,
}: ExportOptions) {
if (!packageExists('playwright-chromium'))
throw new Error('The exporting for Slidev is powered by Playwright, please installed it via `npm i -D playwright-chromium`')

const pages: number[] = parseRangeString(total, range)

const { chromium } = await import('playwright-chromium')
const browser = await chromium.launch()
const browser = await chromium.launch({
executablePath,
})
const context = await browser.newContext({
viewport: {
width,
Expand Down

0 comments on commit 216f33f

Please sign in to comment.