@storybook/nextjs 7.0.0-beta.1 → 7.0.0-beta.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -14,12 +14,12 @@
14
14
  - [Remote Images](#remote-images)
15
15
  - [Optimization](#optimization)
16
16
  - [AVIF](#avif)
17
- - [Next.js Navigation](#nextjs-navigation)
18
17
  - [Next.js Routing](#nextjs-routing)
19
18
  - [Overriding defaults](#overriding-defaults)
20
19
  - [Global Defaults](#global-defaults)
21
20
  - [Default Router](#default-router)
22
21
  - [Actions Integration Caveats](#actions-integration-caveats)
22
+ - [Next.js Navigation](#nextjs-navigation)
23
23
  - [Sass/Scss](#sassscss)
24
24
  - [Css/Sass/Scss Modules](#csssassscss-modules)
25
25
  - [Styled JSX](#styled-jsx)
@@ -30,7 +30,7 @@
30
30
  - [Typescript](#typescript)
31
31
  - [Notes for Yarn v2 and v3 users](#notes-for-yarn-v2-and-v3-users)
32
32
  - [FAQ](#faq)
33
- - [Stories for pages](#stories-for-pages)
33
+ - [Stories for pages](#stories-for-pages-components-which-fetch-data)
34
34
  - [Statically imported images won't load](#statically-imported-images-wont-load)
35
35
  - [Module not found: Error: Can't resolve [package name]](#module-not-found-error-cant-resolve-package-name)
36
36
  - [Acknowledgements](#acknowledgements)
@@ -71,29 +71,52 @@
71
71
  Follow the prompts after running this command in your Next.js project's root directory:
72
72
 
73
73
  ```bash
74
- npx storybook init
74
+ npx storybook@next init
75
75
  ```
76
76
 
77
- [More on getting started with Storybook](https://storybook.js.org/docs/react/get-started/introduction)
77
+ [More on getting started with Storybook](https://storybook.js.org/docs/react/get-started/install)
78
78
 
79
79
  ### In a project with Storybook
80
80
 
81
- Update your `main.js` to look something like this:
81
+ This framework is designed to work with Storybook 7. If you’re not already using v7, upgrade with this command:
82
+
83
+ ```bash
84
+ npx storybook@next upgrade --prerelease
85
+ ```
82
86
 
83
87
  Install the framework:
84
88
 
85
89
  ```bash
86
- yarn install @storybook/nextjs
90
+ yarn install -D @storybook/nextjs@next
87
91
  ```
88
92
 
93
+ Update your `main.js` to change the framework property:
94
+
89
95
  ```js
90
96
  // .storybook/main.js
91
97
  module.exports = {
98
+ // ...
92
99
  framework: {
93
- name: '@storybook/nextjs',
94
- options: {};
95
- }
96
- }
100
+ // name: '@storybook/react-webpack5', // Remove this
101
+ name: '@storybook/nextjs', // Add this
102
+ options: {},
103
+ },
104
+ };
105
+ ```
106
+
107
+ If you were using Storybook plugins to integrate with Next.js, those are no longer necessary when using this framework and can be removed:
108
+
109
+ ```js
110
+ // .storybook/main.js
111
+ module.exports = {
112
+ // ...
113
+ addons: [
114
+ // ...
115
+ // These can both be removed
116
+ // 'storybook-addon-next',
117
+ // 'storybook-addon-next-router',
118
+ ],
119
+ };
97
120
  ```
98
121
 
99
122
  ## Documentation
@@ -109,14 +132,13 @@ For example:
109
132
  const path = require('path');
110
133
 
111
134
  module.exports = {
112
- // other config ommited for brevity
135
+ // ...
113
136
  framework: {
114
137
  name: '@storybook/nextjs',
115
138
  options: {
116
139
  nextConfigPath: path.resolve(__dirname, '../next.config.js'),
117
140
  },
118
141
  },
119
- // ...
120
142
  };
121
143
  ```
122
144
 
@@ -174,69 +196,34 @@ export default function Home() {
174
196
 
175
197
  This format is not supported by this framework yet. Feel free to [open up an issue](https://github.com/storybookjs/storybook/issues) if this is something you want to see.
176
198
 
177
- ### Next.js Navigation
178
-
179
- Please note that [next/navigation](https://beta.nextjs.org/docs/upgrade-guide#step-5-migrating-routing-hooks) can only be used in components/pages of the `app` directory of Next.js v13 or higher.
180
-
181
- #### Set `nextjs.appDirectory` to `true`
182
-
183
- If your story imports components that use `next/navigation`, you need to set the parameter `nextjs.appDirectory` to `true` in your Story:
184
-
185
- ```js
186
- // SomeComponentThatUsesTheRouter.stories.js
187
- import SomeComponentThatUsesTheNavigation from './SomeComponentThatUsesTheNavigation';
188
-
189
- export default {
190
- component: SomeComponentThatUsesTheNavigation,
191
- };
192
-
193
- // if you have the actions addon
194
- // you can click the links and see the route change events there
195
- export const Example = {
196
- parameters: {
197
- nextjs: {
198
- appDirectory: true,
199
- },
200
- },
201
- },
202
- ```
203
-
204
- If your Next.js project uses the `app` directory for every page (in other words, it does not have a `pages` directory), you can set the parameter `nextjs.appDirectory` to `true` in the [preview.js](https://storybook.js.org/docs/react/configure/overview#configure-story-rendering) file to apply it to all stories.
205
-
206
- ```js
207
- // .storybook/preview.js
199
+ ### Next.js Routing
208
200
 
209
- export const parameters = {
210
- nextjs: {
211
- appDirectory: true,
212
- },
213
- };
214
- ```
201
+ [Next.js's router](https://nextjs.org/docs/routing/introduction) is automatically stubbed for you so that when the router is interacted with, all of its interactions are automatically logged to the Actions ctions panel if you have the [Storybook actions addon](https://storybook.js.org/docs/react/essentials/actions).
215
202
 
216
- The parameter `nextjs.appDirectory` defaults to `false` if not set.
203
+ > When using Next.js 13+, you should only use `next/router` in the `pages` directory. In the `app` directory, it is necessary to use `next/navigation`.
217
204
 
218
205
  #### Overriding defaults
219
206
 
220
- Per-story overrides can be done by adding a `nextjs.navigation` property onto the story [parameters](https://storybook.js.org/docs/react/writing-stories/parameters). The framework will shallowly merge whatever you put here into the router.
207
+ Per-story overrides can be done by adding a `nextjs.router` property onto the story [parameters](https://storybook.js.org/docs/react/writing-stories/parameters). The framework will shallowly merge whatever you put here into the router.
221
208
 
222
209
  ```js
223
- // SomeComponentThatUsesTheNavigation.stories.js
224
- import SomeComponentThatUsesTheNavigation from './SomeComponentThatUsesTheNavigation';
210
+ // SomeComponentThatUsesTheRouter.stories.js
211
+ import SomeComponentThatUsesTheRouter from './SomeComponentThatUsesTheRouter';
225
212
 
226
213
  export default {
227
- component: SomeComponentThatUsesTheNavigation,
214
+ component: SomeComponentThatUsesTheRouter,
228
215
  };
229
216
 
230
- // if you have the actions addon
231
- // you can click the links and see the route change events there
217
+ // If you have the actions addon,
218
+ // you can interact with the links and see the route change events there
232
219
  export const Example = {
233
220
  parameters: {
234
221
  nextjs: {
235
- appDirectory: true,
236
- navigation: {
237
- pathname: '/some-default-path',
222
+ router: {
223
+ path: '/profile/[id]',
224
+ asPath: '/profile/1',
238
225
  query: {
239
- foo: 'bar',
226
+ id: '1',
240
227
  },
241
228
  },
242
229
  },
@@ -253,41 +240,65 @@ Global defaults can be set in [preview.js](https://storybook.js.org/docs/react/c
253
240
 
254
241
  export const parameters = {
255
242
  nextjs: {
256
- appDirectory: true,
257
- navigation: {
258
- pathname: '/some-default-path',
259
- query: {
260
- foo: 'bar',
261
- },
243
+ router: {
244
+ path: '/some-default-path',
245
+ asPath: '/some-default-path',
246
+ query: {},
262
247
  },
263
248
  },
264
249
  };
265
250
  ```
266
251
 
267
- #### Default Navigation Context
252
+ #### Default Router
268
253
 
269
- The default values on the stubbed navigation context are as follows:
254
+ The default values on the stubbed router are as follows (see [globals](https://storybook.js.org/docs/react/essentials/toolbars-and-globals#globals) for more details on how globals work)
270
255
 
271
256
  ```ts
272
- const defaultNavigationContext = {
257
+ const defaultRouter = {
273
258
  push(...args) {
274
- action('nextNavigation.push')(...args);
259
+ action('nextRouter.push')(...args);
260
+ return Promise.resolve(true);
275
261
  },
276
262
  replace(...args) {
277
- action('nextNavigation.replace')(...args);
263
+ action('nextRouter.replace')(...args);
264
+ return Promise.resolve(true);
278
265
  },
279
- forward(...args) {
280
- action('nextNavigation.forward')(...args);
266
+ reload(...args) {
267
+ action('nextRouter.reload')(...args);
281
268
  },
282
269
  back(...args) {
283
- action('nextNavigation.back')(...args);
270
+ action('nextRouter.back')(...args);
271
+ },
272
+ forward() {
273
+ action('nextRouter.forward')();
284
274
  },
285
275
  prefetch(...args) {
286
- action('nextNavigation.prefetch')(...args);
276
+ action('nextRouter.prefetch')(...args);
277
+ return Promise.resolve();
287
278
  },
288
- refresh: () => {
289
- action('nextNavigation.refresh')();
279
+ beforePopState(...args) {
280
+ action('nextRouter.beforePopState')(...args);
290
281
  },
282
+ events: {
283
+ on(...args) {
284
+ action('nextRouter.events.on')(...args);
285
+ },
286
+ off(...args) {
287
+ action('nextRouter.events.off')(...args);
288
+ },
289
+ emit(...args) {
290
+ action('nextRouter.events.emit')(...args);
291
+ },
292
+ },
293
+ // The locale should be configured [globally](https://storybook.js.org/docs/react/essentials/toolbars-and-globals#globals)
294
+ locale: globals?.locale,
295
+ asPath: '/',
296
+ basePath: '/',
297
+ isFallback: false,
298
+ isLocaleDomain: false,
299
+ isReady: true,
300
+ isPreview: false,
301
+ route: '/',
291
302
  pathname: '/',
292
303
  query: {},
293
304
  };
@@ -295,17 +306,16 @@ const defaultNavigationContext = {
295
306
 
296
307
  #### Actions Integration Caveats
297
308
 
298
- If you override a function, you lose the automatic action tab integration and have to build it out yourself.
309
+ If you override a function, you lose the automatic actions integration and have to build it out yourself.
299
310
 
300
311
  ```js
301
312
  // .storybook/preview.js
302
313
 
303
314
  export const parameters = {
304
315
  nextjs: {
305
- appDirectory: true,
306
- navigation: {
316
+ router: {
307
317
  push() {
308
- // The default implementation that logs the action into the action tab is lost
318
+ // The default implementation that logs the action into the Actions panel is lost
309
319
  },
310
320
  },
311
321
  },
@@ -320,13 +330,12 @@ import { action } from '@storybook/addon-actions';
320
330
 
321
331
  export const parameters = {
322
332
  nextjs: {
323
- appDirectory: true,
324
- navigation: {
333
+ router: {
325
334
  push(...args) {
326
- // custom logic can go here
327
- // this logs to the actions tab
328
- action('nextNavigation.push')(...args);
329
- // return whatever you want here
335
+ // Custom logic can go here
336
+ // This logs to the Actions panel
337
+ action('nextRouter.push')(...args);
338
+ // Return whatever you want here
330
339
  return Promise.resolve(true);
331
340
  },
332
341
  },
@@ -334,34 +343,67 @@ export const parameters = {
334
343
  };
335
344
  ```
336
345
 
337
- ### Next.js Routing
346
+ ### Next.js Navigation
338
347
 
339
- [Next.js's router](https://nextjs.org/docs/routing/introduction) is automatically stubbed for you so that when the router is interacted with, all of its interactions are automatically logged to the [Storybook actions tab](https://storybook.js.org/docs/react/essentials/actions) if you have the actions addon.
348
+ > Please note that [next/navigation](https://beta.nextjs.org/docs/upgrade-guide#step-5-migrating-routing-hooks) can only be used in components/pages in the `app` directory of Next.js 13+.
340
349
 
341
- You should only use `next/router` in the `pages` directory of Next.js v13 or higher. In the `app` directory, it is necessary to use `next/navigation`.
350
+ #### Set `nextjs.appDirectory` to `true`
351
+
352
+ If your story imports components that use `next/navigation`, you need to set the parameter `nextjs.appDirectory` to `true` in your Story:
353
+
354
+ ```js
355
+ // SomeComponentThatUsesTheRouter.stories.js
356
+ import SomeComponentThatUsesTheNavigation from './SomeComponentThatUsesTheNavigation';
357
+
358
+ export default {
359
+ component: SomeComponentThatUsesTheNavigation,
360
+ };
361
+
362
+ export const Example = {
363
+ parameters: {
364
+ nextjs: {
365
+ appDirectory: true,
366
+ },
367
+ },
368
+ },
369
+ ```
370
+
371
+ If your Next.js project uses the `app` directory for every page (in other words, it does not have a `pages` directory), you can set the parameter `nextjs.appDirectory` to `true` in the [preview.js](https://storybook.js.org/docs/react/configure/overview#configure-story-rendering) file to apply it to all stories.
372
+
373
+ ```js
374
+ // .storybook/preview.js
375
+
376
+ export const parameters = {
377
+ nextjs: {
378
+ appDirectory: true,
379
+ },
380
+ };
381
+ ```
382
+
383
+ The parameter `nextjs.appDirectory` defaults to `false` if not set.
342
384
 
343
385
  #### Overriding defaults
344
386
 
345
- Per-story overrides can be done by adding a `nextRouter` property onto the story [parameters](https://storybook.js.org/docs/react/writing-stories/parameters). The framework will shallowly merge whatever you put here into the router.
387
+ Per-story overrides can be done by adding a `nextjs.navigation` property onto the story [parameters](https://storybook.js.org/docs/react/writing-stories/parameters). The framework will shallowly merge whatever you put here into the router.
346
388
 
347
389
  ```js
348
- // SomeComponentThatUsesTheRouter.stories.js
349
- import SomeComponentThatUsesTheRouter from './SomeComponentThatUsesTheRouter';
390
+ // SomeComponentThatUsesTheNavigation.stories.js
391
+ import SomeComponentThatUsesTheNavigation from './SomeComponentThatUsesTheNavigation';
350
392
 
351
393
  export default {
352
- component: SomeComponentThatUsesTheRouter,
394
+ component: SomeComponentThatUsesTheNavigation,
353
395
  };
354
396
 
355
- // if you have the actions addon
356
- // you can click the links and see the route change events there
397
+ // If you have the actions addon,
398
+ // you can interact with the links and see the route change events there
357
399
  export const Example = {
358
400
  parameters: {
359
401
  nextjs: {
360
- router: {
361
- path: '/profile/[id]',
362
- asPath: '/profile/ryanclementshax',
402
+ appDirectory: true,
403
+ navigation: {
404
+ pathname: '/profile',
363
405
  query: {
364
- id: 'ryanclementshax',
406
+ user: '1',
365
407
  },
366
408
  },
367
409
  },
@@ -378,65 +420,38 @@ Global defaults can be set in [preview.js](https://storybook.js.org/docs/react/c
378
420
 
379
421
  export const parameters = {
380
422
  nextjs: {
381
- router: {
382
- path: '/some-default-path',
383
- asPath: '/some-default-path',
384
- query: {},
423
+ appDirectory: true,
424
+ navigation: {
425
+ pathname: '/some-default-path',
385
426
  },
386
427
  },
387
428
  };
388
429
  ```
389
430
 
390
- #### Default Router
431
+ #### Default Navigation Context
391
432
 
392
- The default values on the stubbed router are as follows (see [globals](https://storybook.js.org/docs/react/essentials/toolbars-and-globals#globals) for more details on how globals work)
433
+ The default values on the stubbed navigation context are as follows:
393
434
 
394
435
  ```ts
395
- const defaultRouter = {
436
+ const defaultNavigationContext = {
396
437
  push(...args) {
397
- action('nextRouter.push')(...args);
398
- return Promise.resolve(true);
438
+ action('nextNavigation.push')(...args);
399
439
  },
400
440
  replace(...args) {
401
- action('nextRouter.replace')(...args);
402
- return Promise.resolve(true);
441
+ action('nextNavigation.replace')(...args);
403
442
  },
404
- reload(...args) {
405
- action('nextRouter.reload')(...args);
443
+ forward(...args) {
444
+ action('nextNavigation.forward')(...args);
406
445
  },
407
446
  back(...args) {
408
- action('nextRouter.back')(...args);
409
- },
410
- forward() {
411
- action('nextRouter.forward')();
447
+ action('nextNavigation.back')(...args);
412
448
  },
413
449
  prefetch(...args) {
414
- action('nextRouter.prefetch')(...args);
415
- return Promise.resolve();
416
- },
417
- beforePopState(...args) {
418
- action('nextRouter.beforePopState')(...args);
450
+ action('nextNavigation.prefetch')(...args);
419
451
  },
420
- events: {
421
- on(...args) {
422
- action('nextRouter.events.on')(...args);
423
- },
424
- off(...args) {
425
- action('nextRouter.events.off')(...args);
426
- },
427
- emit(...args) {
428
- action('nextRouter.events.emit')(...args);
429
- },
452
+ refresh: () => {
453
+ action('nextNavigation.refresh')();
430
454
  },
431
- // The locale should be configured [globally](https://storybook.js.org/docs/react/essentials/toolbars-and-globals#globals)
432
- locale: globals?.locale,
433
- asPath: '/',
434
- basePath: '/',
435
- isFallback: false,
436
- isLocaleDomain: false,
437
- isReady: true,
438
- isPreview: false,
439
- route: '/',
440
455
  pathname: '/',
441
456
  query: {},
442
457
  };
@@ -451,9 +466,10 @@ If you override a function, you lose the automatic action tab integration and ha
451
466
 
452
467
  export const parameters = {
453
468
  nextjs: {
454
- router: {
469
+ appDirectory: true,
470
+ navigation: {
455
471
  push() {
456
- // The default implementation that logs the action into the action tab is lost
472
+ // The default implementation that logs the action into the Actions panel is lost
457
473
  },
458
474
  },
459
475
  },
@@ -468,12 +484,13 @@ import { action } from '@storybook/addon-actions';
468
484
 
469
485
  export const parameters = {
470
486
  nextjs: {
471
- router: {
487
+ appDirectory: true,
488
+ navigation: {
472
489
  push(...args) {
473
- // custom logic can go here
474
- // this logs to the actions tab
475
- action('nextRouter.push')(...args);
476
- // return whatever you want here
490
+ // Custom logic can go here
491
+ // This logs to the Actions panel
492
+ action('nextNavigation.push')(...args);
493
+ // Return whatever you want here
477
494
  return Promise.resolve(true);
478
495
  },
479
496
  },
@@ -496,7 +513,7 @@ This will automatically include any of your [custom sass configurations](https:/
496
513
  const path = require('path');
497
514
 
498
515
  module.exports = {
499
- // any options here are included in sass compilation for your stories
516
+ // Any options here are included in Sass compilation for your stories
500
517
  sassOptions: {
501
518
  includePaths: [path.join(__dirname, 'styles')],
502
519
  },
@@ -508,7 +525,7 @@ module.exports = {
508
525
  [css modules](https://nextjs.org/docs/basic-features/built-in-css-support#adding-component-level-css) work as expected.
509
526
 
510
527
  ```js
511
- // this import works just fine in Storybook now
528
+ // This import works just fine in Storybook now
512
529
  import styles from './Button.module.css';
513
530
  // sass/scss is also supported
514
531
  // import styles from './Button.module.scss'
@@ -603,10 +620,11 @@ export default function HomePage() {
603
620
  }
604
621
  ```
605
622
 
623
+ Also OK for global styles in `preview.js`!
624
+
606
625
  ```js
607
- // preview.js
626
+ // .storybook/preview.js
608
627
 
609
- // Also ok in preview.js!
610
628
  import 'styles/globals.scss';
611
629
 
612
630
  // ...
@@ -659,14 +677,14 @@ Below is an example of how to add svgr support to Storybook with this framework.
659
677
  ```js
660
678
  // .storybook/main.js
661
679
  module.exports = {
662
- // other config omitted for brevity
680
+ // ...
663
681
  webpackFinal: async (config) => {
664
- // this modifies the existing image rule to exclude .svg files
682
+ // This modifies the existing image rule to exclude .svg files
665
683
  // since you want to handle those files with @svgr/webpack
666
684
  const imageRule = config.module.rules.find((rule) => rule.test.test('.svg'));
667
685
  imageRule.exclude = /\.svg$/;
668
686
 
669
- // configure .svg files to be loaded with @svgr/webpack
687
+ // Configure .svg files to be loaded with @svgr/webpack
670
688
  config.module.rules.push({
671
689
  test: /\.svg$/,
672
690
  use: ['@svgr/webpack'],
@@ -703,9 +721,9 @@ This is because those versions of Yarn have different package resolution rules t
703
721
 
704
722
  ### FAQ
705
723
 
706
- #### Stories for pages
724
+ #### Stories for pages/components which fetch data
707
725
 
708
- Next.js page files can contain imports to modules meant to run in a node environment (for use in data fetching functions). If you import from a Next.js page file containing those node module imports in your stories, your Storybook's Webpack will crash because those modules will not run in a browser. To get around this, you can extract the component in your page file into a separate file and import that component in your stories. Or, if that's not feasible for some reason, you can [polyfill those modules](https://webpack.js.org/configuration/node/) in your Storybook's [`webpackFinal` configuration](https://storybook.js.org/docs/react/builders/webpack#extending-storybooks-webpack-config).
726
+ Next.js page files can contain imports to modules meant to run in a node environment (for use in data fetching functions). If you import from a Next.js page file containing those node module imports in your stories, your Storybook's Webpack will crash because those modules will not run in a browser. To get around this, you can extract the component in your page file into a separate file and import that pure component in your stories. Or, if that's not feasible for some reason, you can [polyfill those modules](https://webpack.js.org/configuration/node/) in your Storybook's [`webpackFinal` configuration](https://storybook.js.org/docs/react/builders/webpack#extending-storybooks-webpack-config).
709
727
 
710
728
  **Before**
711
729
 
@@ -713,9 +731,10 @@ Next.js page files can contain imports to modules meant to run in a node environ
713
731
  // ./pages/my-page.jsx
714
732
  import fs from 'fs';
715
733
 
716
- export default MyPage = (props) => (
717
- // ...
718
- );
734
+ // Using this component in your stories will break the Storybook build
735
+ export default function Page(props) {
736
+ return; // ...
737
+ }
719
738
 
720
739
  export const getStaticProps = async () => {
721
740
  // Logic that uses `fs`
@@ -728,15 +747,57 @@ export const getStaticProps = async () => {
728
747
  // ./pages/my-page.jsx
729
748
  import fs from 'fs';
730
749
 
750
+ // Use this pure component in your stories instead
731
751
  import MyPage from 'components/MyPage';
732
752
 
733
- export default MyPage;
753
+ export default function Page(props) {
754
+ return <MyPage {...props} />;
755
+ }
734
756
 
735
757
  export const getStaticProps = async () => {
736
758
  // Logic that uses `fs`
737
759
  };
738
760
  ```
739
761
 
762
+ Starting with Next.js 13, you can also fetch data directly within server components in the `app` directory. This does not (currently) work within Storybook for similar reasons as above. It can be worked around similarly as well, by extracting a pure component to a separate file and importing that component in your stories.
763
+
764
+ **Before**
765
+
766
+ ```jsx
767
+ // ./app/my-page/index.jsx
768
+ async function getData() {
769
+ const res = await fetch(...);
770
+ // ...
771
+ }
772
+
773
+ // Using this component in your stories will break the Storybook build
774
+ export default async function Page() {
775
+ const data = await getData();
776
+
777
+ return // ...
778
+ }
779
+ ```
780
+
781
+ **After**
782
+
783
+ ```jsx
784
+ // ./app/my-page/index.jsx
785
+
786
+ // Use this component in your stories
787
+ import MyPage from './components/MyPage';
788
+
789
+ async function getData() {
790
+ const res = await fetch(...);
791
+ // ...
792
+ }
793
+
794
+ export default async function Page() {
795
+ const data = await getData();
796
+
797
+ return <MyPage {...data} />;
798
+ }
799
+ ```
800
+
740
801
  #### Statically imported images won't load
741
802
 
742
803
  Make sure you are treating image imports the same way you treat them when using `next/image` in normal development.
package/dist/preset.d.ts CHANGED
@@ -1020,7 +1020,7 @@ interface StorybookConfig {
1020
1020
  /**
1021
1021
  * References external Storybooks
1022
1022
  */
1023
- refs?: CoreCommon_StorybookRefs | ((config: any, options: Options) => CoreCommon_StorybookRefs);
1023
+ refs?: PresetValue<CoreCommon_StorybookRefs>;
1024
1024
  /**
1025
1025
  * Modify or return babel config.
1026
1026
  */
@@ -1034,15 +1034,15 @@ interface StorybookConfig {
1034
1034
  *
1035
1035
  * @deprecated use `previewAnnotations` or `/preview.js` file instead
1036
1036
  */
1037
- config?: (entries: Entry[], options: Options) => Entry[];
1037
+ config?: PresetValue<Entry[]>;
1038
1038
  /**
1039
1039
  * Add additional scripts to run in the preview a la `.storybook/preview.js`
1040
1040
  */
1041
- previewAnnotations?: (entries: Entry[], options: Options) => Entry[];
1041
+ previewAnnotations?: PresetValue<Entry[]>;
1042
1042
  /**
1043
1043
  * Process CSF files for the story index.
1044
1044
  */
1045
- storyIndexers?: (indexers: StoryIndexer[], options: Options) => StoryIndexer[];
1045
+ storyIndexers?: PresetValue<StoryIndexer[]>;
1046
1046
  /**
1047
1047
  * Docs related features in index generation
1048
1048
  */
@@ -1052,9 +1052,10 @@ interface StorybookConfig {
1052
1052
  * The previewHead and previewBody functions accept a string,
1053
1053
  * which is the existing head/body, and return a modified string.
1054
1054
  */
1055
- previewHead?: (head: string, options: Options) => string;
1056
- previewBody?: (body: string, options: Options) => string;
1055
+ previewHead?: PresetValue<string>;
1056
+ previewBody?: PresetValue<string>;
1057
1057
  }
1058
+ type PresetValue<T> = T | ((config: T, options: Options) => T | Promise<T>);
1058
1059
  type PresetProperty<K, TStorybookConfig = StorybookConfig> = TStorybookConfig[K extends keyof TStorybookConfig ? K : never] | PresetPropertyFn<K, TStorybookConfig>;
1059
1060
  type PresetPropertyFn<K, TStorybookConfig = StorybookConfig, TOptions = {}> = (config: TStorybookConfig[K extends keyof TStorybookConfig ? K : never], options: Options & TOptions) => TStorybookConfig[K extends keyof TStorybookConfig ? K : never] | Promise<TStorybookConfig[K extends keyof TStorybookConfig ? K : never]>;
1060
1061
 
package/dist/preset.js CHANGED
@@ -1,5 +1,5 @@
1
- "use strict";var Z=Object.create;var x=Object.defineProperty;var ee=Object.getOwnPropertyDescriptor;var oe=Object.getOwnPropertyNames;var te=Object.getPrototypeOf,re=Object.prototype.hasOwnProperty;var se=(e,t)=>{for(var o in t)x(e,o,{get:t[o],enumerable:!0})},h=(e,t,o,r)=>{if(t&&typeof t=="object"||typeof t=="function")for(let s of oe(t))!re.call(e,s)&&s!==o&&x(e,s,{get:()=>t[s],enumerable:!(r=ee(t,s))||r.enumerable});return e};var i=(e,t,o)=>(o=e!=null?Z(te(e)):{},h(t||!e||!e.__esModule?x(o,"default",{value:e,enumerable:!0}):o,e)),ie=e=>h(x({},"__esModule",{value:!0}),e);var ye={};se(ye,{addons:()=>me,babel:()=>de,config:()=>ue,core:()=>ge,frameworkOptions:()=>le,webpackFinal:()=>xe});module.exports=ie(ye);var c=require("path"),Q=require("@babel/core"),Y=require("@storybook/core-common");var b=i(require("semver")),A=require("webpack");var k=i(require("path")),R=require("webpack"),j=require("next/constants"),P=i(require("find-up")),E=require("fs-extra"),I=i(require("ts-dedent")),S=require("url"),O=e=>{var t;(t=e.plugins)==null||t.push(new R.DefinePlugin({"process.env.__NEXT_VERSION":JSON.stringify(f())}))},f=()=>require(y("next/package.json")).version,ne=async e=>["mjs","js"].reduce(async(o,r)=>(await o||(o=(0,P.default)(`next.config.${r}`,{cwd:e})),o),Promise.resolve(void 0)),_=async({baseConfig:e={},nextConfigPath:t,configDir:o})=>{let r=t||await ne(o);if(!r||await(0,E.pathExists)(r)===!1)throw new Error(I.default`
1
+ "use strict";var Z=Object.create;var x=Object.defineProperty;var ee=Object.getOwnPropertyDescriptor;var oe=Object.getOwnPropertyNames;var te=Object.getPrototypeOf,re=Object.prototype.hasOwnProperty;var se=(e,t)=>{for(var o in t)x(e,o,{get:t[o],enumerable:!0})},h=(e,t,o,r)=>{if(t&&typeof t=="object"||typeof t=="function")for(let s of oe(t))!re.call(e,s)&&s!==o&&x(e,s,{get:()=>t[s],enumerable:!(r=ee(t,s))||r.enumerable});return e};var n=(e,t,o)=>(o=e!=null?Z(te(e)):{},h(t||!e||!e.__esModule?x(o,"default",{value:e,enumerable:!0}):o,e)),ie=e=>h(x({},"__esModule",{value:!0}),e);var ye={};se(ye,{addons:()=>me,babel:()=>de,config:()=>ue,core:()=>ge,frameworkOptions:()=>le,webpackFinal:()=>xe});module.exports=ie(ye);var c=require("path"),Q=require("@babel/core"),Y=require("@storybook/core-common");var b=n(require("semver")),V=require("webpack");var k=n(require("path")),R=require("webpack"),j=require("next/constants"),P=n(require("find-up")),E=require("fs-extra"),S=n(require("ts-dedent")),I=require("url"),O=e=>{var t;(t=e.plugins)==null||t.push(new R.DefinePlugin({"process.env.__NEXT_VERSION":JSON.stringify(f())}))},f=()=>require(y("next/package.json")).version,ne=async e=>["mjs","js"].reduce(async(o,r)=>(await o||(o=(0,P.default)(`next.config.${r}`,{cwd:e})),o),Promise.resolve(void 0)),_=async({baseConfig:e={},nextConfigPath:t,configDir:o})=>{let r=t||await ne(o);if(!r||await(0,E.pathExists)(r)===!1)throw new Error(S.default`
2
2
  Could not find or resolve your Next config file. Please provide the next config file path as a framework option.
3
3
 
4
4
  More info: https://github.com/storybookjs/storybook/blob/next/code/frameworks/nextjs/README.md#options
5
- `);let s=await import((0,S.pathToFileURL)(r).href),p=typeof s=="function"?s(j.PHASE_DEVELOPMENT_SERVER,{defaultConfig:e}):s;return p.default||p},n=(e,t,o)=>{e.resolve??={},e.resolve.alias??={};let r=e.resolve.alias,s=y(`${o??t}`);Array.isArray(r)?r.push({name:t,alias:s}):r[t]=s},y=e=>{let t=require.resolve(e,{paths:[k.default.resolve()]}),r=t.lastIndexOf(e.replace(/\//g,k.default.sep))+e.length;return t.substring(0,r)};var V=async({baseConfig:e,nextConfigPath:t,configDir:o})=>{let r=await _({baseConfig:e,nextConfigPath:t,configDir:o});return n(e,"next/config"),pe(e,r),r},W=f(),pe=(e,t)=>{var s,p;let o={"process.env.__NEXT_RUNTIME_CONFIG":JSON.stringify({serverRuntimeConfig:{},publicRuntimeConfig:t.publicRuntimeConfig})},r=(s=t.experimental)==null?void 0:s.newNextLinkBehavior;b.default.gte(W,"13.0.0")&&b.default.lt(W,"13.0.6")&&r!==!1?o["process.env.__NEXT_NEW_LINK_BEHAVIOR"]=!0:o["process.env.__NEXT_NEW_LINK_BEHAVIOR"]=r,(p=e.plugins)==null||p.push(new A.DefinePlugin(o))};var v=require("next/dist/build/webpack/config/blocks/css/loaders/getCssModuleLocalIdent"),w=require("next/dist/build/webpack/config/blocks/css/loaders/file-resolve"),q=i(require("semver"));var T=(e,t)=>{var r,s,p;let o=(r=e.module)==null?void 0:r.rules;o==null||o.forEach((m,l)=>{typeof m!="string"&&m.test instanceof RegExp&&m.test.test("test.css")&&(o[l]={test:/\.css$/,use:["style-loader",{loader:"css-loader",options:{importLoaders:1,...F(t),modules:{auto:!0,getLocalIdent:v.getCssModuleLocalIdent}}},"postcss-loader"]})}),o==null||o.push({test:/\.(scss|sass)$/,use:["style-loader",{loader:"css-loader",options:{importLoaders:3,...F(t),modules:{auto:!0,getLocalIdent:v.getCssModuleLocalIdent}}},"postcss-loader","resolve-url-loader",{loader:"sass-loader",options:{sourceMap:!0,sassOptions:t.sassOptions,additionalData:((s=t.sassOptions)==null?void 0:s.prependData)||((p=t.sassOptions)==null?void 0:p.additionalData)}}]})},F=e=>ae()?{url:{filter:L(e)},import:{filter:$(e)}}:{url:L(e),import:$(e)},L=e=>(t,o)=>{var r;return(0,w.cssFileResolve)(t,o,(r=e.experimental)==null?void 0:r.urlImports)},$=e=>(t,o,r)=>{var s;return(0,w.cssFileResolve)(typeof t=="string"?t:t.url,r,(s=e.experimental)==null?void 0:s.urlImports)},ae=()=>{try{let e=require(y("css-loader/package.json")).version;return q.default.gte(e,"6.0.0")}catch{return!1}};var D=i(require("tsconfig-paths-webpack-plugin")),M=require("tsconfig-paths"),B=e=>{let t=(0,M.loadConfig)();t.resultType==="failed"||!t.baseUrl||(e.resolve??={},e.resolve.plugins??=[],e.resolve.plugins.push(new D.default({configFile:t.configFileAbsolutePath,extensions:[".js",".jsx",".ts",".tsx"]})))};var U=i(require("semver"));var J=e=>{let t=fe();n(e,t)},fe=()=>{let e=f();return U.default.gte(e,"11.1.0")?"next/dist/shared/lib/router-context":"next/dist/next-server/lib/router-context"};var X=i(require("semver"));var H=e=>{let t=f();X.default.gte(t,"12.0.0")?n(e,"styled-jsx"):(n(e,"styled-jsx/babel"),n(e,"styled-jsx/css"),n(e,"styled-jsx/macro"),n(e,"styled-jsx/server"),n(e,"styled-jsx/style"),n(e,"styled-jsx/webpack"))};var K=i(require("semver"));var G=e=>{ce(e),n(e,"next/image")},ce=e=>{var s,p,m;let t=f();if(K.default.lt(t,"11.0.0"))return;let o=(s=e.module)==null?void 0:s.rules,r=o==null?void 0:o.find(l=>typeof l!="string"&&l.test instanceof RegExp&&l.test.test("test.jpg"));!r||(r.test=/\.(apng|eot|otf|ttf|woff|woff2|cur|ani|pdf)(\?.*)?$/,o==null||o.push({test:/\.(png|jpg|jpeg|gif|webp|avif|ico|bmp|svg)$/i,issuer:{not:/\.(css|scss|sass)$/},use:[{loader:require.resolve("@storybook/nextjs/next-image-loader-stub.js"),options:{filename:(p=r.generator)==null?void 0:p.filename}}]}),o==null||o.push({test:/\.(png|jpg|jpeg|gif|webp|avif|ico|bmp|svg)$/i,issuer:/\.(css|scss|sass)$/,type:"asset/resource",generator:{filename:(m=r.generator)==null?void 0:m.filename}}))};var u=i(require("semver")),d=require("webpack");function z(e){let t=f(),o=u.default.satisfies(t,"~12"),r=u.default.satisfies(t,"~13"),s=u.default.lt(t,"13.0.0");e.plugins=e.plugins??[],r||e.plugins.push(new d.IgnorePlugin({resourceRegExp:/next\/legacy\/image$/})),o||e.plugins.push(new d.IgnorePlugin({resourceRegExp:/next\/future\/image$/})),s&&e.plugins.push(new d.IgnorePlugin({resourceRegExp:/next\/dist\/shared\/lib\/hooks-client-context$/})),u.default.lt(t,"12.2.0")&&e.plugins.push(new d.IgnorePlugin({resourceRegExp:/next\/dist\/shared\/lib\/app-router-context$/}))}var me=[(0,c.dirname)(require.resolve((0,c.join)("@storybook/preset-react-webpack","package.json"))),(0,c.dirname)(require.resolve((0,c.join)("@storybook/builder-webpack5","package.json")))],C={},le=async(e,t)=>{let o=await t.presets.apply("framework");return typeof o=="string"?{name:o,options:C}:typeof o>"u"?{name:require.resolve("@storybook/nextjs"),options:C}:{name:o.name,options:{...C,...o.options}}},ge=async(e,t)=>{let o=await t.presets.apply("framework");return{...e,builder:{name:(0,c.dirname)(require.resolve((0,c.join)("@storybook/builder-webpack5","package.json"))),options:typeof o=="string"?{}:o.options.builder||{}},renderer:(0,c.dirname)(require.resolve((0,c.join)("@storybook/react","package.json")))}},ue=(e=[])=>[...e,require.resolve("@storybook/nextjs/preview.js")],de=async e=>{var m,l,N;let t=(0,Q.loadPartialConfig)({...e,filename:`${(0,Y.getProjectRoot)()}/__fake__.js`}),o=t==null?void 0:t.options,r=a=>typeof a=="object"&&a!==null&&"file"in a;((m=o==null?void 0:o.presets)==null?void 0:m.find(a=>{var g;return Array.isArray(a)&&a[0]==="next/babel"||a==="next/babel"||r(a)&&((g=a.file)==null?void 0:g.request)==="next/babel"}))||(l=o==null?void 0:o.presets)==null||l.push("next/babel");let p=(N=o==null?void 0:o.presets)==null?void 0:N.filter(a=>{var g;return!(r(a)&&((g=a.file)==null?void 0:g.request)===require.resolve("@babel/preset-react"))});return{...o,presets:p,babelrc:!1,configFile:!1}},xe=async(e,t)=>{let o=await t.presets.apply("frameworkOptions"),{options:{nextConfigPath:r}={}}=o,s=await V({baseConfig:e,nextConfigPath:r,configDir:t.configDir});return z(e),O(e),B(e),T(e,s),G(e),J(e),H(e),e};0&&(module.exports={addons,babel,config,core,frameworkOptions,webpackFinal});
5
+ `);let s=await import((0,I.pathToFileURL)(r).href),i=typeof s=="function"?s(j.PHASE_DEVELOPMENT_SERVER,{defaultConfig:e}):s;return i.default||i},p=(e,t,o)=>{e.resolve??={},e.resolve.alias??={};let r=e.resolve.alias,s=y(`${o??t}`);Array.isArray(r)?r.push({name:t,alias:s}):r[t]=s},y=e=>{let t=require.resolve(e,{paths:[k.default.resolve()]}),r=t.lastIndexOf(e.replace(/\//g,k.default.sep))+e.length;return t.substring(0,r)};var A=async({baseConfig:e,nextConfigPath:t,configDir:o})=>{let r=await _({baseConfig:e,nextConfigPath:t,configDir:o});return p(e,"next/config"),pe(e,r),r},W=f(),pe=(e,t)=>{var s,i;let o={"process.env.__NEXT_RUNTIME_CONFIG":JSON.stringify({serverRuntimeConfig:{},publicRuntimeConfig:t.publicRuntimeConfig})},r=(s=t.experimental)==null?void 0:s.newNextLinkBehavior;b.default.gte(W,"13.0.0")&&b.default.lt(W,"13.0.6")&&r!==!1?o["process.env.__NEXT_NEW_LINK_BEHAVIOR"]=!0:o["process.env.__NEXT_NEW_LINK_BEHAVIOR"]=r,(i=e.plugins)==null||i.push(new V.DefinePlugin(o))};var v=require("next/dist/build/webpack/config/blocks/css/loaders/getCssModuleLocalIdent"),w=require("next/dist/build/webpack/config/blocks/css/loaders/file-resolve"),$=n(require("semver"));var q=(e,t)=>{var r,s,i;let o=(r=e.module)==null?void 0:r.rules;o==null||o.forEach((m,l)=>{typeof m!="string"&&m.test instanceof RegExp&&m.test.test("test.css")&&(o[l]={test:/\.css$/,use:["style-loader",{loader:"css-loader",options:{importLoaders:1,...F(t),modules:{auto:!0,getLocalIdent:v.getCssModuleLocalIdent}}},"postcss-loader"]})}),o==null||o.push({test:/\.(scss|sass)$/,use:["style-loader",{loader:"css-loader",options:{importLoaders:3,...F(t),modules:{auto:!0,getLocalIdent:v.getCssModuleLocalIdent}}},"postcss-loader","resolve-url-loader",{loader:"sass-loader",options:{sourceMap:!0,sassOptions:t.sassOptions,additionalData:((s=t.sassOptions)==null?void 0:s.prependData)||((i=t.sassOptions)==null?void 0:i.additionalData)}}]})},F=e=>ae()?{url:{filter:L(e)},import:{filter:T(e)}}:{url:L(e),import:T(e)},L=e=>(t,o)=>{var r;return(0,w.cssFileResolve)(t,o,(r=e.experimental)==null?void 0:r.urlImports)},T=e=>(t,o,r)=>{var s;return(0,w.cssFileResolve)(typeof t=="string"?t:t.url,r,(s=e.experimental)==null?void 0:s.urlImports)},ae=()=>{try{let e=require(y("css-loader/package.json")).version;return $.default.gte(e,"6.0.0")}catch{return!1}};var D=n(require("tsconfig-paths-webpack-plugin")),M=require("tsconfig-paths"),B=e=>{let t=(0,M.loadConfig)();t.resultType==="failed"||!t.baseUrl||(e.resolve??={},e.resolve.plugins??=[],e.resolve.plugins.push(new D.default({configFile:t.configFileAbsolutePath,extensions:[".js",".jsx",".ts",".tsx"]})))};var U=n(require("semver"));var J=e=>{let t=fe();p(e,t)},fe=()=>{let e=f();return U.default.gte(e,"11.1.0")?"next/dist/shared/lib/router-context":"next/dist/next-server/lib/router-context"};var X=n(require("semver"));var H=e=>{let t=f();X.default.gte(t,"12.0.0")?p(e,"styled-jsx"):(p(e,"styled-jsx/babel"),p(e,"styled-jsx/css"),p(e,"styled-jsx/macro"),p(e,"styled-jsx/server"),p(e,"styled-jsx/style"),p(e,"styled-jsx/webpack"))};var K=n(require("semver"));var G=e=>{ce(e),p(e,"next/image")},ce=e=>{var s,i,m;let t=f();if(K.default.lt(t,"11.0.0"))return;let o=(s=e.module)==null?void 0:s.rules,r=o==null?void 0:o.find(l=>typeof l!="string"&&l.test instanceof RegExp&&l.test.test("test.jpg"));!r||(r.test=/\.(apng|eot|otf|ttf|woff|woff2|cur|ani|pdf)(\?.*)?$/,o==null||o.push({test:/\.(png|jpg|jpeg|gif|webp|avif|ico|bmp|svg)$/i,issuer:{not:/\.(css|scss|sass)$/},use:[{loader:require.resolve("@storybook/nextjs/next-image-loader-stub.js"),options:{filename:(i=r.generator)==null?void 0:i.filename}}]}),o==null||o.push({test:/\.(png|jpg|jpeg|gif|webp|avif|ico|bmp|svg)$/i,issuer:/\.(css|scss|sass)$/,type:"asset/resource",generator:{filename:(m=r.generator)==null?void 0:m.filename}}))};var u=n(require("semver")),d=require("webpack");function z(e){let t=f(),o=u.default.satisfies(t,"~12"),r=u.default.satisfies(t,"~13"),s=u.default.lt(t,"12.2.0"),i=u.default.lt(t,"13.0.0");e.plugins=e.plugins??[],r||e.plugins.push(new d.IgnorePlugin({resourceRegExp:/next\/legacy\/image$/})),(!o||s)&&e.plugins.push(new d.IgnorePlugin({resourceRegExp:/next\/future\/image$/})),i&&e.plugins.push(new d.IgnorePlugin({resourceRegExp:/next\/dist\/shared\/lib\/hooks-client-context$/})),s&&e.plugins.push(new d.IgnorePlugin({resourceRegExp:/next\/dist\/shared\/lib\/app-router-context$/}))}var me=[(0,c.dirname)(require.resolve((0,c.join)("@storybook/preset-react-webpack","package.json"))),(0,c.dirname)(require.resolve((0,c.join)("@storybook/builder-webpack5","package.json")))],C={},le=async(e,t)=>{let o=await t.presets.apply("framework");return typeof o=="string"?{name:o,options:C}:typeof o>"u"?{name:require.resolve("@storybook/nextjs"),options:C}:{name:o.name,options:{...C,...o.options}}},ge=async(e,t)=>{let o=await t.presets.apply("framework");return{...e,builder:{name:(0,c.dirname)(require.resolve((0,c.join)("@storybook/builder-webpack5","package.json"))),options:typeof o=="string"?{}:o.options.builder||{}},renderer:(0,c.dirname)(require.resolve((0,c.join)("@storybook/react","package.json")))}},ue=(e=[])=>[...e,require.resolve("@storybook/nextjs/preview.js")],de=async e=>{var m,l,N;let t=(0,Q.loadPartialConfig)({...e,filename:`${(0,Y.getProjectRoot)()}/__fake__.js`}),o=t==null?void 0:t.options,r=a=>typeof a=="object"&&a!==null&&"file"in a;((m=o==null?void 0:o.presets)==null?void 0:m.find(a=>{var g;return Array.isArray(a)&&a[0]==="next/babel"||a==="next/babel"||r(a)&&((g=a.file)==null?void 0:g.request)==="next/babel"}))||(l=o==null?void 0:o.presets)==null||l.push("next/babel");let i=(N=o==null?void 0:o.presets)==null?void 0:N.filter(a=>{var g;return!(r(a)&&((g=a.file)==null?void 0:g.request)===require.resolve("@babel/preset-react"))});return{...o,presets:i,babelrc:!1,configFile:!1}},xe=async(e,t)=>{let o=await t.presets.apply("frameworkOptions"),{options:{nextConfigPath:r}={}}=o,s=await A({baseConfig:e,nextConfigPath:r,configDir:t.configDir});return z(e),O(e),B(e),q(e,s),G(e),J(e),H(e),e};0&&(module.exports={addons,babel,config,core,frameworkOptions,webpackFinal});
package/dist/preset.mjs CHANGED
@@ -2,4 +2,4 @@ import{__require}from"./chunk-LAHENP5R.mjs";import{dirname,join}from"path";impor
2
2
  Could not find or resolve your Next config file. Please provide the next config file path as a framework option.
3
3
 
4
4
  More info: https://github.com/storybookjs/storybook/blob/next/code/frameworks/nextjs/README.md#options
5
- `);let nextConfigExport=await import(pathToFileURL(nextConfigFile).href),nextConfig=typeof nextConfigExport=="function"?nextConfigExport(PHASE_DEVELOPMENT_SERVER,{defaultConfig:baseConfig}):nextConfigExport;return nextConfig.default||nextConfig},addScopedAlias=(baseConfig,name,alias)=>{baseConfig.resolve??={},baseConfig.resolve.alias??={};let aliasConfig=baseConfig.resolve.alias,scopedAlias=scopedResolve(`${alias??name}`);Array.isArray(aliasConfig)?aliasConfig.push({name,alias:scopedAlias}):aliasConfig[name]=scopedAlias},scopedResolve=id=>{let scopedModulePath=__require.resolve(id,{paths:[path.resolve()]}),beginningOfMainScriptPath=scopedModulePath.lastIndexOf(id.replace(/\//g,path.sep))+id.length;return scopedModulePath.substring(0,beginningOfMainScriptPath)};var configureConfig=async({baseConfig,nextConfigPath,configDir})=>{let nextConfig=await resolveNextConfig({baseConfig,nextConfigPath,configDir});return addScopedAlias(baseConfig,"next/config"),setupRuntimeConfig(baseConfig,nextConfig),nextConfig},version=getNextjsVersion(),setupRuntimeConfig=(baseConfig,nextConfig)=>{let definePluginConfig={"process.env.__NEXT_RUNTIME_CONFIG":JSON.stringify({serverRuntimeConfig:{},publicRuntimeConfig:nextConfig.publicRuntimeConfig})},newNextLinkBehavior=nextConfig.experimental?.newNextLinkBehavior;semver.gte(version,"13.0.0")&&semver.lt(version,"13.0.6")&&newNextLinkBehavior!==!1?definePluginConfig["process.env.__NEXT_NEW_LINK_BEHAVIOR"]=!0:definePluginConfig["process.env.__NEXT_NEW_LINK_BEHAVIOR"]=newNextLinkBehavior,baseConfig.plugins?.push(new DefinePlugin2(definePluginConfig))};import{getCssModuleLocalIdent}from"next/dist/build/webpack/config/blocks/css/loaders/getCssModuleLocalIdent";import{cssFileResolve}from"next/dist/build/webpack/config/blocks/css/loaders/file-resolve";import semver2 from"semver";var configureCss=(baseConfig,nextConfig)=>{let rules=baseConfig.module?.rules;rules?.forEach((rule,i)=>{typeof rule!="string"&&rule.test instanceof RegExp&&rule.test.test("test.css")&&(rules[i]={test:/\.css$/,use:["style-loader",{loader:"css-loader",options:{importLoaders:1,...getImportAndUrlCssLoaderOptions(nextConfig),modules:{auto:!0,getLocalIdent:getCssModuleLocalIdent}}},"postcss-loader"]})}),rules?.push({test:/\.(scss|sass)$/,use:["style-loader",{loader:"css-loader",options:{importLoaders:3,...getImportAndUrlCssLoaderOptions(nextConfig),modules:{auto:!0,getLocalIdent:getCssModuleLocalIdent}}},"postcss-loader","resolve-url-loader",{loader:"sass-loader",options:{sourceMap:!0,sassOptions:nextConfig.sassOptions,additionalData:nextConfig.sassOptions?.prependData||nextConfig.sassOptions?.additionalData}}]})},getImportAndUrlCssLoaderOptions=nextConfig=>isCssLoaderV6()?{url:{filter:getUrlResolver(nextConfig)},import:{filter:getImportResolver(nextConfig)}}:{url:getUrlResolver(nextConfig),import:getImportResolver(nextConfig)},getUrlResolver=nextConfig=>(url,resourcePath)=>cssFileResolve(url,resourcePath,nextConfig.experimental?.urlImports),getImportResolver=nextConfig=>(url,_,resourcePath)=>cssFileResolve(typeof url=="string"?url:url.url,resourcePath,nextConfig.experimental?.urlImports),isCssLoaderV6=()=>{try{let cssLoaderVersion=__require(scopedResolve("css-loader/package.json")).version;return semver2.gte(cssLoaderVersion,"6.0.0")}catch{return!1}};import TsconfigPathsPlugin from"tsconfig-paths-webpack-plugin";import{loadConfig}from"tsconfig-paths";var configureImports=baseConfig=>{let configLoadResult=loadConfig();configLoadResult.resultType==="failed"||!configLoadResult.baseUrl||(baseConfig.resolve??={},baseConfig.resolve.plugins??=[],baseConfig.resolve.plugins.push(new TsconfigPathsPlugin({configFile:configLoadResult.configFileAbsolutePath,extensions:[".js",".jsx",".ts",".tsx"]})))};import semver3 from"semver";var configureRouting=baseConfig=>{let routerContextPath=getRouterContextPath();addScopedAlias(baseConfig,routerContextPath)},getRouterContextPath=()=>{let version2=getNextjsVersion();return semver3.gte(version2,"11.1.0")?"next/dist/shared/lib/router-context":"next/dist/next-server/lib/router-context"};import semver4 from"semver";var configureStyledJsx=baseConfig=>{let version2=getNextjsVersion();semver4.gte(version2,"12.0.0")?addScopedAlias(baseConfig,"styled-jsx"):(addScopedAlias(baseConfig,"styled-jsx/babel"),addScopedAlias(baseConfig,"styled-jsx/css"),addScopedAlias(baseConfig,"styled-jsx/macro"),addScopedAlias(baseConfig,"styled-jsx/server"),addScopedAlias(baseConfig,"styled-jsx/style"),addScopedAlias(baseConfig,"styled-jsx/webpack"))};import semver5 from"semver";var configureImages=baseConfig=>{configureStaticImageImport(baseConfig),addScopedAlias(baseConfig,"next/image")},configureStaticImageImport=baseConfig=>{let version2=getNextjsVersion();if(semver5.lt(version2,"11.0.0"))return;let rules=baseConfig.module?.rules,assetRule=rules?.find(rule=>typeof rule!="string"&&rule.test instanceof RegExp&&rule.test.test("test.jpg"));!assetRule||(assetRule.test=/\.(apng|eot|otf|ttf|woff|woff2|cur|ani|pdf)(\?.*)?$/,rules?.push({test:/\.(png|jpg|jpeg|gif|webp|avif|ico|bmp|svg)$/i,issuer:{not:/\.(css|scss|sass)$/},use:[{loader:__require.resolve("@storybook/nextjs/next-image-loader-stub.js"),options:{filename:assetRule.generator?.filename}}]}),rules?.push({test:/\.(png|jpg|jpeg|gif|webp|avif|ico|bmp|svg)$/i,issuer:/\.(css|scss|sass)$/,type:"asset/resource",generator:{filename:assetRule.generator?.filename}}))};import semver6 from"semver";import{IgnorePlugin}from"webpack";function configureNextImport(baseConfig){let nextJSVersion=getNextjsVersion(),isNext12=semver6.satisfies(nextJSVersion,"~12"),isNext13=semver6.satisfies(nextJSVersion,"~13"),isNextVersionSmallerThan13=semver6.lt(nextJSVersion,"13.0.0");baseConfig.plugins=baseConfig.plugins??[],isNext13||baseConfig.plugins.push(new IgnorePlugin({resourceRegExp:/next\/legacy\/image$/})),isNext12||baseConfig.plugins.push(new IgnorePlugin({resourceRegExp:/next\/future\/image$/})),isNextVersionSmallerThan13&&baseConfig.plugins.push(new IgnorePlugin({resourceRegExp:/next\/dist\/shared\/lib\/hooks-client-context$/})),semver6.lt(nextJSVersion,"12.2.0")&&baseConfig.plugins.push(new IgnorePlugin({resourceRegExp:/next\/dist\/shared\/lib\/app-router-context$/}))}var addons=[dirname(__require.resolve(join("@storybook/preset-react-webpack","package.json"))),dirname(__require.resolve(join("@storybook/builder-webpack5","package.json")))],defaultFrameworkOptions={},frameworkOptions=async(_,options)=>{let config2=await options.presets.apply("framework");return typeof config2=="string"?{name:config2,options:defaultFrameworkOptions}:typeof config2>"u"?{name:__require.resolve("@storybook/nextjs"),options:defaultFrameworkOptions}:{name:config2.name,options:{...defaultFrameworkOptions,...config2.options}}},core=async(config2,options)=>{let framework=await options.presets.apply("framework");return{...config2,builder:{name:dirname(__require.resolve(join("@storybook/builder-webpack5","package.json"))),options:typeof framework=="string"?{}:framework.options.builder||{}},renderer:dirname(__require.resolve(join("@storybook/react","package.json")))}},config=(entry=[])=>[...entry,__require.resolve("@storybook/nextjs/preview.js")],babel=async baseConfig=>{let options=loadPartialConfig({...baseConfig,filename:`${getProjectRoot()}/__fake__.js`})?.options,isPresetConfigItem=preset=>typeof preset=="object"&&preset!==null&&"file"in preset;options?.presets?.find(preset=>Array.isArray(preset)&&preset[0]==="next/babel"||preset==="next/babel"||isPresetConfigItem(preset)&&preset.file?.request==="next/babel")||options?.presets?.push("next/babel");let presets=options?.presets?.filter(preset=>!(isPresetConfigItem(preset)&&preset.file?.request===__require.resolve("@babel/preset-react")));return{...options,presets,babelrc:!1,configFile:!1}},webpackFinal=async(baseConfig,options)=>{let frameworkOptions2=await options.presets.apply("frameworkOptions"),{options:{nextConfigPath}={}}=frameworkOptions2,nextConfig=await configureConfig({baseConfig,nextConfigPath,configDir:options.configDir});return configureNextImport(baseConfig),configureRuntimeNextjsVersionResolution(baseConfig),configureImports(baseConfig),configureCss(baseConfig,nextConfig),configureImages(baseConfig),configureRouting(baseConfig),configureStyledJsx(baseConfig),baseConfig};export{addons,babel,config,core,frameworkOptions,webpackFinal};
5
+ `);let nextConfigExport=await import(pathToFileURL(nextConfigFile).href),nextConfig=typeof nextConfigExport=="function"?nextConfigExport(PHASE_DEVELOPMENT_SERVER,{defaultConfig:baseConfig}):nextConfigExport;return nextConfig.default||nextConfig},addScopedAlias=(baseConfig,name,alias)=>{baseConfig.resolve??={},baseConfig.resolve.alias??={};let aliasConfig=baseConfig.resolve.alias,scopedAlias=scopedResolve(`${alias??name}`);Array.isArray(aliasConfig)?aliasConfig.push({name,alias:scopedAlias}):aliasConfig[name]=scopedAlias},scopedResolve=id=>{let scopedModulePath=__require.resolve(id,{paths:[path.resolve()]}),beginningOfMainScriptPath=scopedModulePath.lastIndexOf(id.replace(/\//g,path.sep))+id.length;return scopedModulePath.substring(0,beginningOfMainScriptPath)};var configureConfig=async({baseConfig,nextConfigPath,configDir})=>{let nextConfig=await resolveNextConfig({baseConfig,nextConfigPath,configDir});return addScopedAlias(baseConfig,"next/config"),setupRuntimeConfig(baseConfig,nextConfig),nextConfig},version=getNextjsVersion(),setupRuntimeConfig=(baseConfig,nextConfig)=>{let definePluginConfig={"process.env.__NEXT_RUNTIME_CONFIG":JSON.stringify({serverRuntimeConfig:{},publicRuntimeConfig:nextConfig.publicRuntimeConfig})},newNextLinkBehavior=nextConfig.experimental?.newNextLinkBehavior;semver.gte(version,"13.0.0")&&semver.lt(version,"13.0.6")&&newNextLinkBehavior!==!1?definePluginConfig["process.env.__NEXT_NEW_LINK_BEHAVIOR"]=!0:definePluginConfig["process.env.__NEXT_NEW_LINK_BEHAVIOR"]=newNextLinkBehavior,baseConfig.plugins?.push(new DefinePlugin2(definePluginConfig))};import{getCssModuleLocalIdent}from"next/dist/build/webpack/config/blocks/css/loaders/getCssModuleLocalIdent";import{cssFileResolve}from"next/dist/build/webpack/config/blocks/css/loaders/file-resolve";import semver2 from"semver";var configureCss=(baseConfig,nextConfig)=>{let rules=baseConfig.module?.rules;rules?.forEach((rule,i)=>{typeof rule!="string"&&rule.test instanceof RegExp&&rule.test.test("test.css")&&(rules[i]={test:/\.css$/,use:["style-loader",{loader:"css-loader",options:{importLoaders:1,...getImportAndUrlCssLoaderOptions(nextConfig),modules:{auto:!0,getLocalIdent:getCssModuleLocalIdent}}},"postcss-loader"]})}),rules?.push({test:/\.(scss|sass)$/,use:["style-loader",{loader:"css-loader",options:{importLoaders:3,...getImportAndUrlCssLoaderOptions(nextConfig),modules:{auto:!0,getLocalIdent:getCssModuleLocalIdent}}},"postcss-loader","resolve-url-loader",{loader:"sass-loader",options:{sourceMap:!0,sassOptions:nextConfig.sassOptions,additionalData:nextConfig.sassOptions?.prependData||nextConfig.sassOptions?.additionalData}}]})},getImportAndUrlCssLoaderOptions=nextConfig=>isCssLoaderV6()?{url:{filter:getUrlResolver(nextConfig)},import:{filter:getImportResolver(nextConfig)}}:{url:getUrlResolver(nextConfig),import:getImportResolver(nextConfig)},getUrlResolver=nextConfig=>(url,resourcePath)=>cssFileResolve(url,resourcePath,nextConfig.experimental?.urlImports),getImportResolver=nextConfig=>(url,_,resourcePath)=>cssFileResolve(typeof url=="string"?url:url.url,resourcePath,nextConfig.experimental?.urlImports),isCssLoaderV6=()=>{try{let cssLoaderVersion=__require(scopedResolve("css-loader/package.json")).version;return semver2.gte(cssLoaderVersion,"6.0.0")}catch{return!1}};import TsconfigPathsPlugin from"tsconfig-paths-webpack-plugin";import{loadConfig}from"tsconfig-paths";var configureImports=baseConfig=>{let configLoadResult=loadConfig();configLoadResult.resultType==="failed"||!configLoadResult.baseUrl||(baseConfig.resolve??={},baseConfig.resolve.plugins??=[],baseConfig.resolve.plugins.push(new TsconfigPathsPlugin({configFile:configLoadResult.configFileAbsolutePath,extensions:[".js",".jsx",".ts",".tsx"]})))};import semver3 from"semver";var configureRouting=baseConfig=>{let routerContextPath=getRouterContextPath();addScopedAlias(baseConfig,routerContextPath)},getRouterContextPath=()=>{let version2=getNextjsVersion();return semver3.gte(version2,"11.1.0")?"next/dist/shared/lib/router-context":"next/dist/next-server/lib/router-context"};import semver4 from"semver";var configureStyledJsx=baseConfig=>{let version2=getNextjsVersion();semver4.gte(version2,"12.0.0")?addScopedAlias(baseConfig,"styled-jsx"):(addScopedAlias(baseConfig,"styled-jsx/babel"),addScopedAlias(baseConfig,"styled-jsx/css"),addScopedAlias(baseConfig,"styled-jsx/macro"),addScopedAlias(baseConfig,"styled-jsx/server"),addScopedAlias(baseConfig,"styled-jsx/style"),addScopedAlias(baseConfig,"styled-jsx/webpack"))};import semver5 from"semver";var configureImages=baseConfig=>{configureStaticImageImport(baseConfig),addScopedAlias(baseConfig,"next/image")},configureStaticImageImport=baseConfig=>{let version2=getNextjsVersion();if(semver5.lt(version2,"11.0.0"))return;let rules=baseConfig.module?.rules,assetRule=rules?.find(rule=>typeof rule!="string"&&rule.test instanceof RegExp&&rule.test.test("test.jpg"));!assetRule||(assetRule.test=/\.(apng|eot|otf|ttf|woff|woff2|cur|ani|pdf)(\?.*)?$/,rules?.push({test:/\.(png|jpg|jpeg|gif|webp|avif|ico|bmp|svg)$/i,issuer:{not:/\.(css|scss|sass)$/},use:[{loader:__require.resolve("@storybook/nextjs/next-image-loader-stub.js"),options:{filename:assetRule.generator?.filename}}]}),rules?.push({test:/\.(png|jpg|jpeg|gif|webp|avif|ico|bmp|svg)$/i,issuer:/\.(css|scss|sass)$/,type:"asset/resource",generator:{filename:assetRule.generator?.filename}}))};import semver6 from"semver";import{IgnorePlugin}from"webpack";function configureNextImport(baseConfig){let nextJSVersion=getNextjsVersion(),isNext12=semver6.satisfies(nextJSVersion,"~12"),isNext13=semver6.satisfies(nextJSVersion,"~13"),isNextVersionSmallerThan12dot2=semver6.lt(nextJSVersion,"12.2.0"),isNextVersionSmallerThan13=semver6.lt(nextJSVersion,"13.0.0");baseConfig.plugins=baseConfig.plugins??[],isNext13||baseConfig.plugins.push(new IgnorePlugin({resourceRegExp:/next\/legacy\/image$/})),(!isNext12||isNextVersionSmallerThan12dot2)&&baseConfig.plugins.push(new IgnorePlugin({resourceRegExp:/next\/future\/image$/})),isNextVersionSmallerThan13&&baseConfig.plugins.push(new IgnorePlugin({resourceRegExp:/next\/dist\/shared\/lib\/hooks-client-context$/})),isNextVersionSmallerThan12dot2&&baseConfig.plugins.push(new IgnorePlugin({resourceRegExp:/next\/dist\/shared\/lib\/app-router-context$/}))}var addons=[dirname(__require.resolve(join("@storybook/preset-react-webpack","package.json"))),dirname(__require.resolve(join("@storybook/builder-webpack5","package.json")))],defaultFrameworkOptions={},frameworkOptions=async(_,options)=>{let config2=await options.presets.apply("framework");return typeof config2=="string"?{name:config2,options:defaultFrameworkOptions}:typeof config2>"u"?{name:__require.resolve("@storybook/nextjs"),options:defaultFrameworkOptions}:{name:config2.name,options:{...defaultFrameworkOptions,...config2.options}}},core=async(config2,options)=>{let framework=await options.presets.apply("framework");return{...config2,builder:{name:dirname(__require.resolve(join("@storybook/builder-webpack5","package.json"))),options:typeof framework=="string"?{}:framework.options.builder||{}},renderer:dirname(__require.resolve(join("@storybook/react","package.json")))}},config=(entry=[])=>[...entry,__require.resolve("@storybook/nextjs/preview.js")],babel=async baseConfig=>{let options=loadPartialConfig({...baseConfig,filename:`${getProjectRoot()}/__fake__.js`})?.options,isPresetConfigItem=preset=>typeof preset=="object"&&preset!==null&&"file"in preset;options?.presets?.find(preset=>Array.isArray(preset)&&preset[0]==="next/babel"||preset==="next/babel"||isPresetConfigItem(preset)&&preset.file?.request==="next/babel")||options?.presets?.push("next/babel");let presets=options?.presets?.filter(preset=>!(isPresetConfigItem(preset)&&preset.file?.request===__require.resolve("@babel/preset-react")));return{...options,presets,babelrc:!1,configFile:!1}},webpackFinal=async(baseConfig,options)=>{let frameworkOptions2=await options.presets.apply("frameworkOptions"),{options:{nextConfigPath}={}}=frameworkOptions2,nextConfig=await configureConfig({baseConfig,nextConfigPath,configDir:options.configDir});return configureNextImport(baseConfig),configureRuntimeNextjsVersionResolution(baseConfig),configureImports(baseConfig),configureCss(baseConfig,nextConfig),configureImages(baseConfig),configureRouting(baseConfig),configureStyledJsx(baseConfig),baseConfig};export{addons,babel,config,core,frameworkOptions,webpackFinal};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@storybook/nextjs",
3
- "version": "7.0.0-beta.1",
3
+ "version": "7.0.0-beta.2",
4
4
  "description": "Storybook for Next.js",
5
5
  "keywords": [
6
6
  "storybook",
@@ -59,12 +59,12 @@
59
59
  "prep": "../../../scripts/prepare/bundle.ts"
60
60
  },
61
61
  "dependencies": {
62
- "@storybook/builder-webpack5": "7.0.0-beta.1",
63
- "@storybook/core-common": "7.0.0-beta.1",
64
- "@storybook/node-logger": "7.0.0-beta.1",
65
- "@storybook/preset-react-webpack": "7.0.0-beta.1",
66
- "@storybook/preview-api": "7.0.0-beta.1",
67
- "@storybook/react": "7.0.0-beta.1",
62
+ "@storybook/builder-webpack5": "7.0.0-beta.2",
63
+ "@storybook/core-common": "7.0.0-beta.2",
64
+ "@storybook/node-logger": "7.0.0-beta.2",
65
+ "@storybook/preset-react-webpack": "7.0.0-beta.2",
66
+ "@storybook/preview-api": "7.0.0-beta.2",
67
+ "@storybook/react": "7.0.0-beta.2",
68
68
  "@types/node": "^16.0.0",
69
69
  "find-up": "^5.0.0",
70
70
  "fs-extra": "^9.0.1",
@@ -80,7 +80,7 @@
80
80
  "tsconfig-paths-webpack-plugin": "^3.5.2"
81
81
  },
82
82
  "devDependencies": {
83
- "@storybook/addon-actions": "7.0.0-beta.1",
83
+ "@storybook/addon-actions": "7.0.0-beta.2",
84
84
  "next": "^13.0.5",
85
85
  "typescript": "^4.9.3",
86
86
  "webpack": "^5.65.0"
@@ -119,5 +119,5 @@
119
119
  ],
120
120
  "platform": "node"
121
121
  },
122
- "gitHead": "42c08678ac06d9c2c8e7a4c31a91e0a14bf5c2cd"
122
+ "gitHead": "66a0d588184add900c48d49f3a62743fa9cc5185"
123
123
  }