Skip to content

Commit

Permalink
fix(server): use jsx loader for .js document files, default loader se…
Browse files Browse the repository at this point in the history
…tup for others
  • Loading branch information
rexxars committed Aug 10, 2022
1 parent 79da537 commit 99f4dc4
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions packages/@sanity/server/src/renderDocument.ts
Expand Up @@ -113,10 +113,17 @@ function renderDocumentFromWorkerData() {

// Require hook #2
// Use `esbuild` to allow JSX/TypeScript and modern JS features
// eslint-disable-next-line import/no-unassigned-import
const {unregister} = require('esbuild-register/dist/node').register({
target: `node${process.version.slice(1)}`,
loader: 'tsx',
extensions: ['.jsx', '.ts', '.tsx', '.mjs'],
})

// Require hook #3
// Same as above, but we don't want to enforce a .jsx extension for anything with JSX
const {unregister: unregisterJs} = require('esbuild-register/dist/node').register({
target: `node${process.version.slice(1)}`,
extensions: ['.js'],
loader: 'jsx',
})

const html = getDocumentHtml(studioRootPath, props)
Expand All @@ -125,6 +132,7 @@ function renderDocumentFromWorkerData() {

// Be polite and clean up after esbuild-register
unregister()
unregisterJs()
}

function getDocumentHtml(studioRootPath: string, props?: DocumentProps): string {
Expand Down

0 comments on commit 99f4dc4

Please sign in to comment.