-
Notifications
You must be signed in to change notification settings - Fork 87
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
75 additions
and
36 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
module.exports = { | ||
...require('@netlify/eslint-config-node/.prettierrc.json'), | ||
printWidth: 100, | ||
} |
This file was deleted.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,43 @@ | ||
import { existsSync } from 'node:fs' | ||
|
||
import { NetlifyPluginConstants } from '@netlify/build' | ||
import { copySync, moveSync } from 'fs-extra/esm' | ||
import { copy, move, remove } from 'fs-extra/esm' | ||
import { globby } from 'globby' | ||
|
||
import { BUILD_DIR } from './constants.js' | ||
|
||
/** | ||
* Move the Next.js build output from the publish dir to a temp dir | ||
*/ | ||
export const stashBuildOutput = ({ PUBLISH_DIR }: NetlifyPluginConstants) => { | ||
moveSync(PUBLISH_DIR, BUILD_DIR, { overwrite: true }) | ||
export const stashBuildOutput = async ({ PUBLISH_DIR }: NetlifyPluginConstants) => { | ||
await move(PUBLISH_DIR, BUILD_DIR, { overwrite: true }) | ||
|
||
// remove prerendered content from the standalone build (it's also in the main build dir) | ||
await Promise.all( | ||
getPrerenderedContent(`${BUILD_DIR}/standalone/`).map((filename: string) => remove(filename)), | ||
) | ||
} | ||
|
||
/** | ||
* Glob for prerendered content in the build output | ||
*/ | ||
const getPrerenderedContent = (cwd: string): string[] => { | ||
// TODO: test this | ||
// return globby('**/*.+(html|json|rsc|body|meta)', { cwd, extglob: true }) | ||
return [] | ||
} | ||
|
||
/** | ||
* Upload prerendered content from the main build dir to the blob store | ||
*/ | ||
export const storePrerenderedContent = () => { | ||
// TODO: implement | ||
} | ||
|
||
/** | ||
* Move static assets to the publish dir so they upload to the CDN | ||
* Move static assets to the publish dir so they are uploaded to the CDN | ||
*/ | ||
export const publishStaticAssets = ({ PUBLISH_DIR }: NetlifyPluginConstants) => { | ||
if (existsSync('public')) { | ||
copySync('public', PUBLISH_DIR) | ||
} | ||
copySync(`${BUILD_DIR}/static/`, `${PUBLISH_DIR}/_next/static`) | ||
return Promise.all([ | ||
copy('public', PUBLISH_DIR), | ||
copy(`${BUILD_DIR}/static/`, `${PUBLISH_DIR}/_next/static`), | ||
]) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,23 @@ | ||
import type { NetlifyPluginOptions } from '@netlify/build' | ||
|
||
import { setBuildConfig } from './helpers/config.js' | ||
import { publishStaticAssets, stashBuildOutput } from './helpers/files.js' | ||
import { stashBuildOutput, publishStaticAssets, storePrerenderedContent } from './helpers/files.js' | ||
import { createServerHandler } from './helpers/functions.js' | ||
|
||
type NetlifyPluginOptionsWithFlags = NetlifyPluginOptions & { featureFlags?: Record<string, unknown> } | ||
type NetlifyPluginOptionsWithFlags = NetlifyPluginOptions & { | ||
featureFlags?: Record<string, unknown> | ||
} | ||
|
||
export const onPreBuild = () => { | ||
setBuildConfig() | ||
} | ||
|
||
export const onBuild = async ({ constants }: NetlifyPluginOptionsWithFlags) => { | ||
stashBuildOutput(constants) | ||
publishStaticAssets(constants) | ||
await createServerHandler() | ||
await stashBuildOutput(constants) | ||
|
||
return Promise.all([ | ||
publishStaticAssets(constants), | ||
storePrerenderedContent(), | ||
createServerHandler(), | ||
]) | ||
} |