poveste 0.6.0 → 0.7.0

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 (220) hide show
  1. package/dist/controls.d.ts +0 -1
  2. package/dist/node/alias.d.ts +0 -1
  3. package/dist/node/bin.d.ts +0 -1
  4. package/dist/node/build-serialize.d.ts +0 -1
  5. package/dist/node/build.d.ts +0 -1
  6. package/dist/node/builtin-plugins/pinceau-tokens.d.ts +0 -1
  7. package/dist/node/builtin-plugins/vanilla-support/MountStory.d.ts +0 -1
  8. package/dist/node/builtin-plugins/vanilla-support/RenderStory.d.ts +0 -1
  9. package/dist/node/builtin-plugins/vanilla-support/client.d.ts +0 -1
  10. package/dist/node/builtin-plugins/vanilla-support/collect.d.ts +0 -1
  11. package/dist/node/builtin-plugins/vanilla-support/plugin.d.ts +0 -1
  12. package/dist/node/builtin-plugins/vanilla-support/types.d.ts +0 -1
  13. package/dist/node/builtin-plugins/vanilla-support/vanilla.story.d.ts +0 -1
  14. package/dist/node/collect/index.d.ts +0 -1
  15. package/dist/node/collect/run.d.ts +0 -1
  16. package/dist/node/collect/worker.d.ts +0 -1
  17. package/dist/node/colors.d.ts +0 -1
  18. package/dist/node/commands/build.d.ts +0 -1
  19. package/dist/node/commands/dev.d.ts +0 -1
  20. package/dist/node/commands/port.d.ts +0 -1
  21. package/dist/node/commands/preview.d.ts +0 -1
  22. package/dist/node/config.d.ts +0 -1
  23. package/dist/node/context.d.ts +0 -1
  24. package/dist/node/dom/dom-keys.d.ts +0 -1
  25. package/dist/node/dom/env.d.ts +0 -1
  26. package/dist/node/dom/util.d.ts +0 -1
  27. package/dist/node/index.d.ts +0 -1
  28. package/dist/node/load.d.ts +0 -1
  29. package/dist/node/markdown.d.ts +0 -1
  30. package/dist/node/plugin.d.ts +0 -1
  31. package/dist/node/preview.d.ts +0 -1
  32. package/dist/node/search.d.ts +0 -1
  33. package/dist/node/server.d.ts +0 -1
  34. package/dist/node/stories.d.ts +0 -1
  35. package/dist/node/style-isolation/entry-css-merger.d.ts +0 -1
  36. package/dist/node/style-isolation/global-styles.d.ts +0 -1
  37. package/dist/node/style-isolation/index.d.ts +0 -1
  38. package/dist/node/style-isolation/scope-chrome.d.ts +0 -1
  39. package/dist/node/style-isolation/selectors.d.ts +0 -1
  40. package/dist/node/style-isolation/transforms.d.ts +0 -1
  41. package/dist/node/style-isolation/vite-plugin.d.ts +0 -1
  42. package/dist/node/tree.d.ts +0 -1
  43. package/dist/node/util/find-up.d.ts +0 -1
  44. package/dist/node/util/fs.d.ts +0 -1
  45. package/dist/node/util/head.d.ts +0 -1
  46. package/dist/node/util/log.d.ts +0 -1
  47. package/dist/node/util/slugify.d.ts +0 -1
  48. package/dist/node/util/vendors.d.ts +0 -1
  49. package/dist/node/util/watch-ignore.d.ts +0 -1
  50. package/dist/node/vendors/controls.d.ts +0 -1
  51. package/dist/node/vendors/vue.d.ts +0 -1
  52. package/dist/node/virtual/index.d.ts +0 -1
  53. package/dist/node/virtual/markdown.d.ts +0 -1
  54. package/dist/node/virtual/noop.d.ts +0 -1
  55. package/dist/node/virtual/resolved-commands.d.ts +0 -1
  56. package/dist/node/virtual/resolved-config.d.ts +0 -1
  57. package/dist/node/virtual/resolved-generated-global-setup.d.ts +0 -1
  58. package/dist/node/virtual/resolved-generated-setup-code.d.ts +0 -1
  59. package/dist/node/virtual/resolved-markdown-files.d.ts +0 -1
  60. package/dist/node/virtual/resolved-stories.d.ts +0 -1
  61. package/dist/node/virtual/resolved-support-plugins-client.d.ts +0 -1
  62. package/dist/node/virtual/resolved-support-plugins-collect.d.ts +0 -1
  63. package/dist/node/virtual/resolved-theme.d.ts +0 -1
  64. package/dist/node/virtual/story-source.d.ts +0 -1
  65. package/dist/node/virtual/story.d.ts +0 -1
  66. package/dist/node/virtual/util.d.ts +0 -1
  67. package/dist/node/virtual/vite-plugin.d.ts +0 -1
  68. package/dist/node/vite.d.ts +0 -1
  69. package/package.json +36 -6
  70. package/dist/controls.d.ts.map +0 -1
  71. package/dist/node/alias.d.ts.map +0 -1
  72. package/dist/node/bin.d.ts.map +0 -1
  73. package/dist/node/build-serialize.d.ts.map +0 -1
  74. package/dist/node/build.d.ts.map +0 -1
  75. package/dist/node/builtin-plugins/pinceau-tokens.d.ts.map +0 -1
  76. package/dist/node/builtin-plugins/vanilla-support/MountStory.d.ts.map +0 -1
  77. package/dist/node/builtin-plugins/vanilla-support/RenderStory.d.ts.map +0 -1
  78. package/dist/node/builtin-plugins/vanilla-support/client.d.ts.map +0 -1
  79. package/dist/node/builtin-plugins/vanilla-support/collect.d.ts.map +0 -1
  80. package/dist/node/builtin-plugins/vanilla-support/plugin.d.ts.map +0 -1
  81. package/dist/node/builtin-plugins/vanilla-support/types.d.ts.map +0 -1
  82. package/dist/node/builtin-plugins/vanilla-support/vanilla.story.d.ts.map +0 -1
  83. package/dist/node/collect/index.d.ts.map +0 -1
  84. package/dist/node/collect/run.d.ts.map +0 -1
  85. package/dist/node/collect/worker.d.ts.map +0 -1
  86. package/dist/node/colors.d.ts.map +0 -1
  87. package/dist/node/commands/build.d.ts.map +0 -1
  88. package/dist/node/commands/dev.d.ts.map +0 -1
  89. package/dist/node/commands/port.d.ts.map +0 -1
  90. package/dist/node/commands/preview.d.ts.map +0 -1
  91. package/dist/node/config.d.ts.map +0 -1
  92. package/dist/node/context.d.ts.map +0 -1
  93. package/dist/node/dom/dom-keys.d.ts.map +0 -1
  94. package/dist/node/dom/env.d.ts.map +0 -1
  95. package/dist/node/dom/util.d.ts.map +0 -1
  96. package/dist/node/index.d.ts.map +0 -1
  97. package/dist/node/load.d.ts.map +0 -1
  98. package/dist/node/markdown.d.ts.map +0 -1
  99. package/dist/node/plugin.d.ts.map +0 -1
  100. package/dist/node/preview.d.ts.map +0 -1
  101. package/dist/node/search.d.ts.map +0 -1
  102. package/dist/node/server.d.ts.map +0 -1
  103. package/dist/node/stories.d.ts.map +0 -1
  104. package/dist/node/style-isolation/entry-css-merger.d.ts.map +0 -1
  105. package/dist/node/style-isolation/global-styles.d.ts.map +0 -1
  106. package/dist/node/style-isolation/index.d.ts.map +0 -1
  107. package/dist/node/style-isolation/scope-chrome.d.ts.map +0 -1
  108. package/dist/node/style-isolation/selectors.d.ts.map +0 -1
  109. package/dist/node/style-isolation/transforms.d.ts.map +0 -1
  110. package/dist/node/style-isolation/vite-plugin.d.ts.map +0 -1
  111. package/dist/node/tree.d.ts.map +0 -1
  112. package/dist/node/util/find-up.d.ts.map +0 -1
  113. package/dist/node/util/fs.d.ts.map +0 -1
  114. package/dist/node/util/head.d.ts.map +0 -1
  115. package/dist/node/util/log.d.ts.map +0 -1
  116. package/dist/node/util/slugify.d.ts.map +0 -1
  117. package/dist/node/util/vendors.d.ts.map +0 -1
  118. package/dist/node/util/watch-ignore.d.ts.map +0 -1
  119. package/dist/node/vendors/controls.d.ts.map +0 -1
  120. package/dist/node/vendors/vue.d.ts.map +0 -1
  121. package/dist/node/virtual/index.d.ts.map +0 -1
  122. package/dist/node/virtual/markdown.d.ts.map +0 -1
  123. package/dist/node/virtual/noop.d.ts.map +0 -1
  124. package/dist/node/virtual/resolved-commands.d.ts.map +0 -1
  125. package/dist/node/virtual/resolved-config.d.ts.map +0 -1
  126. package/dist/node/virtual/resolved-generated-global-setup.d.ts.map +0 -1
  127. package/dist/node/virtual/resolved-generated-setup-code.d.ts.map +0 -1
  128. package/dist/node/virtual/resolved-markdown-files.d.ts.map +0 -1
  129. package/dist/node/virtual/resolved-stories.d.ts.map +0 -1
  130. package/dist/node/virtual/resolved-support-plugins-client.d.ts.map +0 -1
  131. package/dist/node/virtual/resolved-support-plugins-collect.d.ts.map +0 -1
  132. package/dist/node/virtual/resolved-theme.d.ts.map +0 -1
  133. package/dist/node/virtual/story-source.d.ts.map +0 -1
  134. package/dist/node/virtual/story.d.ts.map +0 -1
  135. package/dist/node/virtual/util.d.ts.map +0 -1
  136. package/dist/node/virtual/vite-plugin.d.ts.map +0 -1
  137. package/dist/node/vite.d.ts.map +0 -1
  138. package/src/controls.ts +0 -1
  139. package/src/node/__tests__/config.spec.ts +0 -25
  140. package/src/node/__tests__/dom-env.spec.ts +0 -97
  141. package/src/node/__tests__/head.spec.ts +0 -32
  142. package/src/node/__tests__/markdown/test1.story.md +0 -7
  143. package/src/node/__tests__/markdown/test2.story.md +0 -5
  144. package/src/node/__tests__/markdown.spec.ts +0 -61
  145. package/src/node/__tests__/port.spec.ts +0 -65
  146. package/src/node/__tests__/tree.spec.ts +0 -109
  147. package/src/node/__tests__/virtual-setup.spec.ts +0 -61
  148. package/src/node/__tests__/watch-ignore.spec.ts +0 -33
  149. package/src/node/alias.ts +0 -8
  150. package/src/node/bin.ts +0 -46
  151. package/src/node/build-serialize.ts +0 -62
  152. package/src/node/build.ts +0 -339
  153. package/src/node/builtin-plugins/pinceau-tokens.ts +0 -523
  154. package/src/node/builtin-plugins/vanilla-support/MountStory.ts +0 -49
  155. package/src/node/builtin-plugins/vanilla-support/RenderStory.ts +0 -167
  156. package/src/node/builtin-plugins/vanilla-support/client.ts +0 -6
  157. package/src/node/builtin-plugins/vanilla-support/collect.ts +0 -43
  158. package/src/node/builtin-plugins/vanilla-support/plugin.ts +0 -35
  159. package/src/node/builtin-plugins/vanilla-support/types.ts +0 -42
  160. package/src/node/builtin-plugins/vanilla-support/vanilla.story.ts +0 -63
  161. package/src/node/collect/index.ts +0 -164
  162. package/src/node/collect/run.ts +0 -9
  163. package/src/node/collect/worker.ts +0 -103
  164. package/src/node/colors.ts +0 -340
  165. package/src/node/commands/build.ts +0 -14
  166. package/src/node/commands/dev.ts +0 -70
  167. package/src/node/commands/port.ts +0 -41
  168. package/src/node/commands/preview.ts +0 -30
  169. package/src/node/config.ts +0 -396
  170. package/src/node/context.ts +0 -60
  171. package/src/node/dom/dom-keys.ts +0 -238
  172. package/src/node/dom/env.ts +0 -123
  173. package/src/node/dom/util.ts +0 -83
  174. package/src/node/index.ts +0 -7
  175. package/src/node/load.ts +0 -59
  176. package/src/node/markdown.ts +0 -280
  177. package/src/node/plugin.ts +0 -95
  178. package/src/node/preview.ts +0 -45
  179. package/src/node/search.ts +0 -84
  180. package/src/node/server.ts +0 -258
  181. package/src/node/stories.ts +0 -145
  182. package/src/node/style-isolation/__tests__/entry-css-merger.spec.ts +0 -145
  183. package/src/node/style-isolation/__tests__/transforms.spec.ts +0 -200
  184. package/src/node/style-isolation/__tests__/vite-plugin.spec.ts +0 -39
  185. package/src/node/style-isolation/entry-css-merger.ts +0 -134
  186. package/src/node/style-isolation/global-styles.ts +0 -37
  187. package/src/node/style-isolation/index.ts +0 -5
  188. package/src/node/style-isolation/scope-chrome.ts +0 -42
  189. package/src/node/style-isolation/selectors.ts +0 -19
  190. package/src/node/style-isolation/transforms.ts +0 -163
  191. package/src/node/style-isolation/vite-plugin.ts +0 -75
  192. package/src/node/tree.ts +0 -158
  193. package/src/node/util/find-up.ts +0 -24
  194. package/src/node/util/fs.ts +0 -1
  195. package/src/node/util/head.ts +0 -12
  196. package/src/node/util/log.ts +0 -10
  197. package/src/node/util/slugify.ts +0 -26
  198. package/src/node/util/vendors.ts +0 -27
  199. package/src/node/util/watch-ignore.ts +0 -13
  200. package/src/node/vendors/controls.ts +0 -1
  201. package/src/node/vendors/vue.ts +0 -1
  202. package/src/node/virtual/index.ts +0 -50
  203. package/src/node/virtual/markdown.ts +0 -21
  204. package/src/node/virtual/noop.ts +0 -9
  205. package/src/node/virtual/resolved-commands.ts +0 -42
  206. package/src/node/virtual/resolved-config.ts +0 -12
  207. package/src/node/virtual/resolved-generated-global-setup.ts +0 -33
  208. package/src/node/virtual/resolved-generated-setup-code.ts +0 -7
  209. package/src/node/virtual/resolved-markdown-files.ts +0 -19
  210. package/src/node/virtual/resolved-stories.ts +0 -44
  211. package/src/node/virtual/resolved-support-plugins-client.ts +0 -14
  212. package/src/node/virtual/resolved-support-plugins-collect.ts +0 -14
  213. package/src/node/virtual/resolved-theme.ts +0 -14
  214. package/src/node/virtual/story-source.ts +0 -18
  215. package/src/node/virtual/story.ts +0 -9
  216. package/src/node/virtual/util.ts +0 -41
  217. package/src/node/virtual/vite-plugin.ts +0 -146
  218. package/src/node/vite.ts +0 -438
  219. package/tsconfig.json +0 -44
  220. package/vitest.config.ts +0 -10
