Skip to content

Commit

Permalink
fix(nextjs): return correct webpack config for next.js storybook app
Browse files Browse the repository at this point in the history
  • Loading branch information
jaysoo authored and Jack Hsu committed Oct 3, 2022
1 parent 77b57b7 commit e5a3ac6
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 5 deletions.
20 changes: 17 additions & 3 deletions e2e/next/src/next.test.ts
Expand Up @@ -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<any> {
Expand Down
9 changes: 7 additions & 2 deletions packages/webpack/src/utils/config.ts
Expand Up @@ -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',
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -392,7 +395,7 @@ export function createLoaderFromCompiler(
}),
},
};
default:
case 'babel':
return {
test: /\.([jt])sx?$/,
loader: join(__dirname, 'web-babel-loader'),
Expand All @@ -410,5 +413,7 @@ export function createLoaderFromCompiler(
cacheCompression: false,
},
};
default:
return null;
}
}

0 comments on commit e5a3ac6

Please sign in to comment.