1
0
Fork 0
mirror of https://github.com/terribleplan/next.js.git synced 2024-01-19 02:48:18 +00:00
next.js/packages/next/build/webpack/plugins/pages-manifest-plugin.js
Tim Neutkens c2eaf26ea9
Remove flow types (#5704)
* Remove flow-typed

* Remove flow types

* Remove the last types

* Bring back taskr dependency

* Revert "Bring back taskr dependency"

This reverts commit 38cb95d7274d63fe63c6ac3c95ca358a28c17895.

* Bring back preset-flow as it’s used for tests

* Revert "Revert "Bring back taskr dependency""

This reverts commit b4c933ef133f4039f544fb10bf31d5c95d3b27a2.
2018-11-21 16:04:37 +01:00

37 lines
1 KiB
JavaScript

import { RawSource } from 'webpack-sources'
import {PAGES_MANIFEST, ROUTE_NAME_REGEX} from 'next-server/constants'
// This plugin creates a pages-manifest.json from page entrypoints.
// This is used for mapping paths like `/` to `.next/server/static/<buildid>/pages/index.js` when doing SSR
// It's also used by next export to provide defaultPathMap
export default class PagesManifestPlugin {
apply (compiler) {
compiler.hooks.emit.tap('NextJsPagesManifest', (compilation) => {
const {entries} = compilation
const pages = {}
for (const entry of entries) {
const result = ROUTE_NAME_REGEX.exec(entry.name)
if (!result) {
continue
}
const pagePath = result[1]
if (!pagePath) {
continue
}
const {name} = entry
pages[`/${pagePath.replace(/\\/g, '/')}`] = name
}
if (typeof pages['/index'] !== 'undefined') {
pages['/'] = pages['/index']
}
compilation.assets[PAGES_MANIFEST] = new RawSource(JSON.stringify(pages))
})
}
}