diff --git a/packages/serverless-nextjs-component/README.md b/packages/serverless-nextjs-component/README.md index a620037bbb..be905bd862 100644 --- a/packages/serverless-nextjs-component/README.md +++ b/packages/serverless-nextjs-component/README.md @@ -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: diff --git a/packages/serverless-nextjs-component/serverless.js b/packages/serverless-nextjs-component/serverless.js index 9d9ea51df2..0249e4d62e 100644 --- a/packages/serverless-nextjs-component/serverless.js +++ b/packages/serverless-nextjs-component/serverless.js @@ -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); @@ -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), @@ -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" }) ); @@ -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" }) );