Skip to content

Commit

Permalink
fix(nextjs): support workspace libs with standalone Next.js app
Browse files Browse the repository at this point in the history
  • Loading branch information
jaysoo committed Apr 21, 2023
1 parent 505b5dc commit 0130b11
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,10 @@ export function createApplicationFiles(host: Tree, options: NormalizedSchema) {

let { extends: _, ...updatedJson } = json;

// Don't generate the `paths` object or else workspace libs will not work later.
// It'll be generated as needed when a lib is first added.
delete json.compilerOptions.paths;

updatedJson = {
...updateJson,
compilerOptions: {
Expand Down
15 changes: 14 additions & 1 deletion packages/next/src/generators/library/library.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,20 @@ export async function libraryGenerator(host: Tree, rawOptions: Schema) {
'src',
`server.${options.js ? 'js' : 'ts'}`
),
`// Use this file to export React server components\n`
`// Use this file to export React server components
export * from './lib/hello-server';`
);
host.write(
joinPathFragments(
options.projectRoot,
'src/lib',
`hello-server.${options.js ? 'js' : 'tsx'}`
),
`// React server components are async so you make database or API calls.
export async function HelloServer() {
return <h1>Hello Server</h1>
}
`
);
addTsConfigPath(host, `${options.importPath}/server`, [serverEntryPath]);

Expand Down
2 changes: 1 addition & 1 deletion packages/react/src/generators/library/library.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ export async function libraryGenerator(host: Tree, schema: Schema) {
...options,
e2eTestRunner: 'none',
skipFormat: true,
skipBabelConfig: options.bundler === 'vite',
skipBabelConfig: options.bundler === 'vite' || options.compiler === 'swc',
skipHelperLibs: options.bundler === 'vite',
});
tasks.push(initTask);
Expand Down

0 comments on commit 0130b11

Please sign in to comment.