diff --git a/src/NextjsBase.ts b/src/NextjsBase.ts index 98a48e8f..44307441 100644 --- a/src/NextjsBase.ts +++ b/src/NextjsBase.ts @@ -49,6 +49,12 @@ export interface NextjsBaseProps { */ readonly nodeEnv?: string; + /** + * Optional value used to install NextJS node dependencies. + * It defaults to "npm" + */ + readonly packageManager?: "npm" | "yarn" | "pnpm"; + /** * 0 - no compression, fatest * 9 - maximum compression, slowest diff --git a/src/NextjsBuild.ts b/src/NextjsBuild.ts index 21c8f831..08d76a71 100644 --- a/src/NextjsBuild.ts +++ b/src/NextjsBuild.ts @@ -133,9 +133,11 @@ export class NextjsBuild extends Construct { }; const buildPath = this.props.buildPath ?? nextjsPath; + const packageManager = this.props.packageManager ?? "npm"; + const buildCommand = packageManager === "yarn" ? ['build'] : ['run', 'build']; // run build - console.debug('├ Running "npm build" in', buildPath); - const buildResult = spawn.sync('npm', ['run', 'build'], { + console.debug(`├ Running "${packageManager} build" in`, buildPath); + const buildResult = spawn.sync(packageManager, buildCommand, { cwd: buildPath, stdio: this.props.quiet ? 'ignore' : 'inherit', env: buildEnv,