Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(nextjs): support workspace libs with standalone Next.js app #16471

Merged
merged 1 commit into from
Apr 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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