-
Notifications
You must be signed in to change notification settings - Fork 2.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(nextjs): Use next.js cli for build and serve targets
- Loading branch information
1 parent
6ebfbbe
commit 8f37db9
Showing
15 changed files
with
227 additions
and
167 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
import 'dotenv/config'; | ||
import { | ||
ExecutorContext, | ||
parseTargetString, | ||
readTargetOptions, | ||
runExecutor, | ||
} from '@nx/devkit'; | ||
import { join, resolve } from 'path'; | ||
|
||
import { | ||
NextBuildBuilderOptions, | ||
NextServeBuilderOptions, | ||
} from '../../utils/types'; | ||
|
||
export default async function* serveExecutor( | ||
options: NextServeBuilderOptions, | ||
context: ExecutorContext | ||
) { | ||
// Cast to any to overwrite NODE_ENV | ||
(process.env as any).NODE_ENV = process.env.NODE_ENV | ||
? process.env.NODE_ENV | ||
: options.dev | ||
? 'development' | ||
: 'production'; | ||
|
||
// Setting port that the custom server should use. | ||
(process.env as any).PORT = options.port; | ||
|
||
const buildOptions = readTargetOptions<NextBuildBuilderOptions>( | ||
parseTargetString(options.buildTarget, context.projectGraph), | ||
context | ||
); | ||
const root = resolve(context.root, buildOptions.root); | ||
|
||
yield* runCustomServer(root, options, context); | ||
} | ||
|
||
async function* runCustomServer( | ||
root: string, | ||
options: NextServeBuilderOptions, | ||
context: ExecutorContext | ||
) { | ||
process.env.NX_NEXT_DIR = root; | ||
process.env.NX_NEXT_PUBLIC_DIR = join(root, 'public'); | ||
|
||
const baseUrl = `http://${options.hostname || 'localhost'}:${options.port}`; | ||
|
||
const customServerBuild = await runExecutor( | ||
parseTargetString(options.customServerTarget, context.projectGraph), | ||
{ | ||
watch: options.dev ? true : false, | ||
}, | ||
context | ||
); | ||
|
||
for await (const result of customServerBuild) { | ||
if (!result.success) { | ||
return result; | ||
} | ||
yield { | ||
success: true, | ||
baseUrl, | ||
}; | ||
} | ||
|
||
return { success: true }; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.