histoire 0.2.5 → 0.3.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.
Files changed (219) hide show
  1. package/dist/client/app/App.vue +8 -3
  2. package/dist/client/app/codegen/const.d.ts +1 -0
  3. package/dist/client/app/codegen/const.js +3 -0
  4. package/dist/client/app/codegen/vue3.js +83 -21
  5. package/dist/client/app/codegen/vue3.js.map +1 -0
  6. package/dist/client/app/components/base/BaseEmpty.vue +17 -1
  7. package/dist/client/app/components/base/BaseOverflowMenu.vue +118 -0
  8. package/dist/client/app/components/base/BaseOverflowTab.vue +46 -0
  9. package/dist/client/app/components/exposed/Story.vue +33 -1
  10. package/dist/client/app/components/exposed/Variant.vue +19 -1
  11. package/dist/client/app/components/panel/PaneTabs.vue +64 -0
  12. package/dist/client/app/components/{story → panel}/StoryControls.vue +6 -1
  13. package/dist/client/app/components/{story → panel}/StoryDocs.vue +18 -11
  14. package/dist/client/app/components/panel/StoryEvent.vue +53 -0
  15. package/dist/client/app/components/panel/StoryEvents.vue +45 -0
  16. package/{src/client/app/components/story → dist/client/app/components/panel}/StorySidePanel.vue +17 -20
  17. package/{src/client/app/components/story → dist/client/app/components/panel}/StorySourceCode.vue +24 -14
  18. package/dist/client/app/components/sandbox/SandboxVue3.vue +16 -4
  19. package/dist/client/app/components/sandbox/lib.js +2 -1
  20. package/dist/client/app/components/search/SearchLoading.vue +16 -0
  21. package/dist/client/app/components/search/SearchModal.vue +12 -149
  22. package/dist/client/app/components/search/SearchPane.vue +210 -0
  23. package/dist/client/app/components/search/search-data.d.ts +2 -0
  24. package/dist/client/app/components/search/search-data.js +8 -0
  25. package/dist/client/app/components/search/search-data.js.map +1 -0
  26. package/dist/client/app/components/story/StoryResponsivePreview.vue +9 -98
  27. package/dist/client/app/components/story/StoryVariantSingle.vue +109 -0
  28. package/dist/client/app/components/story/StoryVariantSinglePreviewNative.vue +39 -0
  29. package/dist/client/app/components/story/StoryVariantSinglePreviewRemote.vue +153 -0
  30. package/dist/client/app/components/story/StoryVariantSingleView.vue +13 -6
  31. package/dist/client/app/components/story/StoryView.vue +17 -3
  32. package/dist/client/app/components/story/StoryViewer.vue +2 -92
  33. package/dist/client/app/components/{story/toolbar → toolbar}/StoryVariantBackground.vue +3 -3
  34. package/{src/client/app/components/story → dist/client/app/components}/toolbar/StoryVariantNewTab.vue +2 -2
  35. package/dist/client/app/components/{story/toolbar → toolbar}/StoryVariantResponsiveSize.vue +3 -3
  36. package/{src/client/app/components/story → dist/client/app/components}/toolbar/StoryVariantTitle.vue +1 -1
  37. package/dist/client/app/components/tree/StoryGroup.vue +4 -4
  38. package/dist/client/app/components/tree/StoryListFolder.vue +4 -4
  39. package/dist/client/app/components/tree/StoryListItem.vue +4 -1
  40. package/dist/client/app/global-components.js +1 -0
  41. package/dist/client/app/global-components.js.map +1 -0
  42. package/dist/client/app/index.js +1 -0
  43. package/dist/client/app/index.js.map +1 -0
  44. package/dist/client/app/router.d.ts +1 -0
  45. package/dist/client/app/router.js +3 -1
  46. package/dist/client/app/sandbox.js +12 -1
  47. package/dist/client/app/sandbox.js.map +1 -0
  48. package/dist/client/app/stores/events.d.ts +29 -0
  49. package/dist/client/app/stores/events.js +26 -0
  50. package/dist/client/app/stores/events.js.map +1 -0
  51. package/dist/client/app/stores/folder.d.ts +10 -0
  52. package/dist/client/app/stores/folder.js +48 -0
  53. package/dist/client/app/stores/folder.js.map +1 -0
  54. package/dist/client/app/stores/story.d.ts +41 -8
  55. package/dist/client/app/stores/story.js +21 -33
  56. package/dist/client/app/stores/story.js.map +1 -0
  57. package/dist/client/app/style/main.pcss +5 -0
  58. package/dist/client/app/style/sandbox.css +2 -0
  59. package/dist/client/app/style/transitions.pcss +13 -0
  60. package/dist/client/app/types.d.ts +4 -0
  61. package/dist/client/app/types.js +1 -0
  62. package/dist/client/app/types.js.map +1 -0
  63. package/dist/client/app/util/const.d.ts +1 -0
  64. package/dist/client/app/util/const.js +1 -0
  65. package/dist/client/app/util/events.d.ts +1 -0
  66. package/dist/client/app/util/events.js +32 -0
  67. package/dist/client/app/util/events.js.map +1 -0
  68. package/dist/client/app/util/keyboard.js +1 -0
  69. package/dist/client/app/util/keyboard.js.map +1 -0
  70. package/dist/client/app/util/mapping.js +5 -2
  71. package/dist/client/app/util/mapping.js.map +1 -0
  72. package/dist/client/app/util/preview-settings.js +1 -0
  73. package/dist/client/app/util/preview-settings.js.map +1 -0
  74. package/dist/client/app/util/reactivity.js +1 -0
  75. package/dist/client/app/util/reactivity.js.map +1 -0
  76. package/dist/client/app/util/scroll.js +1 -0
  77. package/dist/client/app/util/scroll.js.map +1 -0
  78. package/dist/client/app/util/variant.js +1 -0
  79. package/dist/client/app/util/variant.js.map +1 -0
  80. package/dist/client/index.d.ts +4 -3
  81. package/dist/client/index.js +3 -1
  82. package/dist/client/index.js.map +1 -0
  83. package/dist/client/server/index.d.ts +7 -2
  84. package/dist/client/server/index.js +8 -26
  85. package/{src/client/server/Story.server.vue → dist/client/server/vue3/Story.vue} +14 -3
  86. package/dist/client/server/{Variant.server.vue → vue3/Variant.vue} +0 -0
  87. package/dist/client/server/vue3/run.d.ts +2 -0
  88. package/dist/client/server/vue3/run.js +33 -0
  89. package/dist/client/server/vue3/run.js.map +1 -0
  90. package/dist/controls.js +1 -0
  91. package/dist/controls.js.map +1 -0
  92. package/dist/node/alias.d.ts +2 -1
  93. package/dist/node/alias.js +3 -2
  94. package/dist/node/build.js +74 -21
  95. package/dist/node/builtin-plugins/tailwind-tokens.d.ts +5 -0
  96. package/dist/node/builtin-plugins/tailwind-tokens.js +510 -0
  97. package/dist/node/collect/index.js +3 -1
  98. package/dist/node/collect/worker.js +6 -2
  99. package/dist/node/commands/preview.js +4 -25
  100. package/dist/node/config.d.ts +103 -3
  101. package/dist/node/config.js +40 -23
  102. package/dist/node/context.d.ts +3 -3
  103. package/dist/node/context.js +1 -1
  104. package/dist/node/index.d.ts +1 -0
  105. package/dist/node/index.js +1 -0
  106. package/dist/node/load.d.ts +12 -0
  107. package/dist/node/load.js +42 -0
  108. package/dist/node/plugin.d.ts +67 -11
  109. package/dist/node/plugin.js +42 -245
  110. package/dist/node/preview.d.ts +8 -0
  111. package/dist/node/preview.js +41 -0
  112. package/dist/node/search.d.ts +2 -0
  113. package/dist/node/search.js +68 -0
  114. package/dist/node/server.js +43 -21
  115. package/dist/node/stories.d.ts +2 -0
  116. package/dist/node/stories.js +4 -4
  117. package/dist/node/types.d.ts +1 -0
  118. package/dist/node/util/find-up.d.ts +1 -0
  119. package/dist/node/util/find-up.js +20 -0
  120. package/dist/node/vite.d.ts +13 -0
  121. package/dist/node/vite.js +278 -0
  122. package/dist/style.css +174 -86
  123. package/package.json +7 -6
  124. package/scripts/copy.mjs +2 -1
  125. package/src/client/app/App.vue +8 -3
  126. package/src/client/app/codegen/const.ts +3 -0
  127. package/src/client/app/codegen/vue3.ts +80 -22
  128. package/src/client/app/components/base/BaseEmpty.vue +17 -1
  129. package/src/client/app/components/base/BaseOverflowMenu.vue +118 -0
  130. package/src/client/app/components/base/BaseOverflowTab.vue +46 -0
  131. package/src/client/app/components/exposed/Story.vue +33 -1
  132. package/src/client/app/components/exposed/Variant.vue +19 -1
  133. package/src/client/app/components/panel/PaneTabs.vue +64 -0
  134. package/src/client/app/components/{story → panel}/StoryControls.vue +6 -1
  135. package/src/client/app/components/{story → panel}/StoryDocs.vue +18 -11
  136. package/src/client/app/components/panel/StoryEvent.vue +53 -0
  137. package/src/client/app/components/panel/StoryEvents.vue +45 -0
  138. package/{dist/client/app/components/story → src/client/app/components/panel}/StorySidePanel.vue +17 -20
  139. package/{dist/client/app/components/story → src/client/app/components/panel}/StorySourceCode.vue +24 -14
  140. package/src/client/app/components/sandbox/SandboxVue3.vue +16 -4
  141. package/src/client/app/components/sandbox/lib.ts +3 -1
  142. package/src/client/app/components/search/SearchLoading.vue +16 -0
  143. package/src/client/app/components/search/SearchModal.vue +12 -149
  144. package/src/client/app/components/search/SearchPane.vue +210 -0
  145. package/src/client/app/components/search/search-data.ts +9 -0
  146. package/src/client/app/components/story/StoryResponsivePreview.vue +9 -98
  147. package/src/client/app/components/story/StoryVariantSingle.vue +109 -0
  148. package/src/client/app/components/story/StoryVariantSinglePreviewNative.vue +39 -0
  149. package/src/client/app/components/story/StoryVariantSinglePreviewRemote.vue +153 -0
  150. package/src/client/app/components/story/StoryVariantSingleView.vue +13 -6
  151. package/src/client/app/components/story/StoryView.vue +17 -3
  152. package/src/client/app/components/story/StoryViewer.vue +2 -92
  153. package/src/client/app/components/{story/toolbar → toolbar}/StoryVariantBackground.vue +3 -3
  154. package/{dist/client/app/components/story → src/client/app/components}/toolbar/StoryVariantNewTab.vue +2 -2
  155. package/src/client/app/components/{story/toolbar → toolbar}/StoryVariantResponsiveSize.vue +3 -3
  156. package/{dist/client/app/components/story → src/client/app/components}/toolbar/StoryVariantTitle.vue +1 -1
  157. package/src/client/app/components/tree/StoryGroup.vue +4 -4
  158. package/src/client/app/components/tree/StoryListFolder.vue +4 -4
  159. package/src/client/app/components/tree/StoryListItem.vue +4 -1
  160. package/src/client/app/router.ts +4 -1
  161. package/src/client/app/sandbox.ts +11 -1
  162. package/src/client/app/stores/events.ts +36 -0
  163. package/{dist/client/app/stores/story.ts → src/client/app/stores/folder.ts} +16 -23
  164. package/src/client/app/stores/story.ts +21 -40
  165. package/src/client/app/style/main.pcss +5 -0
  166. package/src/client/app/style/sandbox.css +2 -0
  167. package/src/client/app/style/transitions.pcss +13 -0
  168. package/src/client/app/types.ts +5 -0
  169. package/src/client/app/util/const.ts +1 -0
  170. package/src/client/app/util/events.ts +30 -0
  171. package/src/client/app/util/mapping.ts +4 -2
  172. package/src/client/index.ts +4 -3
  173. package/src/client/server/index.ts +14 -27
  174. package/{dist/client/server/Story.server.vue → src/client/server/vue3/Story.vue} +14 -3
  175. package/src/client/server/{Variant.server.vue → vue3/Variant.vue} +0 -0
  176. package/{dist/client/server/index.ts → src/client/server/vue3/run.ts} +10 -4
  177. package/src/node/alias.ts +4 -2
  178. package/src/node/build.ts +86 -21
  179. package/src/node/builtin-plugins/tailwind-tokens.ts +521 -0
  180. package/src/node/collect/index.ts +3 -1
  181. package/src/node/collect/worker.ts +7 -2
  182. package/src/node/commands/preview.ts +4 -33
  183. package/src/node/config.ts +53 -27
  184. package/src/node/context.ts +3 -3
  185. package/src/node/index.ts +1 -0
  186. package/src/node/load.ts +63 -0
  187. package/src/node/plugin.ts +75 -252
  188. package/src/node/preview.ts +56 -0
  189. package/src/node/search.ts +75 -0
  190. package/src/node/server.ts +49 -23
  191. package/src/node/stories.ts +4 -4
  192. package/src/node/types.ts +1 -0
  193. package/src/node/util/find-up.ts +24 -0
  194. package/src/node/vite.ts +296 -0
  195. package/tailwind.config.cjs +1 -0
  196. package/dist/client/app/codegen/serialize-js.ts +0 -119
  197. package/dist/client/app/codegen/util.ts +0 -79
  198. package/dist/client/app/codegen/vue3.ts +0 -276
  199. package/dist/client/app/components/sandbox/lib.ts +0 -8
  200. package/dist/client/app/global-components.ts +0 -13
  201. package/dist/client/app/index.ts +0 -28
  202. package/dist/client/app/router.ts +0 -17
  203. package/dist/client/app/sandbox.ts +0 -94
  204. package/dist/client/app/stores/preview-settings.ts +0 -17
  205. package/dist/client/app/types.ts +0 -78
  206. package/dist/client/app/util/config.ts +0 -6
  207. package/dist/client/app/util/const.ts +0 -3
  208. package/dist/client/app/util/dark.ts +0 -4
  209. package/dist/client/app/util/env.ts +0 -1
  210. package/dist/client/app/util/keyboard.ts +0 -99
  211. package/dist/client/app/util/mapping.ts +0 -48
  212. package/dist/client/app/util/preview-settings.ts +0 -8
  213. package/dist/client/app/util/reactivity.ts +0 -22
  214. package/dist/client/app/util/responsive.ts +0 -3
  215. package/dist/client/app/util/scroll.ts +0 -31
  216. package/dist/client/app/util/tooltip.ts +0 -13
  217. package/dist/client/app/util/variant.ts +0 -20
  218. package/dist/client/index.ts +0 -12
  219. package/dist/client/shim.d.ts +0 -5
