1
0
Fork 0
mirror of https://github.com/terribleplan/next.js.git synced 2024-01-19 02:48:18 +00:00
next.js/server
Tim Neutkens a8a97b07c7
Provide a way to copy files in exportPathMap (#5089)
Related #4659 

Adds the possibility for users to copy files inside of `exportPathMap`. This allows for adding `robots.txt` `sitemap.xml` etc. another use case is for https://github.com/hanford/next-offline, currently it's manually reading the buildId in `exportPathMap`.

To allow users to do this we'll introduce a new parameter holding an object with the following keys:

- `dev` - `true` when `exportPathMap` is being called in development. `false` when running `next export`. In development `exportPathMap` is used to define routes and behavior like copying files is not required.
- `dir` - Absolute path to the project directory
- `outDir` - Absolute path to the `out` directory (configurable with `-o` or `--outdir`). When `dev` is `true` the value of `outDir` will be `null`.
- `distDir` - Absolute path to the `.next` directory (configurable using the `distDir` config key)
- `buildId` - The buildId the export is running for

Example usage:

```js
// next.config.js
const fs = require('fs')
const {join} = require('path')
const {promisify} = require('util')
const copyFile = promisify(fs.copyFile)

module.exports = {
  exportPathMap: async function (defaultPathMap, {dev, dir, outDir, distDir, buildId}) {
    if(dev) {
      return defaultPathMap
    }
    // This will copy robots.txt from your project root into the out directory
    await copyFile(join(dir, 'robots.txt'), join(outDir, 'robots.txt'))
    return defaultPathMap
  }
}
```
2018-09-04 16:01:50 +02:00
..
lib Open editor from error-overlay (minor) (#4979) 2018-08-24 16:30:41 +02:00
config.js Replace uuid with nanoid (#4987) 2018-08-23 17:02:47 +02:00
document.js Fixes dynamic chunks preload links, use href instead of src (#5047) 2018-08-28 17:56:48 +02:00
hot-reloader.js Open editor from error-overlay (minor) (#4979) 2018-08-24 16:30:41 +02:00
index.js Provide a way to copy files in exportPathMap (#5089) 2018-09-04 16:01:50 +02:00
next.js Programmatic API (#310) 2016-12-16 12:33:08 -08:00
on-demand-entry-handler.js Compile pages to .next/static directory (#4828) 2018-07-25 13:45:42 +02:00
render.js Make sure that 404's is not cached by CDN:s (#5088) 2018-09-04 14:13:15 +02:00
require.js Clean up references to this.dir and this.dist everywhere (#4535) 2018-06-04 15:45:39 +02:00
router.js Use a latest version of path-to-regexp for path-match (#3655) 2018-02-01 19:54:09 +01:00
utils.js [WIP] Webpack 4, react-error-overlay, react-loadable (#4639) 2018-07-24 11:24:40 +02:00