Skip to content

Commit 4d88580

Browse files
author
Louis DeScioli
committed
fix: copy public directory from outdir when exists
1 parent 3fcebf5 commit 4d88580

File tree

2 files changed

+11
-5
lines changed

2 files changed

+11
-5
lines changed

src/helpers/files.js

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ exports.moveStaticPages = async ({ netlifyConfig, target, i18n }) => {
166166
yellowBright(outdent`
167167
Skipped moving ${matchedPages.size} ${
168168
matchedPages.size === 1 ? 'file because it matches' : 'files because they match'
169-
} middleware, so cannot be deployed to the CDN and will be served from the origin instead.
169+
} middleware, so cannot be deployed to the CDN and will be served from the origin instead.
170170
This is fine, but we're letting you know because it may not be what you expect.
171171
`),
172172
)
@@ -301,8 +301,14 @@ exports.unpatchNextFiles = async (root) => {
301301
}
302302
}
303303

304-
exports.movePublicFiles = async ({ appDir, publish }) => {
305-
const publicDir = join(appDir, 'public')
304+
exports.movePublicFiles = async ({ appDir, outdir, publish }) => {
305+
// `outdir` is a config property added when using Next.js with Nx. It's typically
306+
// a relative path outside of the appDir, e.g. '../../dist/apps/<app-name>', and
307+
// the parent directory of the .next directory.
308+
// If it exists, copy the files from the public folder there in order to include
309+
// any files that were generated during the build. Otherwise, copy the public
310+
// directory from the original app directory.
311+
const publicDir = outdir ? join(appDir, outdir, 'public') : join(appDir, 'public')
306312
if (existsSync(publicDir)) {
307313
await copy(publicDir, `${publish}/`)
308314
}

src/index.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ module.exports = {
4848

4949
checkNextSiteHasBuilt({ publish, failBuild })
5050

51-
const { appDir, basePath, i18n, images, target, ignore, trailingSlash } = await getNextConfig({
51+
const { appDir, basePath, i18n, images, target, ignore, trailingSlash, outdir } = await getNextConfig({
5252
publish,
5353
failBuild,
5454
})
@@ -58,7 +58,7 @@ module.exports = {
5858
await generateFunctions(constants, appDir)
5959
await generatePagesResolver({ netlifyConfig, target, constants })
6060

61-
await movePublicFiles({ appDir, publish })
61+
await movePublicFiles({ appDir, outdir, publish })
6262

6363
if (process.env.EXPERIMENTAL_ODB_TTL) {
6464
await patchNextFiles(basePath)

0 commit comments

Comments
 (0)