Skip to content
This repository was archived by the owner on Jan 28, 2025. It is now read-only.
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 8 additions & 4 deletions packages/serverless-nextjs-component/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -118,10 +118,14 @@ The fourth cache behaviour handles next API requests `api/*`.

### Inputs

| Name | Type | Default Value | Description |
| ---------- | -------- | ------------- | ------------------------------------------------------------------------------- |
| domain | `Array` | `null` | For example `['admin', 'portal.com']`. |
| bucketName | `string` | `null` | Custom bucket name where static assets are stored. By default is autogenerated. |
| Name | Type | Default Value | Description |
| ------------------ | -------------- | ------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------- |
| domain | `Array` | `null` | For example `['admin', 'portal.com']`. |
| bucketName | `string` | `null` | Custom bucket name where static assets are stored. By default is autogenerated. |
| nextConfigDir | `string` | `./` | Directory where your application `next.config.js` file is. This input is useful when the `serverless.yml` is not in the same directory as the next app. |
| build | `boolean` | `true` | When true builds and deploys app, when false assume the app has been built and uses the .next .serverless_nextjs directories in nextConfigDir to deploy |
| nextBuildArguments | `Array|string` | `[]` | Allows for additional arguments when calling `next build` |
| staticPath | `string` | `./` | If your `static/public` directory is not a child of `nextConfigPath` this is needed. |

Custom inputs can be configured like this:

Expand Down
20 changes: 13 additions & 7 deletions packages/serverless-nextjs-component/serverless.js
Original file line number Diff line number Diff line change
Expand Up @@ -176,10 +176,15 @@ class NextjsComponent extends Component {
const nextConfigPath = inputs.nextConfigDir
? path.resolve(inputs.nextConfigDir)
: process.cwd();
const nextBuildArguments = inputs.nextBuildArguments || [];

await execa("node_modules/.bin/next", ["build"], {
cwd: nextConfigPath
});
await execa(
"node_modules/.bin/next",
["build"].concat(nextBuildArguments),
{
cwd: nextConfigPath
}
);

await this.emptyBuildDirectory(nextConfigPath);

Expand All @@ -203,6 +208,7 @@ class NextjsComponent extends Component {
const nextConfigPath = inputs.nextConfigDir
? path.resolve(inputs.nextConfigDir)
: process.cwd();
const staticPath = inputs.staticPath || "";

const [defaultBuildManifest, apiBuildManifest] = await Promise.all([
this.readDefaultBuildManifest(nextConfigPath),
Expand Down Expand Up @@ -243,14 +249,14 @@ class NextjsComponent extends Component {
];

const [publicDirExists, staticDirExists] = await Promise.all([
fse.exists(join(nextConfigPath, "public")),
fse.exists(join(nextConfigPath, "static"))
fse.exists(join(nextConfigPath, staticPath, "public")),
fse.exists(join(nextConfigPath, staticPath, "static"))
]);

if (publicDirExists) {
assetsUpload.push(
bucket.upload({
dir: join(nextConfigPath, "public"),
dir: join(nextConfigPath, staticPath, "public"),
keyPrefix: "public"
})
);
Expand All @@ -259,7 +265,7 @@ class NextjsComponent extends Component {
if (staticDirExists) {
assetsUpload.push(
bucket.upload({
dir: join(nextConfigPath, "static"),
dir: join(nextConfigPath, staticPath, "static"),
keyPrefix: "static"
})
);
Expand Down