rsnext/packages/next/build/webpack/loaders/next-flight-server-loader.ts
Shu Ding b122178ead
Decouple entries for server components and client components (#36860)
* (wip)

* dev mode

* build mode

* update comment

* fix tests

* fix _N_SSP and _N_SSG exports

* fix missing variables

* fix api route bug

* fix compiler stats

* fix lint errors

* add extra cache group for edge server

* fix test

* fix test

* fix views route meta and entries

* fix linter error

Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>
2022-05-13 19:48:53 +02:00

31 lines
562 B
TypeScript

import { parse } from '../../swc'
export default async function transformSource(
this: any,
source: string
): Promise<string> {
const { resourcePath } = this
const ast = await parse(source, {
filename: resourcePath,
isModule: 'unknown',
})
const isModule = ast.type === 'Module'
return (
source +
(isModule
? `
export const __next_rsc__ = {
__webpack_require__,
server: true
}
`
: `
exports.__next_rsc__ = {
__webpack_require__,
server: true
}
`)
)
}