mirror of
https://github.com/terribleplan/next.js.git
synced 2024-01-19 02:48:18 +00:00
27c0b199d0
This PR Fixes #4920 So the problem is that when a next.js application is built on windows, the `pages-manifest.json` file is created with backslashes. If this built application is deployed to a linux hosting enviroment, the server will fail when trying to load the modules. ``` Error: Cannot find module '/user_code/next/server/bundles\pages\index.js ``` My simple solution is to modify the `pages-manifest.json` to always use linux separator (`/`), then also modify `server/require.js` to, when requiring page, replace any separator (`\` or `/`) with current platform-specific file separator (`require('path').sep`). The fix in `server/require.js` would be sufficient, but my opinion is that having some cross-platform consistency is nice. This change was tested by bulding an application in windows and running it in linux and windows, aswell as building an application in linux and running it in linux and windows. The related tests was also run. # Conflicts: # test/integration/production/test/index.test.js
38 lines
1.2 KiB
JavaScript
38 lines
1.2 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
|
|
// Write filename, replace any backslashes in path (on windows) with forwardslashes for cross-platform consistency.
|
|
pages[`/${pagePath.replace(/\\/g, '/')}`] = name.replace(/\\/g, '/')
|
|
}
|
|
|
|
if (typeof pages['/index'] !== 'undefined') {
|
|
pages['/'] = pages['/index']
|
|
}
|
|
|
|
compilation.assets[PAGES_MANIFEST] = new RawSource(JSON.stringify(pages))
|
|
})
|
|
}
|
|
}
|