-
Notifications
You must be signed in to change notification settings - Fork 86
/
Copy pathcopyNextAssets.js
25 lines (21 loc) · 1010 Bytes
/
copyNextAssets.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
const { join } = require('path')
const { copySync, existsSync } = require('fs-extra')
const getNextDistDir = require('../helpers/getNextDistDir')
const { logTitle } = require('../helpers/logger')
// Copy the NextJS' static assets from NextJS distDir to Netlify publish folder.
// These need to be available for NextJS to work.
const copyNextAssets = async (publishPath) => {
const nextDistDir = await getNextDistDir()
const staticAssetsPath = join(nextDistDir, 'static')
if (!existsSync(staticAssetsPath)) {
throw new Error(
'No static assets found in .next dist (aka no /.next/static). Please check your project configuration. Your next.config.js must be one of `serverless` or `experimental-serverless-trace`. Your build command should include `next build`.',
)
}
logTitle('💼 Copying static NextJS assets to', publishPath)
copySync(staticAssetsPath, join(publishPath, '_next', 'static'), {
overwrite: false,
errorOnExist: true,
})
}
module.exports = copyNextAssets