Skip to content

Commit 050d81e

Browse files
fix(.storybook): fix alias paths with tsconfig plugin
1 parent ffdbd8a commit 050d81e

File tree

6 files changed

+21
-16
lines changed

6 files changed

+21
-16
lines changed

.storybook/main.ts

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
import path from "path"
2-
31
import type { StorybookConfig } from "@storybook/nextjs"
42
import { propNames } from "@chakra-ui/react"
53

4+
import TsconfigPathsPlugin from "tsconfig-paths-webpack-plugin"
5+
66
/**
77
* Note regarding package.json settings related to Storybook:
88
*
@@ -37,11 +37,15 @@ const config: StorybookConfig = {
3737
disable: true,
3838
},
3939
},
40-
webpackFinal: async (config: any) => {
41-
// Add path aliases
42-
config.resolve.alias["@"] = path.resolve(__dirname, "../src")
43-
config.resolve.alias["@/public"] = path.resolve(__dirname, "../public")
44-
40+
webpackFinal: async (config) => {
41+
if (config.resolve) {
42+
config.resolve.plugins = [
43+
...(config.resolve.plugins || []),
44+
new TsconfigPathsPlugin({
45+
extensions: config.resolve.extensions,
46+
}),
47+
]
48+
}
4549
return config
4650
},
4751
typescript: {

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,11 +91,12 @@
9191
"storybook": "7.6.6",
9292
"storybook-react-i18next": "^2.0.9",
9393
"ts-node": "^10.9.1",
94+
"tsconfig-paths-webpack-plugin": "4.1.0",
9495
"typescript": "^5.4.2",
9596
"unified": "^10.0.0",
9697
"unist-util-visit": "^5.0.0"
9798
},
9899
"resolutions": {
99100
"jackspeak": "2.1.1"
100101
}
101-
}
102+
}

src/components/Hero/ContentHero/ContentHero.stories.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@ import { Meta, StoryObj } from "@storybook/react"
33

44
import ContentHeroComponent, { ContentHeroProps } from "."
55

6-
type ContentHeroType = typeof ContentHeroComponent
6+
import contentHeroImg from "@/public/mainnet.png"
77

8-
import contentHeroImg from "../../../../public/mainnet.png"
8+
type ContentHeroType = typeof ContentHeroComponent
99

1010
const meta = {
1111
title: "Organisms / Layouts / Hero",

src/components/Hero/HomeHero/HomeHero.stories.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ const meta = {
2222

2323
export default meta
2424

25-
import homeHeroImg from "../../../../public/home/hero.png"
25+
import homeHeroImg from "@/public/home/hero.png"
2626

2727
export const HomeHero: StoryObj<typeof meta> = {
2828
args: {

src/components/Hero/HubHero/HubHero.stories.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,12 @@ import { useTranslation } from "next-i18next"
33
import { Box } from "@chakra-ui/react"
44
import { Meta, StoryObj } from "@storybook/react"
55

6+
import { CommonHeroProps } from "@/lib/types"
7+
68
import HubHeroComponent from "./"
79

10+
import learnHubHeroImg from "@/public/heroes/learn-hub-hero.png"
11+
812
type HubHeroType = typeof HubHeroComponent
913

1014
const meta = {
@@ -24,10 +28,6 @@ const meta = {
2428

2529
export default meta
2630

27-
import { CommonHeroProps } from "@/lib/types"
28-
29-
import learnHubHeroImg from "../../../../public/heroes/learn-hub-hero.png"
30-
3131
export const HubHero: StoryObj<typeof meta> = {
3232
args: {
3333
title: "common:learn-hub",

yarn.lock

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13108,7 +13108,7 @@ ts-pnp@^1.1.6:
1310813108
resolved "https://registry.yarnpkg.com/ts-pnp/-/ts-pnp-1.2.0.tgz#a500ad084b0798f1c3071af391e65912c86bca92"
1310913109
integrity sha512-csd+vJOb/gkzvcCHgTGSChYpy5f1/XKNsmvBGO4JXS+z1v2HobugDz4s1IeFXM3wZB44uczs+eazB5Q/ccdhQw==
1311013110

13111-
tsconfig-paths-webpack-plugin@^4.0.1:
13111+
tsconfig-paths-webpack-plugin@^4.0.1, tsconfig-paths-webpack-plugin@^4.1.0:
1311213112
version "4.1.0"
1311313113
resolved "https://registry.yarnpkg.com/tsconfig-paths-webpack-plugin/-/tsconfig-paths-webpack-plugin-4.1.0.tgz#3c6892c5e7319c146eee1e7302ed9e6f2be4f763"
1311413114
integrity sha512-xWFISjviPydmtmgeUAuXp4N1fky+VCtfhOkDUFIv5ea7p4wuTomI4QTrXvFBX2S4jZsmyTSrStQl+E+4w+RzxA==

0 commit comments

Comments
 (0)