Skip to content

Commit c8f645c

Browse files
committed
fix: prepend basePath to static file URLs
1 parent 7d58544 commit c8f645c

File tree

2 files changed

+6
-3
lines changed

2 files changed

+6
-3
lines changed

demos/static-root/next.config.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ module.exports = {
2121
},
2222
trailingSlash: true,
2323
// Configurable site features _to_ support:
24-
// basePath: '/docs',
24+
basePath: '/docs',
2525
// Rewrites allow you to map an incoming request path to a different destination path.
2626
async rewrites() {
2727
return {

src/helpers/files.ts

+5-2
Original file line numberDiff line numberDiff line change
@@ -73,10 +73,12 @@ export const moveStaticPages = async ({
7373
netlifyConfig,
7474
target,
7575
i18n,
76+
basePath,
7677
}: {
7778
netlifyConfig: NetlifyConfig
7879
target: 'server' | 'serverless' | 'experimental-serverless-trace'
7980
i18n: NextConfig['i18n']
81+
basePath?: string
8082
}): Promise<void> => {
8183
console.log('Moving static page files to serve from CDN...')
8284
const outputDir = join(netlifyConfig.build.publish, target === 'server' ? 'server' : 'serverless')
@@ -117,11 +119,12 @@ export const moveStaticPages = async ({
117119
const isData = file.endsWith('.json')
118120
const source = join(root, file)
119121
const targetFile = isData ? join(dataDir, file) : file
122+
const targetPath = basePath ? join(basePath, targetFile) : targetFile
120123

121124
files.push(file)
122-
filesManifest[file] = targetFile
125+
filesManifest[file] = targetPath
123126

124-
const dest = join(netlifyConfig.build.publish, targetFile)
127+
const dest = join(netlifyConfig.build.publish, targetPath)
125128

126129
try {
127130
await move(source, dest)

0 commit comments

Comments
 (0)