@@ -1,33 +0,0 @@
1
- import type { Stats } from 'node:fs'
2
- import { describe, expect, it } from 'vitest'
3
- import { createWatchIgnore } from '../util/watch-ignore.js'
4
-
5
- const file = { isFile: () => true } as Stats
6
- const dir = { isFile: () => false } as Stats
7
-
8
- describe('createWatchIgnore', () => {
9
- const root = '/repo/.claude/worktrees/feature/examples/vue3'
10
- const ignored = createWatchIgnore(['**/node_modules/**', '**/dist/**'], ['**/*.story.md'])
11
-
12
- it('ignores storyIgnored paths when the root sits under a dot directory', () => {
13
- expect(ignored(`${root}/node_modules/foo/index.js`, file)).toBe(true)
14
- expect(ignored(`${root}/node_modules/.pnpm/foo/node_modules/bar`, dir)).toBe(true)
15
- expect(ignored(`${root}/dist/index.html`, file)).toBe(true)
16
- })
17
-
18
- it('keeps included files when the root sits under a dot directory', () => {
19
- expect(ignored(`${root}/src/Button.story.md`, file)).toBe(false)
20
- })
21
-
22
- it('traverses directories and skips other files', () => {
23
- expect(ignored(`${root}/src`, dir)).toBe(false)
24
- expect(ignored(`${root}/src/Button.vue`, file)).toBe(true)
25
- expect(ignored(`${root}/src/Button.vue`)).toBe(false)
26
- })
27
-
28
- it('matches patterns resolved to absolute paths', () => {
29
- const resolved = createWatchIgnore([`${root}/**/node_modules/**`], [`${root}/**/*.story.vue`])
30
- expect(resolved(`${root}/node_modules/.pnpm/foo/node_modules/bar/index.js`, file)).toBe(true)
31
- expect(resolved(`${root}/src/Button.story.vue`, file)).toBe(false)
32
- })
33
- })
package/src/node/alias.ts DELETED
@@ -1,8 +0,0 @@
1
- import { createRequire } from 'node:module'
2
- import path from 'pathe'
3
-
4
- const require = createRequire(import.meta.url)
5
-
6
- export const APP_PATH = path.join(path.dirname(require.resolve('@poveste/app/package.json')), process.env.POVESTE_DEV ? 'src' : 'dist')
7
-
8
- export const TEMP_PATH = path.join(process.cwd(), 'node_modules', '.poveste')
package/src/node/bin.ts DELETED
@@ -1,46 +0,0 @@
1
- import fs from 'node:fs'
2
- import { fileURLToPath } from 'node:url'
3
- import { dirname, resolve } from 'pathe'
4
- import sade from 'sade'
5
-
6
- const __dirname = dirname(fileURLToPath(import.meta.url))
7
-
8
- const { version } = JSON.parse(fs.readFileSync(resolve(__dirname, '../../package.json'), 'utf8'))
9
-
10
- process.env.NODE_ENV = process.argv.includes('build') || process.argv.includes('preview') ? 'production' : 'development'
11
- process.env.HISTOIRE = 'true'
12
- process.env.POVESTE = 'true'
13
-
14
- const program = sade('poveste')
15
- program.version(version)
16
-
17
- program.command('dev')
18
- .describe('open the stories in your browser for development')
19
- .option('-p, --port <port>', 'Listening port of the server')
20
- .option('-c, --config <file>', `[string] use specified config file`)
21
- .option('--open', 'Open in your default browser')
22
- .option('--host [host]', '[string] specify hostname (omit value or pass `0.0.0.0` to expose to all network interfaces)')
23
- .action(async (options) => {
24
- const { devCommand } = await import('./commands/dev.js')
25
- return devCommand(options)
26
- })
27
-
28
- program.command('build')
29
- .describe('build the poveste final app you can deploy')
30
- .option('-c, --config <file>', `[string] use specified config file`)
31
- .action(async (options) => {
32
- const { buildCommand } = await import('./commands/build.js')
33
- return buildCommand(options)
34
- })
35
-
36
- program.command('preview')
37
- .describe('preview the built directory')
38
- .option('-p, --port <port>', 'Listening port of the server')
39
- .option('--open', 'Open in your default browser')
40
- .option('--host [host]', '[string] specify hostname (omit value or pass `0.0.0.0` to expose to all network interfaces)')
41
- .action(async (options) => {
42
- const { previewCommand } = await import('./commands/preview.js')
43
- return previewCommand(options)
44
- })
45
-
46
- program.parse(process.argv)
@@ -1,62 +0,0 @@
1
- import type { ServerStory } from '@poveste/shared'
2
- import type { Context } from './context.js'
3
-
4
- interface SerializedStory extends Omit<ServerStory, 'docsText'> {
5
- relativePath: string
6
- supportPluginId: string
7
- treePath?: string[]
8
- virtual?: boolean
9
- markdownFile?: SerializedMarkdownFile
10
- }
11
-
12
- interface SerializedMarkdownFile {
13
- id: string
14
- relativePath: string
15
- isRelatedToStory: boolean
16
- frontmatter?: any
17
- }
18
-
19
- interface SerializedStoryData {
20
- stories: SerializedStory[]
21
- markdownFiles: SerializedMarkdownFile[]
22
- }
23
-
24
- export function getSerializedStoryData(ctx: Context): SerializedStoryData {
25
- const data: SerializedStoryData = {
26
- stories: [],
27
- markdownFiles: [],
28
- }
29
-
30
- for (const storyFile of ctx.storyFiles) {
31
- if (storyFile.story) {
32
- data.stories.push({
33
- ...Object.assign({}, storyFile.story, {
34
- docsText: undefined,
35
- }),
36
- relativePath: storyFile.relativePath,
37
- supportPluginId: storyFile.supportPluginId,
38
- treePath: storyFile.treePath,
39
- virtual: storyFile.virtual,
40
- markdownFile: storyFile.markdownFile
41
- ? {
42
- id: storyFile.markdownFile.id,
43
- relativePath: storyFile.markdownFile.relativePath,
44
- isRelatedToStory: storyFile.markdownFile.isRelatedToStory,
45
- frontmatter: storyFile.markdownFile.frontmatter,
46
- }
47
- : null,
48
- })
49
- }
50
- }
51
-
52
- for (const markdownFile of ctx.markdownFiles) {
53
- data.markdownFiles.push({
54
- id: markdownFile.id,
55
- relativePath: markdownFile.relativePath,
56
- isRelatedToStory: markdownFile.isRelatedToStory,
57
- frontmatter: markdownFile.frontmatter,
58
- })
59
- }
60
-
61
- return data
62
- }
package/src/node/build.ts DELETED
@@ -1,339 +0,0 @@
1
- import type {
2
- BuildEndCallback,
3
- ChangeViteConfigCallback,
4
- PreviewStoryCallback,
5
- } from '@poveste/shared'
6
- import type {
7
- Rolldown,
8
- InlineConfig as ViteInlineConfig,
9
- Plugin as VitePlugin,
10
- } from 'vite'
11
- import type { Context } from './context.js'
12
- import { performance } from 'node:perf_hooks'
13
- import fs from 'fs-extra'
14
- import { lookup as lookupMime } from 'mrmime'
15
- import { join } from 'pathe'
16
- import pc from 'picocolors'
17
- import {
18
- createServer as createViteServer,
19
- mergeConfig as mergeViteConfig,
20
- build as viteBuild,
21
- } from 'vite'
22
- import { APP_PATH } from './alias.js'
23
- import { getSerializedStoryData } from './build-serialize.js'
24
- import { useCollectStories } from './collect/index.js'
25
- import { useModuleLoader } from './load.js'
26
- import { createMarkdownFilesWatcher } from './markdown.js'
27
- import { BuildPluginApi } from './plugin.js'
28
- import { startPreview } from './preview.js'
29
- import { findAllStories } from './stories.js'
30
- import {
31
- chromeCssScopePlugin,
32
- entryCssMergerPlugin,
33
- userCssScopePlugin,
34
- } from './style-isolation/index.js'
35
- import { applyHeadTransform } from './util/head.js'
36
- import { getViteConfigWithPlugins } from './vite.js'
37
-
38
- const PRELOAD_MODULES = [
39
- 'vendor',
40
- ]
41
-
42
- // Kept out of the shared `vendor` chunk because only the app UI imports them,
43
- // while `vendor` is imported by the sandbox too.
44
- //
45
- // Shiki is the source panel's syntax highlighter: 386 grammars and 60 themes,
46
- // and it was the bulk of an 11.5 MB `vendor`. The sandbox entry pulls seven Vue
47
- // exports from that chunk and nothing else, but a grid renders one sandbox
48
- // iframe per cell and each iframe is its own realm — so every cell parsed and
49
- // executed all 11.5 MB again, with the HTTP cache saving only the download.
50
- // That was 34% of a scroll profile spent in top-level vendor evaluation (#103).
51
- //
52
- // They go to a chunk of their own rather than being left to Rollup: leaving
53
- // placement automatic emitted one chunk per grammar — 402 assets — and tripled
54
- // the blocking time it was meant to cut.
55
- const APP_ONLY_VENDORS = [
56
- /[\\/]node_modules[\\/]shiki[\\/]/,
57
- /[\\/]node_modules[\\/]@shikijs[\\/]/,
58
- ]
59
-
60
- const PREFETCHED_MODULES = [
61
- 'StoryView',
62
- 'reactivity',
63
- 'global-components',
64
- ]
65
-
66
- export async function build(ctx: Context) {
67
- const startTime = performance.now()
68
- await findAllStories(ctx)
69
-
70
- // Scan for markdown files
71
- {
72
- const { stop } = await createMarkdownFilesWatcher(ctx)
73
- await stop()
74
- }
75
-
76
- const { viteConfig } = await getViteConfigWithPlugins(true, ctx)
77
- const server = await createViteServer(
78
- mergeViteConfig(viteConfig, {
79
- optimizeDeps: { include: [], noDiscovery: true },
80
- }),
81
- )
82
- await server.pluginContainer.buildStart({})
83
-
84
- const moduleLoader = useModuleLoader({
85
- server,
86
- throws: true,
87
- })
88
- const changeViteConfigCallbacks: ChangeViteConfigCallback[] = []
89
- const buildEndCallbacks: BuildEndCallback[] = []
90
- const previewStoryCallbacks: PreviewStoryCallback[] = []
91
- for (const plugin of ctx.config.plugins) {
92
- if (plugin.onBuild) {
93
- const api = new BuildPluginApi(ctx, plugin, moduleLoader)
94
- await plugin.onBuild(api)
95
- changeViteConfigCallbacks.push(...api.changeViteConfigCallbacks)
96
- buildEndCallbacks.push(...api.buildEndCallbacks)
97
- previewStoryCallbacks.push(...api.previewStoryCallbacks)
98
- }
99
- }
100
-
101
- // Collect story data
102
- const { executeStoryFile, destroy: destroyCollectStories } = useCollectStories({
103
- server,
104
- throws: true,
105
- }, ctx)
106
- await Promise.all(ctx.storyFiles.map(storyFile => executeStoryFile(storyFile)))
107
- await destroyCollectStories()
108
-
109
- const storyCount = ctx.storyFiles.reduce((sum, file) => sum + (file.story?.variants.length ? 1 : 0), 0)
110
- const variantCount = ctx.storyFiles.reduce((sum, file) => sum + (file.story?.variants.length ?? 0), 0)
111
- const emptyStoryCount = ctx.storyFiles.length - storyCount
112
-
113
- const { viteConfig: buildViteConfigRaw } = await getViteConfigWithPlugins(false, ctx)
114
- const buildViteConfig: ViteInlineConfig = mergeViteConfig(buildViteConfigRaw, {
115
- mode: 'development',
116
- build: {
117
- lib: false,
118
- rollupOptions: {
119
- input: [
120
- join(APP_PATH, 'bundle-main.js'),
121
- join(APP_PATH, 'bundle-sandbox.js'),
122
- ],
123
- plugins: [
124
- {
125
- name: 'poveste-build-rollup-options-override',
126
- enforce: 'post',
127
- options(options) {
128
- // Don't externalize
129
- options.external = []
130
- },
131
- },
132
- ],
133
- },
134
- },
135
- })
136
-
137
- // For @vite/plugin-vue: Always put our vite server
138
- // Disable template inlining
139
- // (so that we no longer need defineExpose)
140
- // Nuxt: replaces the Nuxt vite dev server
141
- buildViteConfig.plugins.push({
142
- name: 'poveste-vue-plugin-override',
143
- config(config) {
144
- const vuePlugin = config.plugins.find((p: any) => p.name === 'vite:vue') as VitePlugin
145
- if (vuePlugin) {
146
- // @ts-expect-error vue plugin use function form
147
- const original = vuePlugin.configureServer.bind(vuePlugin)
148
- vuePlugin.configureServer = () => {
149
- original({
150
- ...server,
151
- config: {
152
- ...server.config,
153
- server: {
154
- ...server.config.server,
155
- hmr: false,
156
- },
157
- },
158
- })
159
- }
160
- // @ts-expect-error vue plugin use function form
161
- vuePlugin.configureServer(server)
162
- }
163
- },
164
- })
165
-
166
- buildViteConfig.plugins.push({
167
- name: 'poveste-build-config-override',
168
- enforce: 'post',
169
- config(config) {
170
- // Don't externalize
171
- config.build.rollupOptions.external = []
172
-
173
- // Force chunk strategy
174
- config.build.rollupOptions.output = {
175
- manualChunks(id) {
176
- // Vite's runtime helpers (`\0vite/preload-helper.js` and friends) are
177
- // virtual modules, so the node_modules routing below never sees them
178
- // and their placement is left to the bundler — which parked
179
- // `__vitePreload` inside the 10 MB `highlighter` chunk. Every chunk
180
- // importing the helper then statically imported the whole highlighter,
181
- // and the sandbox was back to evaluating it once per grid cell (#197),
182
- // undoing exactly what `APP_ONLY_VENDORS` is for. Pin them somewhere
183
- // harmless instead of leaving the choice to chunking heuristics.
184
- if (id.replace(/^\0/, '').startsWith('vite/')) {
185
- return 'app-runtime'
186
- }
187
-
188
- if (!id.includes('@poveste/app') && id.includes('node_modules')) {
189
- if (APP_ONLY_VENDORS.some(test => test.test(id))) {
190
- return 'highlighter'
191
- }
192
-
193
- for (const test of ctx.config.build?.excludeFromVendorsChunk ?? []) {
194
- if ((
195
- typeof test === 'string' && id.includes(test)
196
- ) || (
197
- test instanceof RegExp && test.test(id)
198
- )) {
199
- // Excluded from vendor chunk
200
- return
201
- }
202
- }
203
- return 'vendor'
204
- }
205
- },
206
- }
207
-
208
- // Force vite build options
209
- Object.assign(config.build, {
210
- outDir: ctx.config.outDir,
211
- emptyOutDir: true,
212
- // Re-merged per-entry by entry-css-merger.
213
- cssCodeSplit: true,
214
- minify: false,
215
- // Don't build in SSR mode
216
- ssr: false,
217
- })
218
-
219
- config.define.__HST_COLLECT__ = false
220
- },
221
- })
222
-
223
- const isolate = ctx.config.isolateStyles !== false
224
- buildViteConfig.plugins.push(userCssScopePlugin({ enabled: isolate }))
225
- buildViteConfig.plugins.push(chromeCssScopePlugin({ enabled: isolate }))
226
- buildViteConfig.plugins.push(entryCssMergerPlugin({ isolateStyles: isolate }))
227
-
228
- for (const cb of changeViteConfigCallbacks) {
229
- console.log('vite config hook', cb)
230
- await cb(buildViteConfig)
231
- }
232
-
233
- const results = await viteBuild(buildViteConfig)
234
- const result = Array.isArray(results) ? results[0] : results as Rolldown.RolldownOutput
235
-
236
- function findEntryCss(entryName: string) {
237
- return result.output.find(
238
- o => o.type === 'asset' && o.fileName === `${entryName}.css`,
239
- )
240
- }
241
- const mainStyleOutput = findEntryCss('bundle-main')
242
- ?? result.output.find(o => o.name === 'style.css' && o.type === 'asset')
243
- const sandboxStyleOutput = findEntryCss('bundle-sandbox') ?? mainStyleOutput
244
-
245
- // Preload
246
- const preloadOutputs = result.output.filter(o => PRELOAD_MODULES.includes(o.name) && o.type === 'chunk')
247
- const preloadHtml = generateScriptLinks(preloadOutputs.map(o => o.fileName), 'preload', ctx)
248
-
249
- // Prefetch
250
- const prefetchOutputs = result.output.filter(o => PREFETCHED_MODULES.includes(o.name) && o.type === 'chunk')
251
- const prefetchHtml = generateScriptLinks(prefetchOutputs.map(o => o.fileName), 'prefetch', ctx)
252
-
253
- // Index
254
- const indexOutput = result.output.find(o => o.name === 'bundle-main' && o.type === 'chunk')
255
- let indexHtml = generateEntryHtml(indexOutput.fileName, mainStyleOutput.fileName, {
256
- HEAD: `${preloadHtml}${prefetchHtml}`,
257
- }, ctx)
258
- indexHtml = await applyHeadTransform(indexHtml, ctx.config.head)
259
- await writeFile('index.html', indexHtml, ctx)
260
-
261
- // Sandbox
262
- const sandboxOutput = result.output.find(o => o.name === 'bundle-sandbox' && o.type === 'chunk')
263
- let sandboxHtml = generateEntryHtml(sandboxOutput.fileName, sandboxStyleOutput.fileName, {}, ctx)
264
- sandboxHtml = await applyHeadTransform(sandboxHtml, ctx.config.head)
265
- await writeFile('__sandbox.html', sandboxHtml, ctx)
266
-
267
- await writeFile('poveste.json', JSON.stringify(getSerializedStoryData(ctx), null, 2), ctx)
268
-
269
- const duration = performance.now() - startTime
270
- if (emptyStoryCount) {
271
- console.warn(pc.yellow(`⚠️ ${emptyStoryCount} empty story file${emptyStoryCount === 1 ? '' : 's'}`))
272
- }
273
- console.log(pc.green(`✅ Built ${storyCount} stor${storyCount === 1 ? 'y' : 'ies'} (${variantCount} variant${variantCount === 1 ? '' : 's'}) in ${Math.round(duration / 1000 * 100) / 100}s`))
274
-
275
- // Render
276
- if (previewStoryCallbacks.length) {
277
- const { baseUrl, close } = await startPreview({}, ctx)
278
- for (const storyFile of ctx.storyFiles) {
279
- const story = storyFile.story
280
- for (const variant of story.variants) {
281
- const query = new URLSearchParams()
282
- query.append('storyId', story.id)
283
- query.append('variantId', variant.id)
284
- const url = `${baseUrl}__sandbox.html?${query.toString()}`
285
- for (const fn of previewStoryCallbacks) {
286
- await fn({
287
- file: storyFile.path,
288
- story,
289
- variant,
290
- url,
291
- })
292
- }
293
- }
294
- }
295
- await close()
296
- }
297
-
298
- await server.close()
299
-
300
- for (const fn of buildEndCallbacks) {
301
- await fn()
302
- }
303
- }
304
-
305
- function generateBaseHtml(head: string, body: string, ctx: Context) {
306
- return `<!DOCTYPE html>
307
- <html>
308
- <head>
309
- <title>${ctx.config.theme.title}</title>
310
- <meta charset="utf-8">
311
- <meta name="viewport" content="width=device-width,initial-scale=1">
312
- <meta name="description" content="">
313
- <style>html,body{margin:0;padding:0}</style>
314
- ${head}
315
- </head>
316
- <body>
317
- ${body}
318
- </body>
319
- </html>`
320
- }
321
-
322
- function generateEntryHtml(jsEntryFile: string, cssEntryFile: string, variables: { HEAD?: string }, ctx: Context) {
323
- return generateBaseHtml(
324
- `<link rel="stylesheet" href="${ctx.resolvedViteConfig.base}${cssEntryFile}">
325
- ${ctx.config.theme?.favicon ? `<link rel="icon" type="${lookupMime(ctx.config.theme.favicon)}" href="${ctx.resolvedViteConfig.base}${ctx.config.theme.favicon}"/>` : ''}
326
- ${variables.HEAD ?? ''}`,
327
- `<div id="app"></div>
328
- <script type="module" src="${ctx.resolvedViteConfig.base}${jsEntryFile}"></script>`,
329
- ctx,
330
- )
331
- }
332
-
333
- async function writeFile(fileName: string, content: string, ctx: Context) {
334
- await fs.writeFile(join(ctx.config.outDir, fileName), content, 'utf8')
335
- }
336
-
337
- function generateScriptLinks(prefetchScripts: string[], rel: string, ctx: Context) {
338
- return prefetchScripts.map(s => `<link rel="${rel}" href="${ctx.resolvedViteConfig.base}${s}" as="script" crossOrigin="anonymous">`).join('')
339
- }