Skip to content

Commit

Permalink
Merge pull request #54 from khuezy/feat/monorepo
Browse files Browse the repository at this point in the history
feat: allow custom buildPath
  • Loading branch information
khuezy authored Dec 14, 2022
2 parents 0bd62c5 + ab7d20b commit 4819d91
Show file tree
Hide file tree
Showing 3 changed files with 129 additions and 2 deletions.
119 changes: 119 additions & 0 deletions API.md

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 7 additions & 0 deletions src/NextjsBase.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,13 @@ export interface NextjsBaseProps {
*/
readonly nextjsPath: string;

/**
* The directory to execute `npm run build` from. By default, it uses `nextjsPath`.
* Can be overridden, particularly useful for monorepos where `build` is expected to run
* at the root of the project.
*/
readonly buildPath?: string;

/**
* Custom environment variables to pass to the NextJS build and runtime.
*/
Expand Down
5 changes: 3 additions & 2 deletions src/NextjsBuild.ts
Original file line number Diff line number Diff line change
Expand Up @@ -115,10 +115,11 @@ export class NextjsBuild extends Construct {
...(this.props.nodeEnv ? { NODE_ENV: this.props.nodeEnv } : {}),
};

const buildPath = this.props.buildPath ?? nextjsPath;
// run build
console.debug('├ Running "npm build" in', nextjsPath);
console.debug('├ Running "npm build" in', buildPath);
const buildResult = spawn.sync('npm', ['run', 'build'], {
cwd: nextjsPath,
cwd: buildPath,
stdio: this.props.quiet ? 'ignore' : 'inherit',
env: buildEnv,
});
Expand Down

0 comments on commit 4819d91

Please sign in to comment.