c2b40d0773
Improve CSS modules support in server components. ## Bug - [ ] Related issues linked using `fixes #number` - [x] Integration tests added - [ ] Errors have helpful link attached, see `contributing.md` ## Feature - [ ] Implements an existing feature request or RFC. Make sure the feature request has been accepted for implementation before opening a PR. - [ ] Related issues linked using `fixes #number` - [ ] Integration tests added - [ ] Documentation added - [ ] Telemetry added. In case of a feature if it's used or not. - [ ] Errors have helpful link attached, see `contributing.md` ## Documentation / Examples - [ ] Make sure the linting passes by running `pnpm lint` - [ ] The examples guidelines are followed from [our contributing doc](https://github.com/vercel/next.js/blob/canary/contributing.md#adding-examples) Co-authored-by: Jiachi Liu <4800338+huozhi@users.noreply.github.com>
33 lines
1 KiB
TypeScript
33 lines
1 KiB
TypeScript
import { SERVER_RUNTIME } from '../../../lib/constants'
|
|
|
|
export default async function transformSource(this: any): Promise<string> {
|
|
let { modules, runtime, ssr, server } = this.getOptions()
|
|
if (!Array.isArray(modules)) {
|
|
modules = modules ? [modules] : []
|
|
}
|
|
|
|
const requests = modules as string[]
|
|
const code =
|
|
requests
|
|
.filter((request) => (server ? !request.endsWith('.css') : true))
|
|
.map((request) => `import(/* webpackMode: "eager" */ '${request}')`)
|
|
.join(';\n') +
|
|
`
|
|
export const __next_rsc_css__ = ${JSON.stringify(
|
|
requests.filter((request) => request.endsWith('.css'))
|
|
)};
|
|
export const __next_rsc__ = {
|
|
server: false,
|
|
__webpack_require__
|
|
};
|
|
export default function RSC() {};
|
|
` +
|
|
// Currently for the Edge runtime, we treat all RSC pages as SSR pages.
|
|
(runtime === SERVER_RUNTIME.edge
|
|
? 'export const __N_SSP = true;'
|
|
: ssr
|
|
? `export const __N_SSP = true;`
|
|
: `export const __N_SSG = true;`)
|
|
|
|
return code
|
|
}
|