@@ -0,0 +1,278 @@
1
+ import { createRequire } from 'module';
2
+ import { relative, dirname } from 'pathe';
3
+ import { resolveConfig as resolveViteConfig } from 'vite';
4
+ import { lookup as lookupMime } from 'mrmime';
5
+ import { APP_PATH, DIST_PATH, TEMP_PATH } from './alias.js';
6
+ import { notifyStoryChange } from './stories.js';
7
+ import { makeTree } from './tree.js';
8
+ import { parseColor } from './colors.js';
9
+ import { createMarkdownRenderer } from './markdown.js';
10
+ import { generateSearchData } from './search.js';
11
+ const require = createRequire(import.meta.url);
12
+ export const STORIES_ID = '$histoire-stories';
13
+ export const RESOLVED_STORIES_ID = `/${STORIES_ID}-resolved`;
14
+ export const SETUP_ID = '$histoire-setup';
15
+ export const NOOP_ID = '/$histoire-noop';
16
+ export const CONFIG_ID = '$histoire-config';
17
+ export const RESOLVED_CONFIG_ID = `/${CONFIG_ID}-resolved`;
18
+ export const THEME_ID = '$histoire-theme';
19
+ export const RESOLVED_THEME_ID = `/${THEME_ID}-resolved.css`;
20
+ export const SEARCH_DATA_ID = '$histoire-search-data';
21
+ export const RESOLVED_SEARCH_DATA_ID = `/${SEARCH_DATA_ID}-resolved`;
22
+ export async function createVitePlugins(ctx) {
23
+ const viteConfig = await resolveViteConfig({}, ctx.mode === 'dev' ? 'serve' : 'build');
24
+ const hasVuePlugin = viteConfig.plugins.find(p => p.name === 'vite:vue');
25
+ const plugins = [];
26
+ if (!hasVuePlugin) {
27
+ plugins.push((await import('@vitejs/plugin-vue')).default());
28
+ }
29
+ if (ctx.config.vite) {
30
+ plugins.push({
31
+ name: 'histoire-vite-config-override',
32
+ config(config, env) {
33
+ return typeof ctx.config.vite === 'function' ? ctx.config.vite(config, env) : ctx.config.vite;
34
+ },
35
+ });
36
+ }
37
+ plugins.push({
38
+ name: 'histoire-vite-plugin',
39
+ config() {
40
+ return {
41
+ optimizeDeps: {
42
+ // force include vue to avoid duplicated copies when linked + optimized
43
+ include: [
44
+ 'vue',
45
+ dirname(require.resolve('@vue/runtime-core/package.json')),
46
+ dirname(require.resolve('shiki/package.json')),
47
+ dirname(require.resolve('vscode-textmate/package.json')),
48
+ dirname(require.resolve('vscode-oniguruma/package.json')),
49
+ dirname(require.resolve('case/package.json')),
50
+ ],
51
+ },
52
+ server: {
53
+ fs: {
54
+ allow: [DIST_PATH, TEMP_PATH, viteConfig.root, process.cwd()],
55
+ },
56
+ },
57
+ define: {
58
+ // We need to force this to be able to use `devtoolsRawSetupState`
59
+ __VUE_PROD_DEVTOOLS__: 'true',
60
+ },
61
+ };
62
+ },
63
+ async resolveId(id, importer) {
64
+ if (id.startsWith(STORIES_ID)) {
65
+ return RESOLVED_STORIES_ID;
66
+ }
67
+ if (id.startsWith(SETUP_ID)) {
68
+ if (ctx.config.setupFile) {
69
+ return this.resolve(ctx.config.setupFile, importer, {
70
+ skipSelf: true,
71
+ });
72
+ }
73
+ else {
74
+ return NOOP_ID;
75
+ }
76
+ }
77
+ if (id.startsWith(CONFIG_ID)) {
78
+ return RESOLVED_CONFIG_ID;
79
+ }
80
+ if (id.startsWith(THEME_ID)) {
81
+ return RESOLVED_THEME_ID;
82
+ }
83
+ if (id.startsWith(SEARCH_DATA_ID)) {
84
+ return RESOLVED_SEARCH_DATA_ID;
85
+ }
86
+ },
87
+ async load(id) {
88
+ if (id === RESOLVED_STORIES_ID) {
89
+ const resolvedStories = ctx.storyFiles.filter(s => !!s.story);
90
+ const files = resolvedStories.map((file, index) => {
91
+ return {
92
+ id: file.id,
93
+ path: file.treePath,
94
+ story: file.story,
95
+ framework: 'vue3',
96
+ index,
97
+ };
98
+ });
99
+ return `import { defineAsyncComponent } from 'vue'
100
+ ${resolvedStories.map((file, index) => `const Comp${index} = defineAsyncComponent(() => import('${file.path}'))`).join('\n')}
101
+ export let files = [${files.map((file) => `{${JSON.stringify(file).slice(1, -1)}, component: Comp${file.index}}`).join(',\n')}]
102
+ export let tree = ${JSON.stringify(makeTree(ctx.config, resolvedStories))}
103
+ const handlers = []
104
+ export function onUpdate (cb) {
105
+ handlers.push(cb)
106
+ }
107
+ if (import.meta.hot) {
108
+ import.meta.hot.accept(newModule => {
109
+ files = newModule.files
110
+ tree = newModule.tree
111
+ handlers.forEach(h => {
112
+ h(newModule.files, newModule.tree)
113
+ newModule.onUpdate(h)
114
+ })
115
+ })
116
+ }`;
117
+ }
118
+ if (id === NOOP_ID) {
119
+ return `export default () => {}`;
120
+ }
121
+ if (id === RESOLVED_CONFIG_ID) {
122
+ let js = `export const config = ${JSON.stringify(ctx.config)}\n`;
123
+ if (ctx.config.theme?.logo) {
124
+ for (const key in ctx.config.theme.logo) {
125
+ js += `import Logo_${key} from '${ctx.config.theme.logo[key]}'\n`;
126
+ }
127
+ }
128
+ js += `export const logos = {${Object.keys(ctx.config.theme?.logo ?? {}).map(key => `${key}: Logo_${key}`).join(', ')}}\n`;
129
+ return js;
130
+ }
131
+ if (id === RESOLVED_THEME_ID) {
132
+ let css = '*, ::before, ::after {';
133
+ // Colors
134
+ for (const color in ctx.config.theme?.colors ?? {}) {
135
+ for (const key in ctx.config.theme.colors[color]) {
136
+ css += `--_histoire-color-${color}-${key}: ${parseColor(ctx.config.theme.colors[color][key]).color.join(' ')};`;
137
+ }
138
+ }
139
+ css += '}';
140
+ return css;
141
+ }
142
+ if (id === RESOLVED_SEARCH_DATA_ID) {
143
+ return `export let searchData = ${JSON.stringify(await generateSearchData(ctx))}
144
+ const handlers = []
145
+ export function onUpdate (cb) {
146
+ handlers.push(cb)
147
+ }
148
+ if (import.meta.hot) {
149
+ import.meta.hot.accept(newModule => {
150
+ searchData = newModule.searchData
151
+ handlers.forEach(h => {
152
+ h(newModule.searchData)
153
+ newModule.onUpdate(h)
154
+ })
155
+ })
156
+ }`;
157
+ }
158
+ },
159
+ handleHotUpdate(updateContext) {
160
+ const story = ctx.storyFiles.find(file => file.path === updateContext.file);
161
+ if (story) {
162
+ notifyStoryChange(story);
163
+ }
164
+ },
165
+ configureServer(server) {
166
+ server.middlewares.use(async (req, res, next) => {
167
+ if (req.url.startsWith(`${server.config.base}__sandbox`)) {
168
+ res.statusCode = 200;
169
+ let html = `
170
+ <!DOCTYPE html>
171
+ <html>
172
+ <head>
173
+ <title></title>
174
+ <meta charset="utf-8">
175
+ <meta name="viewport" content="width=device-width,initial-scale=1">
176
+ <meta name="description" content="">
177
+ </head>
178
+ <body>
179
+ <div id="app"></div>
180
+ <script>
181
+ // Hide spammy vite messages
182
+ const origConsoleLog = console.log
183
+ console.log = (...args) => {
184
+ if (typeof args[0] !== 'string' || !args[0].startsWith('[vite] connect')) {
185
+ origConsoleLog(...args)
186
+ }
187
+ }
188
+ </script>
189
+ <script type="module" src="/@fs/${APP_PATH}/sandbox.js"></script>
190
+ </body>
191
+ </html>`;
192
+ // Apply Vite HTML transforms. This injects the Vite HMR client, and
193
+ // also applies HTML transforms from Vite plugins
194
+ html = await server.transformIndexHtml(req.url, html);
195
+ res.end(html);
196
+ return;
197
+ }
198
+ next();
199
+ });
200
+ // serve our index.html after vite history fallback
201
+ return () => {
202
+ server.middlewares.use(async (req, res, next) => {
203
+ if (req.url.endsWith('.html')) {
204
+ res.statusCode = 200;
205
+ let html = `
206
+ <!DOCTYPE html>
207
+ <html>
208
+ <head>
209
+ <title></title>
210
+ <link rel="icon" href=""/>
211
+ <meta charset="utf-8">
212
+ <meta name="viewport" content="width=device-width,initial-scale=1">
213
+ <meta name="description" content="">
214
+ ${ctx.config.theme?.favicon ? `<link rel="icon" type="${lookupMime(ctx.config.theme.favicon)}" href="${server.config.base}${ctx.config.theme.favicon}"/>` : ''}
215
+ </head>
216
+ <body>
217
+ <div id="app"></div>
218
+ <script type="module" src="/@fs/${APP_PATH}/index.js"></script>
219
+ </body>
220
+ </html>`;
221
+ // Apply Vite HTML transforms. This injects the Vite HMR client, and
222
+ // also applies HTML transforms from Vite plugins
223
+ html = await server.transformIndexHtml(req.url, html);
224
+ res.end(html);
225
+ return;
226
+ }
227
+ next();
228
+ });
229
+ };
230
+ },
231
+ });
232
+ // Custom blocks
233
+ plugins.push(...await createCustomBlocksPlugins(ctx));
234
+ if (ctx.mode === 'build') {
235
+ // Add file name in build mode to have components names instead of <Anonymous>
236
+ const include = [/\.vue$/];
237
+ const exclude = [/[\\/]node_modules[\\/]/, /[\\/]\.git[\\/]/, /[\\/]\.nuxt[\\/]/];
238
+ plugins.push({
239
+ name: 'histoire-file-name-plugin',
240
+ enforce: 'post',
241
+ transform(code, id) {
242
+ if (exclude.some(r => r.test(id)))
243
+ return;
244
+ if (include.some(r => r.test(id))) {
245
+ const file = relative(viteConfig.root, id);
246
+ const index = code.indexOf('export default');
247
+ const result = `${code.substring(0, index)}_sfc_main.__file = '${file}'\n${code.substring(index)}`;
248
+ return result;
249
+ }
250
+ },
251
+ });
252
+ }
253
+ return plugins;
254
+ }
255
+ async function createCustomBlocksPlugins(ctx) {
256
+ const plugins = [];
257
+ let md = await createMarkdownRenderer();
258
+ if (ctx.config.markdown) {
259
+ const result = await ctx.config.markdown(md);
260
+ if (result) {
261
+ md = result;
262
+ }
263
+ }
264
+ plugins.push({
265
+ name: 'histoire-vue-docs-block',
266
+ transform(code, id) {
267
+ if (!id.includes('?vue&type=docs'))
268
+ return;
269
+ if (!id.includes('lang.md'))
270
+ return;
271
+ const html = md.render(code);
272
+ return `export default Comp => {
273
+ Comp.doc = ${JSON.stringify(html)}
274
+ }`;
275
+ },
276
+ });
277
+ return plugins;
278
+ }