diff --git a/packages/serverless-nextjs-component/README.md b/packages/serverless-nextjs-component/README.md index ebb0cc01fa..b531d4e912 100644 --- a/packages/serverless-nextjs-component/README.md +++ b/packages/serverless-nextjs-component/README.md @@ -76,10 +76,19 @@ AWS_ACCESS_KEY_ID=accesskey AWS_SECRET_ACCESS_KEY=sshhh ``` +Set next.js build target to `serverless`: +```js +// next.config.js + +module.exports = { + target: 'serverless' +} +``` + And simply deploy: ```bash -$ serverless +$ next-build && serverless ``` ### Custom domain name @@ -170,13 +179,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. | -| 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 | -| memory | `number` or `object` | `512` | When assigned a number, both the default and api lambdas will assigned memory of that value. When assigned to an object, values for the default and api lambdas can be separately defined | +| 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.
**Note:** `nextConfigDir` should be set if `next.config.js` `distDir` is used. | +| 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 | | +| staticDir | `string` | `./` | If your `static` or `public` directory is not a direct child of `nextConfigDir` this is needed. | +| memory | `number` or `object` | `512` | When assigned a number, both the default and api lambdas will assigned memory of that value. When assigned to an object, values for the default and api lambdas can be separately defined | Custom inputs can be configured like this: diff --git a/packages/serverless-nextjs-component/serverless.js b/packages/serverless-nextjs-component/serverless.js index b263dfbb74..ab746a7b3f 100644 --- a/packages/serverless-nextjs-component/serverless.js +++ b/packages/serverless-nextjs-component/serverless.js @@ -237,10 +237,6 @@ class NextjsComponent extends Component { ? path.resolve(inputs.nextConfigDir) : process.cwd(); - await execa("node_modules/.bin/next", ["build"], { - cwd: nextConfigPath - }); - await this.emptyBuildDirectory(nextConfigPath); const { @@ -263,6 +259,8 @@ class NextjsComponent extends Component { const nextConfigPath = inputs.nextConfigDir ? path.resolve(inputs.nextConfigDir) : process.cwd(); + const nextStaticPath = inputs.nextStaticDir || ""; + const staticPath = nextStaticPath || nextConfigPath; const [defaultBuildManifest, apiBuildManifest] = await Promise.all([ this.readDefaultBuildManifest(nextConfigPath), @@ -312,14 +310,14 @@ class NextjsComponent extends Component { ]; const [publicDirExists, staticDirExists] = await Promise.all([ - fse.exists(join(nextConfigPath, "public")), - fse.exists(join(nextConfigPath, "static")) + fse.exists(join(staticPath, "public")), + fse.exists(join(staticPath, "static")) ]); if (publicDirExists) { assetsUpload.push( bucket.upload({ - dir: join(nextConfigPath, "public"), + dir: join(staticPath, "public"), keyPrefix: "public" }) ); @@ -328,7 +326,7 @@ class NextjsComponent extends Component { if (staticDirExists) { assetsUpload.push( bucket.upload({ - dir: join(nextConfigPath, "static"), + dir: join(staticPath, "static"), keyPrefix: "static" }) );