mirror of
https://github.com/terribleplan/next.js.git
synced 2024-01-19 02:48:18 +00:00
e90f89633c
* Initial implementation of next export without exportPathMap * Shorter message * Set up flow * Create pages manifest * Use pagesManifest for next export * Fix tests * Document defaultPathMap * Replacing the path is no longer needed * Use posix normalize for consistent behaviour * Remove second instance of examples * Add comment about what pages-manifest does * Make windows path a route
31 lines
925 B
JavaScript
31 lines
925 B
JavaScript
// @flow
|
|
import { RawSource } from 'webpack-sources'
|
|
import { MATCH_ROUTE_NAME } from '../../utils'
|
|
import {PAGES_MANIFEST} from '../../../lib/constants'
|
|
|
|
// This plugin creates a pages-manifest.json from page entrypoints.
|
|
// This is used for mapping paths like `/` to `.next/dist/bundles/pages/index.js` when doing SSR
|
|
// It's also used by next export to provide defaultPathMap
|
|
export default class PagesManifestPlugin {
|
|
apply (compiler: any) {
|
|
compiler.plugin('emit', (compilation, callback) => {
|
|
const {entries} = compilation
|
|
const pages = {}
|
|
|
|
for (const entry of entries) {
|
|
const pagePath = MATCH_ROUTE_NAME.exec(entry.name)[1]
|
|
|
|
if (!pagePath) {
|
|
continue
|
|
}
|
|
|
|
const {name} = entry
|
|
pages[`/${pagePath.replace(/\\/g, '/')}`] = name
|
|
}
|
|
|
|
compilation.assets[PAGES_MANIFEST] = new RawSource(JSON.stringify(pages))
|
|
callback()
|
|
})
|
|
}
|
|
}
|