fix: convert paths in dynamic imports to file urls (#671) (#673)

fix #671
pull/685/head
Divyansh Singh 2 years ago committed by GitHub
parent c219c0f1dd
commit d93b477c76
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -151,7 +151,7 @@
} }
}, },
"simple-git-hooks": { "simple-git-hooks": {
"pre-commit": "lint-staged" "pre-commit": "pnpm lint-staged"
}, },
"lint-staged": { "lint-staged": {
"*": [ "*": [

@ -1,6 +1,7 @@
import { createRequire } from 'module' import { createRequire } from 'module'
import fs from 'fs-extra' import fs from 'fs-extra'
import path from 'path' import path from 'path'
import { pathToFileURL } from 'url'
import escape from 'escape-html' import escape from 'escape-html'
import { normalizePath, transformWithEsbuild } from 'vite' import { normalizePath, transformWithEsbuild } from 'vite'
import { RollupOutput, OutputChunk, OutputAsset } from 'rollup' import { RollupOutput, OutputChunk, OutputAsset } from 'rollup'
@ -19,7 +20,9 @@ export async function renderPage(
pageToHashMap: Record<string, string>, pageToHashMap: Record<string, string>,
hashMapString: string hashMapString: string
) { ) {
const { createApp } = await import(path.join(config.tempDir, `app.js`)) const { createApp } = await import(
pathToFileURL(path.join(config.tempDir, `app.js`)).toString()
)
const { app, router } = createApp() const { app, router } = createApp()
const routePath = `/${page.replace(/\.md$/, '')}` const routePath = `/${page.replace(/\.md$/, '')}`
const siteData = resolveSiteDataByRoute(config.site, routePath) const siteData = resolveSiteDataByRoute(config.site, routePath)
@ -37,7 +40,9 @@ export async function renderPage(
} }
// render page // render page
const content = await import(rendererPath).then((r) => r.renderToString(app)) const content = await import(pathToFileURL(rendererPath).toString()).then(
(r) => r.renderToString(app)
)
const pageName = page.replace(/\//g, '_') const pageName = page.replace(/\//g, '_')
// server build doesn't need hash // server build doesn't need hash
@ -49,7 +54,7 @@ export async function renderPage(
// resolve page data so we can render head tags // resolve page data so we can render head tags
const { __pageData } = await import( const { __pageData } = await import(
path.join(config.tempDir, pageServerJsFileName) pathToFileURL(path.join(config.tempDir, pageServerJsFileName)).toString()
) )
const pageData = JSON.parse(__pageData) const pageData = JSON.parse(__pageData)

Loading…
Cancel
Save