2022-08-17 12:56:52 +02:00
|
|
|
/**
|
|
|
|
* For server-side CSS imports, we need to ignore the actual module content but
|
|
|
|
* still trigger the hot-reloading diff mechanism. So here we put the content
|
|
|
|
* inside a comment.
|
|
|
|
*/
|
|
|
|
|
2022-08-25 18:40:16 +02:00
|
|
|
export function pitch(this: any) {
|
|
|
|
const content = this.fs.readFileSync(this.resource)
|
|
|
|
this.data.__checksum = (
|
|
|
|
typeof content === 'string' ? Buffer.from(content) : content
|
|
|
|
).toString('hex')
|
|
|
|
}
|
|
|
|
|
|
|
|
const NextServerCSSLoader = function (this: any, content: string) {
|
2022-08-17 12:56:52 +02:00
|
|
|
this.cacheable && this.cacheable()
|
|
|
|
|
2022-08-25 18:40:16 +02:00
|
|
|
const isCSSModule = this.resource.match(/\.module\.css$/)
|
|
|
|
if (isCSSModule) {
|
|
|
|
return (
|
|
|
|
content +
|
|
|
|
'\nmodule.exports.__checksum = ' +
|
|
|
|
JSON.stringify(this.data.__checksum)
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
return `export default ${JSON.stringify(this.data.__checksum)}`
|
2022-08-17 12:56:52 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
export default NextServerCSSLoader
|