20486c159d
* [edge] allow importing blob assets * Fix test * extract to a new file, to make it easier to read and review * Use webpack asset discovery and transform with a loader * fix tests * don't prefix assets * use emitFile * rename assets to blobs to be more specific * rename blobs to assets and use webpack's hashing algo * Dedupe correctly * Add a Node.js dep test * Update packages/next/server/next-server.ts Co-authored-by: Tobias Koppers <tobias.koppers@googlemail.com> * [code review] test remote URL fetches * [code review] use `import type` for type-only imports * Update packages/next/server/next-server.ts Co-authored-by: Tobias Koppers <tobias.koppers@googlemail.com> * Apply suggestions from code review Co-authored-by: JJ Kasper <jj@jjsweb.site> Co-authored-by: Tobias Koppers <tobias.koppers@googlemail.com> Co-authored-by: JJ Kasper <jj@jjsweb.site>
19 lines
643 B
TypeScript
19 lines
643 B
TypeScript
import loaderUtils from 'next/dist/compiled/loader-utils3'
|
|
import { getModuleBuildInfo } from './get-module-build-info'
|
|
|
|
export default function MiddlewareAssetLoader(this: any, source: Buffer) {
|
|
const name = loaderUtils.interpolateName(this, '[name].[hash].[ext]', {
|
|
context: this.rootContext,
|
|
content: source,
|
|
})
|
|
const filePath = `edge-chunks/asset_${name}`
|
|
const buildInfo = getModuleBuildInfo(this._module)
|
|
buildInfo.nextAssetMiddlewareBinding = {
|
|
filePath: `server/${filePath}`,
|
|
name,
|
|
}
|
|
this.emitFile(filePath, source)
|
|
return `module.exports = ${JSON.stringify(`blob:${name}`)}`
|
|
}
|
|
|
|
export const raw = true
|