From 0bc6bb0ae72898616229321798756edcc5ef42bb Mon Sep 17 00:00:00 2001 From: Jack Hsu Date: Mon, 3 Oct 2022 10:52:03 -0400 Subject: [PATCH] fix(nextjs): return correct webpack config for next.js storybook app --- e2e/next/src/next.test.ts | 20 +++++++++++++++++--- packages/webpack/src/utils/config.ts | 9 +++++++-- 2 files changed, 24 insertions(+), 5 deletions(-) diff --git a/e2e/next/src/next.test.ts b/e2e/next/src/next.test.ts index 28182c8d6d00e7..d6f674d464a638 100644 --- a/e2e/next/src/next.test.ts +++ b/e2e/next/src/next.test.ts @@ -414,9 +414,23 @@ describe('Next.js Applications', () => { checkExport: false, }); }, 300_000); - it('should run default jest tests', async () => { - await expectJestTestsToPass('@nrwl/next:app'); - }, 100_000); + + it('should run a Next.js based Storybook setup', async () => { + const appName = uniq('app'); + runCLI(`generate @nrwl/next:app ${appName} --no-interactive`); + runCLI( + `generate @nrwl/next:component Foo --project=${appName} --no-interactive` + ); + runCLI( + `generate @nrwl/react:storybook-configuration ${appName} --generateStories --no-interactive` + ); + + const p = await runCommandUntil(`run ${appName}:storybook`, (output) => { + return /Storybook.*started/gi.test(output); + }); + + p.kill(); + }, 1_000_000); }); function getData(port: number, path = ''): Promise { diff --git a/packages/webpack/src/utils/config.ts b/packages/webpack/src/utils/config.ts index b177fbaf609edb..5f1077e8ff0131 100644 --- a/packages/webpack/src/utils/config.ts +++ b/packages/webpack/src/utils/config.ts @@ -37,6 +37,9 @@ export function getBaseWebpackPartial( internalOptions: InternalBuildOptions, context?: ExecutorContext ): Configuration { + // If the function is called directly and not through `@nrwl/webpack:webpack` then this target may not be set. + options.target ??= 'web'; + const mainFields = [ ...(internalOptions.esm ? ['es2015'] : []), 'module', @@ -68,7 +71,7 @@ export function getBaseWebpackPartial( ) ?? {}; const webpackConfig: Configuration = { - target: options.target ?? 'web', // webpack defaults to 'browserslist' which breaks Fast Refresh + target: options.target, entry: { [mainEntry]: [options.main], ...additionalEntryPoints, @@ -392,7 +395,7 @@ export function createLoaderFromCompiler( }), }, }; - default: + case 'babel': return { test: /\.([jt])sx?$/, loader: join(__dirname, 'web-babel-loader'), @@ -410,5 +413,7 @@ export function createLoaderFromCompiler( cacheCompression: false, }, }; + default: + return null; } }