Skip to content

Commit c0d8f06

Browse files
docs: update guide for Storybook integration (#1735)
1 parent 1bb8a34 commit c0d8f06

File tree

2 files changed

+105
-39
lines changed

2 files changed

+105
-39
lines changed

apps/docs-app/docs/integrations/storybook/index.md

Lines changed: 52 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -144,17 +144,18 @@ To load shared CSS paths, configure them using `loadPaths` css option in the `vi
144144

145145
```ts
146146
import path from 'node:path';
147+
import { UserConfig, mergeConfig } from 'vite';
147148

148-
async viteFinal() {
149-
return {
149+
export async function viteFinal(config: UserConfig) {
150+
return mergeConfig(config, {
150151
css: {
151152
preprocessorOptions: {
152153
scss: {
153-
loadPaths: `${path.resolve(__dirname, '../src/lib/styles')}`
154-
}
155-
}
156-
}
157-
};
154+
loadPaths: `${path.resolve(__dirname, '../src/lib/styles')}`,
155+
},
156+
},
157+
},
158+
});
158159
}
159160
```
160161

@@ -192,32 +193,64 @@ pnpm install -w vite-tsconfig-paths --save-dev
192193
</TabItem>
193194
</Tabs>
194195

195-
Next, add the plugin to the `plugins` array.
196+
Next, add the plugin to the `plugins` array in the `.storybook/main.ts`.
196197

197198
```ts
198199
import viteTsConfigPaths from 'vite-tsconfig-paths';
200+
import { UserConfig, mergeConfig } from 'vite';
199201

200-
async viteFinal() {
201-
return {
202-
plugins: [
203-
viteTsConfigPaths()
204-
],
205-
};
202+
export async function viteFinal(config: UserConfig) {
203+
return mergeConfig(config, {
204+
plugins: [viteTsConfigPaths()],
205+
});
206206
}
207207
```
208208

209209
### With Nx
210210

211-
For Nx workspaces, import and use the `nxViteTsPaths` plugin from the `@nx/vite` package.
211+
For Nx workspaces, import and use the `nxViteTsPaths` plugin from the `@nx/vite` package. Add the plugin to the `plugins` array in the `.storybook/main.ts`.
212212

213213
```ts
214214
import { nxViteTsPaths } from '@nx/vite/plugins/nx-tsconfig-paths.plugin';
215+
import { UserConfig, mergeConfig } from 'vite';
216+
217+
export async function viteFinal(config: UserConfig) {
218+
return mergeConfig(config, {
219+
plugins: [nxViteTsPaths()],
220+
});
221+
}
222+
```
223+
224+
## Using File Replacements
215225

216-
async viteFinal(config: UserConfig) {
217-
return {
226+
You can also use the `replaceFiles()` plugin from Nx to replace files during your build.
227+
228+
Import the plugin and set it up:
229+
230+
```ts
231+
import { replaceFiles } from '@nx/vite/plugins/rollup-replace-files.plugin';
232+
import { UserConfig, mergeConfig } from 'vite';
233+
234+
export async function viteFinal(config: UserConfig) {
235+
return mergeConfig(config, {
218236
plugins: [
219-
nxViteTsPaths()
237+
replaceFiles([
238+
{
239+
replace: './src/one.ts',
240+
with: './src/two.ts',
241+
},
242+
]),
220243
],
221-
};
244+
});
245+
}
246+
```
247+
248+
Adding the replacement files to `files` array in the `tsconfig.app.json` may also be necessary.
249+
250+
```json
251+
{
252+
"extends": "./tsconfig.json",
253+
// other config
254+
"files": ["src/main.ts", "src/main.server.ts", "src/two.ts"]
222255
}
223256
```

packages/storybook-angular/README.md

Lines changed: 53 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ Add the `zone.js` import to the top of the `.storybook/preview.ts` file.
2626

2727
```ts
2828
import 'zone.js';
29-
import { applicationConfig, type Preview } from '@storybook/angular';
29+
import { applicationConfig, type Preview } from '@analogjs/storybook-angular';
3030
import { provideNoopAnimations } from '@angular/platform-browser/animations';
3131

3232
const preview: Preview = {
@@ -101,17 +101,18 @@ To load shared CSS paths, configure them using `loadPaths` css option in the `vi
101101

102102
```ts
103103
import path from 'node:path';
104+
import { UserConfig, mergeConfig } from 'vite';
104105

105-
async viteFinal() {
106-
return {
106+
export async function viteFinal(config: UserConfig) {
107+
return mergeConfig(config, {
107108
css: {
108109
preprocessorOptions: {
109110
scss: {
110-
loadPaths: `${path.resolve(__dirname, '../src/lib/styles')}`
111-
}
112-
}
113-
}
114-
};
111+
loadPaths: `${path.resolve(__dirname, '../src/lib/styles')}`,
112+
},
113+
},
114+
},
115+
});
115116
}
116117
```
117118

@@ -127,32 +128,64 @@ First, install the `vite-tsconfig-paths` package.
127128
npm install vite-tsconfig-paths --save-dev
128129
```
129130

130-
Next, add the plugin to the `plugins` array.
131+
Next, add the plugin to the `plugins` array in the `.storybook/main.ts`.
131132

132133
```ts
133134
import viteTsConfigPaths from 'vite-tsconfig-paths';
135+
import { UserConfig, mergeConfig } from 'vite';
134136

135-
async viteFinal() {
136-
return {
137-
plugins: [
138-
viteTsConfigPaths()
139-
],
140-
};
137+
export async function viteFinal(config: UserConfig) {
138+
return mergeConfig(config, {
139+
plugins: [viteTsConfigPaths()],
140+
});
141141
}
142142
```
143143

144144
### With Nx
145145

146-
For Nx workspaces, import and use the `nxViteTsPaths` plugin from the `@nx/vite` package.
146+
For Nx workspaces, import and use the `nxViteTsPaths` plugin from the `@nx/vite` package. Add the plugin to the `plugins` array in the `.storybook/main.ts`.
147147

148148
```ts
149149
import { nxViteTsPaths } from '@nx/vite/plugins/nx-tsconfig-paths.plugin';
150+
import { UserConfig, mergeConfig } from 'vite';
151+
152+
export async function viteFinal(config: UserConfig) {
153+
return mergeConfig(config, {
154+
plugins: [nxViteTsPaths()],
155+
});
156+
}
157+
```
158+
159+
## Using File Replacements
150160

151-
async viteFinal(config: UserConfig) {
152-
return {
161+
You can also use the `replaceFiles()` plugin from Nx to replace files during your build.
162+
163+
Import the plugin and set it up:
164+
165+
```ts
166+
import { replaceFiles } from '@nx/vite/plugins/rollup-replace-files.plugin';
167+
import { UserConfig, mergeConfig } from 'vite';
168+
169+
export async function viteFinal(config: UserConfig) {
170+
return mergeConfig(config, {
153171
plugins: [
154-
nxViteTsPaths()
172+
replaceFiles([
173+
{
174+
replace: './src/one.ts',
175+
with: './src/two.ts',
176+
},
177+
]),
155178
],
156-
};
179+
});
180+
}
181+
```
182+
183+
Adding the replacement files to `files` array in the `tsconfig.app.json` may also be necessary.
184+
185+
```json
186+
{
187+
"extends": "./tsconfig.json",
188+
// other config
189+
"files": ["src/main.ts", "src/main.server.ts", "src/two.ts"]
157190
}
158191
```

0 commit comments

Comments
 (0)