histoire 0.5.3 → 0.6.1

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.
@@ -1495,7 +1495,7 @@ const _sfc_main$c = /* @__PURE__ */ defineComponent({
1495
1495
  key: 0,
1496
1496
  modelValue: unref(model),
1497
1497
  "onUpdate:modelValue": _cache[1] || (_cache[1] = ($event) => isRef(model) ? model.value = $event : null),
1498
- title: __props.definition.name,
1498
+ title: `${__props.definition.name}${unref(canReset) ? " *" : ""}`,
1499
1499
  placeholder: unref(isJSON) ? "Enter JSON" : null
1500
1500
  }, {
1501
1501
  actions: withCtx(() => [
@@ -18,7 +18,7 @@ var __spreadValues = (a, b) => {
18
18
  };
19
19
  var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
20
20
  import "$histoire-theme";
21
- import { pushScopeId, popScopeId, defineComponent, useCssVars, unref, computed, ref, openBlock, createElementBlock, createVNode, withCtx, createElementVNode, normalizeClass, toDisplayString, createCommentVNode, watch, resolveComponent, withKeys, Fragment, renderList, createBlock, isRef, resolveDirective, withDirectives, createTextVNode, defineAsyncComponent, vShow, reactive, Transition, normalizeStyle, resolveDynamicComponent, createApp } from "vue";
21
+ import { pushScopeId, popScopeId, defineComponent, useCssVars, unref, computed, ref, openBlock, createElementBlock, createVNode, withCtx, createElementVNode, normalizeClass, toDisplayString, createCommentVNode, watch, resolveComponent, withKeys, Fragment, renderList, createBlock, isRef, resolveDirective, withDirectives, createTextVNode, defineAsyncComponent, vShow, reactive, Transition, normalizeStyle, onMounted, resolveDynamicComponent, createApp } from "vue";
22
22
  import { defineStore, createPinia } from "pinia";
23
23
  import FloatingVue from "floating-vue";
24
24
  import { files, tree, onUpdate } from "$histoire-stories";
@@ -141,7 +141,7 @@ const _withScopeId$1 = (n) => (pushScopeId("data-v-1a78012e"), n = n(), popScope
141
141
  const _hoisted_1$9 = { "data-test-id": "story-list-folder" };
142
142
  const _hoisted_2$6 = ["onKeyup"];
143
143
  const _hoisted_3$4 = { class: "bind-tree-padding htw-flex htw-items-center htw-gap-2 htw-min-w-0" };
144
- const _hoisted_4$4 = { class: "htw-flex htw-flex-none htw-items-center" };
144
+ const _hoisted_4$3 = { class: "htw-flex htw-flex-none htw-items-center" };
145
145
  const _hoisted_5$1 = { class: "htw-truncate" };
146
146
  const _hoisted_6 = { key: 0 };
147
147
  const _sfc_main$9 = /* @__PURE__ */ defineComponent({
@@ -180,7 +180,7 @@ const _sfc_main$9 = /* @__PURE__ */ defineComponent({
180
180
  ]
181
181
  }, [
182
182
  createElementVNode("span", _hoisted_3$4, [
183
- createElementVNode("span", _hoisted_4$4, [
183
+ createElementVNode("span", _hoisted_4$3, [
184
184
  createVNode(unref(Icon), {
185
185
  icon: "carbon:caret-right",
186
186
  class: normalizeClass(["htw-w-4 htw-h-4 htw-transition-transform htw-duration-150 htw-opacity-30", {
@@ -225,7 +225,7 @@ const _hoisted_1$8 = {
225
225
  };
226
226
  const _hoisted_2$5 = ["onKeyup"];
227
227
  const _hoisted_3$3 = { class: "htw-truncate htw-opacity-50" };
228
- const _hoisted_4$3 = /* @__PURE__ */ createElementVNode("span", { class: "htw-h-[1px] htw-flex-1 htw-bg-gray-500/10 htw-mx-2" }, null, -1);
228
+ const _hoisted_4$2 = /* @__PURE__ */ createElementVNode("span", { class: "htw-h-[1px] htw-flex-1 htw-bg-gray-500/10 htw-mx-2" }, null, -1);
229
229
  const _hoisted_5 = { key: 1 };
230
230
  const _sfc_main$8 = /* @__PURE__ */ defineComponent({
231
231
  name: "StoryGroup",
@@ -262,7 +262,7 @@ const _sfc_main$8 = /* @__PURE__ */ defineComponent({
262
262
  }])
263
263
  }, null, 8, ["class"]),
264
264
  createElementVNode("span", _hoisted_3$3, toDisplayString(__props.group.title), 1),
265
- _hoisted_4$3
265
+ _hoisted_4$2
266
266
  ], 40, _hoisted_2$5)) : createCommentVNode("", true),
267
267
  unref(isFolderOpen) ? (openBlock(), createElementBlock("div", _hoisted_5, [
268
268
  (openBlock(true), createElementBlock(Fragment, null, renderList(__props.group.children, (element) => {
@@ -435,7 +435,7 @@ function genKeyboardShortcutHtml(shortcut) {
435
435
  const _hoisted_1$5 = { class: "htw-px-4 htw-h-16 htw-flex htw-items-center htw-gap-2" };
436
436
  const _hoisted_2$4 = { class: "htw-py-3 sm:htw-py-4 htw-flex-1 htw-h-full htw-flex htw-items-center htw-pr-2" };
437
437
  const _hoisted_3$2 = ["href"];
438
- const _hoisted_4$2 = { class: "htw-ml-auto htw-flex-none htw-flex" };
438
+ const _hoisted_4$1 = { class: "htw-ml-auto htw-flex-none htw-flex" };
439
439
  const _sfc_main$5 = /* @__PURE__ */ defineComponent({
440
440
  name: "AppHeader",
441
441
  emits: {
@@ -462,7 +462,7 @@ const _sfc_main$5 = /* @__PURE__ */ defineComponent({
462
462
  createVNode(_sfc_main$6, { class: "htw-max-w-full htw-max-h-full" })
463
463
  ], 8, _hoisted_3$2)
464
464
  ]),
465
- createElementVNode("div", _hoisted_4$2, [
465
+ createElementVNode("div", _hoisted_4$1, [
466
466
  withDirectives((openBlock(), createElementBlock("a", {
467
467
  class: "htw-p-2 sm:htw-p-1 hover:htw-text-primary-500 dark:hover:htw-text-primary-400 htw-cursor-pointer htw-text-gray-900 dark:htw-text-gray-100",
468
468
  "data-test-id": "search-btn",
@@ -496,7 +496,7 @@ const _withScopeId = (n) => (pushScopeId("data-v-5fe505b0"), n = n(), popScopeId
496
496
  const _hoisted_1$4 = /* @__PURE__ */ _withScopeId(() => /* @__PURE__ */ createElementVNode("span", { class: "htw-opacity-40" }, " / ", -1));
497
497
  const _hoisted_2$3 = { class: "htw-flex htw-items-center htw-gap-2" };
498
498
  const _hoisted_3$1 = { class: "htw-opacity-40 htw-text-sm" };
499
- const _hoisted_4$1 = /* @__PURE__ */ createTextVNode(" Select a story... ");
499
+ const _hoisted_4 = /* @__PURE__ */ createTextVNode(" Select a story... ");
500
500
  const _sfc_main$4 = /* @__PURE__ */ defineComponent({
501
501
  name: "Breadcrumb",
502
502
  props: {
@@ -553,7 +553,7 @@ const _sfc_main$4 = /* @__PURE__ */ defineComponent({
553
553
  createElementVNode("span", _hoisted_3$1, toDisplayString(unref(story).variants.length), 1)
554
554
  ])
555
555
  ], 64)) : (openBlock(), createElementBlock(Fragment, { key: 1 }, [
556
- _hoisted_4$1
556
+ _hoisted_4
557
557
  ], 64)),
558
558
  createVNode(unref(Icon), {
559
559
  icon: "carbon:chevron-sort",
@@ -689,12 +689,11 @@ const _hoisted_1 = {
689
689
  key: 0,
690
690
  class: "htw-hidden"
691
691
  };
692
- const _hoisted_2 = { class: "htw-h-screen htw-bg-white dark:htw-bg-gray-700 dark:htw-text-gray-100" };
693
- const _hoisted_3 = {
692
+ const _hoisted_2 = {
694
693
  key: 0,
695
694
  class: "htw-h-full htw-flex htw-flex-col htw-divide-y htw-divide-gray-100 dark:htw-divide-gray-800"
696
695
  };
697
- const _hoisted_4 = { class: "htw-flex htw-flex-col htw-h-full" };
696
+ const _hoisted_3 = { class: "htw-flex htw-flex-col htw-h-full" };
698
697
  const __default__ = {
699
698
  name: "HistoireApp"
700
699
  };
@@ -747,6 +746,10 @@ const _sfc_main = /* @__PURE__ */ defineComponent(__spreadProps(__spreadValues({
747
746
  loading.value = false;
748
747
  });
749
748
  }
749
+ const mounted = ref(false);
750
+ onMounted(() => {
751
+ mounted.value = true;
752
+ });
750
753
  return (_ctx, _cache) => {
751
754
  const _component_RouterView = resolveComponent("RouterView");
752
755
  return openBlock(), createElementBlock(Fragment, null, [
@@ -755,8 +758,13 @@ const _sfc_main = /* @__PURE__ */ defineComponent(__spreadProps(__spreadValues({
755
758
  story: unref(storyStore).currentStory
756
759
  }, null, 8, ["story"]))
757
760
  ])) : createCommentVNode("", true),
758
- createElementVNode("div", _hoisted_2, [
759
- unref(isMobile) ? (openBlock(), createElementBlock("div", _hoisted_3, [
761
+ createElementVNode("div", {
762
+ class: "htw-h-screen htw-bg-white dark:htw-bg-gray-700 dark:htw-text-gray-100",
763
+ style: normalizeStyle({
764
+ opacity: mounted.value && !loading.value ? 1 : 0
765
+ })
766
+ }, [
767
+ unref(isMobile) ? (openBlock(), createElementBlock("div", _hoisted_2, [
760
768
  createVNode(_sfc_main$5, {
761
769
  onSearch: _cache[0] || (_cache[0] = ($event) => isSearchOpen.value = true)
762
770
  }),
@@ -774,7 +782,7 @@ const _sfc_main = /* @__PURE__ */ defineComponent(__spreadProps(__spreadValues({
774
782
  class: "htw-h-full"
775
783
  }, {
776
784
  first: withCtx(() => [
777
- createElementVNode("div", _hoisted_4, [
785
+ createElementVNode("div", _hoisted_3, [
778
786
  createVNode(_sfc_main$5, {
779
787
  class: "htw-flex-none",
780
788
  onSearch: _cache[1] || (_cache[1] = ($event) => isSearchOpen.value = true)
@@ -795,14 +803,14 @@ const _sfc_main = /* @__PURE__ */ defineComponent(__spreadProps(__spreadValues({
795
803
  key: 2,
796
804
  shown: isSearchOpen.value,
797
805
  onClose: _cache[2] || (_cache[2] = ($event) => isSearchOpen.value = false)
798
- }, null, 8, ["shown"])) : createCommentVNode("", true),
799
- createVNode(Transition, { name: "__histoire-fade" }, {
800
- default: withCtx(() => [
801
- loading.value ? (openBlock(), createBlock(_sfc_main$1, { key: 0 })) : createCommentVNode("", true)
802
- ]),
803
- _: 1
804
- })
805
- ])
806
+ }, null, 8, ["shown"])) : createCommentVNode("", true)
807
+ ], 4),
808
+ createVNode(Transition, { name: "__histoire-fade" }, {
809
+ default: withCtx(() => [
810
+ loading.value ? (openBlock(), createBlock(_sfc_main$1, { key: 0 })) : createCommentVNode("", true)
811
+ ]),
812
+ _: 1
813
+ })
806
814
  ], 64);
807
815
  };
808
816
  }
@@ -9,7 +9,7 @@ export default {
9
9
  import { files as rawFiles, tree as rawTree, onUpdate } from '$histoire-stories'
10
10
  import StoryList from './components/tree/StoryList.vue'
11
11
  import BaseSplitPane from './components/base/BaseSplitPane.vue'
12
- import { computed, ref, watch } from 'vue'
12
+ import { computed, onMounted, ref, watch } from 'vue'
13
13
  import AppHeader from './components/app/AppHeader.vue'
14
14
  import type { StoryFile, Tree } from './types'
15
15
  import { useStoryStore } from './stores/story'
@@ -76,14 +76,17 @@ onKeyboardShortcut(['ctrl+k', 'meta+k'], (event) => {
76
76
 
77
77
  const loading = ref(false)
78
78
 
79
- // @ts-expect-error vite hot api
80
79
  if (import.meta.hot && !rawFiles.length) {
81
80
  loading.value = true
82
- // @ts-expect-error vite hot api
83
81
  import.meta.hot.on('histoire:all-stories-loaded', () => {
84
82
  loading.value = false
85
83
  })
86
84
  }
85
+
86
+ const mounted = ref(false)
87
+ onMounted(() => {
88
+ mounted.value = true
89
+ })
87
90
  </script>
88
91
 
89
92
  <template>
@@ -97,7 +100,13 @@ if (import.meta.hot && !rawFiles.length) {
97
100
  />
98
101
  </div>
99
102
 
100
- <div class="htw-h-screen htw-bg-white dark:htw-bg-gray-700 dark:htw-text-gray-100">
103
+ <div
104
+ class="htw-h-screen htw-bg-white dark:htw-bg-gray-700 dark:htw-text-gray-100"
105
+ :style="{
106
+ // Prevent flash of content
107
+ opacity: mounted && !loading ? 1 : 0,
108
+ }"
109
+ >
101
110
  <div
102
111
  v-if="isMobile"
103
112
  class="htw-h-full htw-flex htw-flex-col htw-divide-y htw-divide-gray-100 dark:htw-divide-gray-800"
@@ -142,11 +151,11 @@ if (import.meta.hot && !rawFiles.length) {
142
151
  :shown="isSearchOpen"
143
152
  @close="isSearchOpen = false"
144
153
  />
145
-
146
- <transition name="__histoire-fade">
147
- <InitialLoading
148
- v-if="loading"
149
- />
150
- </transition>
151
154
  </div>
155
+
156
+ <transition name="__histoire-fade">
157
+ <InitialLoading
158
+ v-if="loading"
159
+ />
160
+ </transition>
152
161
  </template>
@@ -8,9 +8,7 @@ const progress = reactive({
8
8
 
9
9
  const maxCols = window.innerWidth / 20
10
10
 
11
- // @ts-expect-error vite hot api
12
11
  if (import.meta.hot) {
13
- // @ts-expect-error vite hot api
14
12
  import.meta.hot.on('histoire:stories-loading-progress', (data) => {
15
13
  progress.loaded = data.loadedFileCount
16
14
  progress.total = data.totalFileCount
@@ -71,7 +71,7 @@ const canReset = computed(() => props.variant.state?._hPropState?.[props.compone
71
71
  :is="comp"
72
72
  v-if="comp"
73
73
  v-model="model"
74
- :title="definition.name"
74
+ :title="`${definition.name}${canReset ? ' *' : ''}`"
75
75
  :placeholder="isJSON ? 'Enter JSON' : null"
76
76
  >
77
77
  <template #actions>
@@ -26,9 +26,7 @@ export function mountMainApp() {
26
26
  app.use(router);
27
27
  registerGlobalComponents(app);
28
28
  app.mount('#app');
29
- // @ts-expect-error vite hot api
30
29
  if (import.meta.hot) {
31
- // @ts-expect-error vite hot api
32
30
  import.meta.hot.send('histoire:mount', {});
33
31
  }
34
32
  }
@@ -1,2 +1,2 @@
1
- export declare const base: any;
1
+ export declare const base: string;
2
2
  export declare const router: import("vue-router").Router;
@@ -1,5 +1,4 @@
1
1
  import { createRouter, createWebHistory } from 'vue-router';
2
- // @ts-expect-error env not defined
3
2
  export const base = import.meta.env.BASE_URL;
4
3
  export const router = createRouter({
5
4
  history: createWebHistory(base),
package/dist/node/bin.js CHANGED
@@ -4,6 +4,7 @@ import { fileURLToPath } from 'url';
4
4
  import sade from 'sade';
5
5
  const __dirname = dirname(fileURLToPath(import.meta.url));
6
6
  const { version } = JSON.parse(fs.readFileSync(resolve(__dirname, '../../package.json'), 'utf8'));
7
+ process.env.NODE_ENV = 'development';
7
8
  const program = sade('histoire');
8
9
  program.version(version);
9
10
  program.command('dev')
@@ -1,11 +1,11 @@
1
1
  import { join } from 'pathe';
2
- import { build as viteBuild, createServer as createViteServer, resolveConfig as resolveViteConfig } from 'vite';
2
+ import { build as viteBuild, createServer as createViteServer, mergeConfig as mergeViteConfig, } from 'vite';
3
3
  import fs from 'fs-extra';
4
4
  import { lookup as lookupMime } from 'mrmime';
5
5
  import pc from 'picocolors';
6
6
  import { performance } from 'perf_hooks';
7
7
  import { APP_PATH } from './alias.js';
8
- import { createVitePlugins } from './vite.js';
8
+ import { getViteConfigWithPlugins, resolveViteConfig } from './vite.js';
9
9
  import { findAllStories } from './stories.js';
10
10
  import { useCollectStories } from './collect/index.js';
11
11
  import { BuildPluginApi } from './plugin.js';
@@ -22,9 +22,8 @@ const PREFETCHED_MODULES = [
22
22
  export async function build(ctx) {
23
23
  const startTime = performance.now();
24
24
  await findAllStories(ctx);
25
- const server = await createViteServer({
26
- plugins: await createVitePlugins(true, ctx),
27
- });
25
+ const resolvedViteConfig = await resolveViteConfig(ctx);
26
+ const server = await createViteServer(await getViteConfigWithPlugins(true, ctx));
28
27
  await server.pluginContainer.buildStart({});
29
28
  const moduleLoader = useModuleLoader({
30
29
  server,
@@ -50,8 +49,8 @@ export async function build(ctx) {
50
49
  const storyCount = ctx.storyFiles.reduce((sum, file) => sum + (file.story?.variants.length ? 1 : 0), 0);
51
50
  const variantCount = ctx.storyFiles.reduce((sum, file) => sum + (file.story?.variants.length ?? 0), 0);
52
51
  const emptyStoryCount = ctx.storyFiles.length - storyCount;
53
- const results = await viteBuild({
54
- plugins: await createVitePlugins(false, ctx),
52
+ const results = await viteBuild(mergeViteConfig(await getViteConfigWithPlugins(false, ctx), {
53
+ mode: 'development',
55
54
  build: {
56
55
  rollupOptions: {
57
56
  input: [
@@ -60,7 +59,7 @@ export async function build(ctx) {
60
59
  ],
61
60
  output: {
62
61
  manualChunks(id) {
63
- if (!id.includes('histoire/dist/client') && id.includes('node_modules')) {
62
+ if (!id.includes('histoire/dist/client') && !id.includes('histoire/dist/bundled') && id.includes('node_modules')) {
64
63
  return 'vendor';
65
64
  }
66
65
  },
@@ -71,11 +70,8 @@ export async function build(ctx) {
71
70
  cssCodeSplit: false,
72
71
  minify: false,
73
72
  },
74
- });
73
+ }));
75
74
  const result = Array.isArray(results) ? results[0] : results;
76
- const resolvedViteConfig = await resolveViteConfig({
77
- plugins: await createVitePlugins(false, ctx),
78
- }, 'build');
79
75
  const styleOutput = result.output.find(o => o.name === 'style.css' && o.type === 'asset');
80
76
  // Preload
81
77
  const preloadOutputs = result.output.filter(o => PRELOAD_MODULES.includes(o.name) && o.type === 'chunk');
@@ -1,15 +1,12 @@
1
- import { resolveConfig as resolveViteConfig } from 'vite';
2
1
  import pc from 'picocolors';
3
2
  import { createContext } from '../context.js';
4
- import { createVitePlugins } from '../vite.js';
3
+ import { resolveViteConfig } from '../vite.js';
5
4
  import { startPreview } from '../preview.js';
6
5
  export async function previewCommand(options) {
7
6
  const ctx = await createContext({
8
7
  mode: 'build',
9
8
  });
10
- const viteConfig = await resolveViteConfig({
11
- plugins: await createVitePlugins(false, ctx),
12
- }, 'build');
9
+ const viteConfig = await resolveViteConfig(ctx);
13
10
  const { baseUrl } = await startPreview(viteConfig, options.port, ctx);
14
11
  console.log(`Preview server listening on ${pc.cyan(baseUrl)}`);
15
12
  }
@@ -1,17 +1,13 @@
1
1
  import { createServer as createViteServer } from 'vite';
2
- import { createVitePlugins, RESOLVED_SEARCH_TITLE_DATA_ID, RESOLVED_STORIES_ID } from './vite.js';
2
+ import { getViteConfigWithPlugins, RESOLVED_SEARCH_TITLE_DATA_ID, RESOLVED_STORIES_ID } from './vite.js';
3
3
  import { onStoryChange, watchStories } from './stories.js';
4
4
  import { useCollectStories } from './collect/index.js';
5
5
  import { DevPluginApi } from './plugin.js';
6
6
  import { useModuleLoader } from './load.js';
7
7
  export async function createServer(ctx, port) {
8
- const server = await createViteServer({
9
- plugins: await createVitePlugins(false, ctx),
10
- });
8
+ const server = await createViteServer(await getViteConfigWithPlugins(false, ctx));
11
9
  await server.pluginContainer.buildStart({});
12
- const nodeServer = await createViteServer({
13
- plugins: await createVitePlugins(true, ctx),
14
- });
10
+ const nodeServer = await createViteServer(await getViteConfigWithPlugins(true, ctx));
15
11
  await nodeServer.pluginContainer.buildStart({});
16
12
  const moduleLoader = useModuleLoader({
17
13
  server: nodeServer,
@@ -1,4 +1,4 @@
1
- import { Plugin as VitePlugin } from 'vite';
1
+ import { ResolvedConfig, InlineConfig } from 'vite';
2
2
  import { Context } from './context.js';
3
3
  export declare const STORIES_ID = "$histoire-stories";
4
4
  export declare const RESOLVED_STORIES_ID: string;
@@ -12,4 +12,5 @@ export declare const SEARCH_TITLE_DATA_ID = "$histoire-search-title-data";
12
12
  export declare const RESOLVED_SEARCH_TITLE_DATA_ID: string;
13
13
  export declare const SEARCH_DOCS_DATA_ID = "$histoire-search-docs-data";
14
14
  export declare const RESOLVED_SEARCH_DOCS_DATA_ID: string;
15
- export declare function createVitePlugins(server: boolean, ctx: Context): Promise<VitePlugin[]>;
15
+ export declare function resolveViteConfig(ctx: Context): Promise<ResolvedConfig>;
16
+ export declare function getViteConfigWithPlugins(server: boolean, ctx: Context): Promise<InlineConfig>;
package/dist/node/vite.js CHANGED
@@ -1,6 +1,6 @@
1
1
  import { createRequire } from 'module';
2
2
  import { relative, dirname } from 'pathe';
3
- import { resolveConfig as resolveViteConfig } from 'vite';
3
+ import { resolveConfig as resolveViteConfigInternal, mergeConfig as mergeViteConfig, } from 'vite';
4
4
  import { lookup as lookupMime } from 'mrmime';
5
5
  import { APP_PATH, DIST_PATH, TEMP_PATH } from './alias.js';
6
6
  import { notifyStoryChange } from './stories.js';
@@ -21,17 +21,31 @@ export const SEARCH_TITLE_DATA_ID = '$histoire-search-title-data';
21
21
  export const RESOLVED_SEARCH_TITLE_DATA_ID = `/${SEARCH_TITLE_DATA_ID}-resolved`;
22
22
  export const SEARCH_DOCS_DATA_ID = '$histoire-search-docs-data';
23
23
  export const RESOLVED_SEARCH_DOCS_DATA_ID = `/${SEARCH_DOCS_DATA_ID}-resolved`;
24
- export async function createVitePlugins(server, ctx) {
25
- const viteConfig = await resolveViteConfig({}, ctx.mode === 'dev' ? 'serve' : 'build');
26
- const plugins = [];
24
+ export async function resolveViteConfig(ctx) {
25
+ const command = ctx.mode === 'dev' ? 'serve' : 'build';
26
+ let viteConfig = (await resolveViteConfigInternal({}, command));
27
+ viteConfig = mergeHistoireViteConfig(viteConfig, ctx);
28
+ return viteConfig;
29
+ }
30
+ async function mergeHistoireViteConfig(viteConfig, ctx) {
27
31
  if (ctx.config.vite) {
28
- plugins.push({
29
- name: 'histoire-vite-config-override',
30
- config(config, env) {
31
- return typeof ctx.config.vite === 'function' ? ctx.config.vite(config, env) : ctx.config.vite;
32
- },
33
- });
32
+ const command = ctx.mode === 'dev' ? 'serve' : 'build';
33
+ const overrides = typeof ctx.config.vite === 'function'
34
+ ? await ctx.config.vite(viteConfig, {
35
+ mode: ctx.mode,
36
+ command,
37
+ })
38
+ : ctx.config.vite;
39
+ if (overrides) {
40
+ viteConfig = mergeViteConfig(viteConfig, overrides);
41
+ }
34
42
  }
43
+ return viteConfig;
44
+ }
45
+ export async function getViteConfigWithPlugins(server, ctx) {
46
+ const resolvedViteConfig = await resolveViteConfig(ctx);
47
+ const inlineConfig = await mergeHistoireViteConfig({}, ctx);
48
+ const plugins = [];
35
49
  plugins.push({
36
50
  name: 'histoire-vite-plugin',
37
51
  config() {
@@ -57,7 +71,7 @@ export async function createVitePlugins(server, ctx) {
57
71
  },
58
72
  server: {
59
73
  fs: {
60
- allow: [DIST_PATH, TEMP_PATH, viteConfig.root, process.cwd()],
74
+ allow: [DIST_PATH, TEMP_PATH, resolvedViteConfig.root, process.cwd()],
61
75
  },
62
76
  },
63
77
  define: {
@@ -247,7 +261,7 @@ if (import.meta.hot) {
247
261
  if (exclude.some(r => r.test(id)))
248
262
  return;
249
263
  if (include.some(r => r.test(id))) {
250
- const file = relative(viteConfig.root, id);
264
+ const file = relative(resolvedViteConfig.root, id);
251
265
  const index = code.indexOf('export default');
252
266
  const result = `${code.substring(0, index)}_sfc_main.__file = '${file}'\n${code.substring(index)}`;
253
267
  return result;
@@ -255,7 +269,9 @@ if (import.meta.hot) {
255
269
  },
256
270
  });
257
271
  }
258
- return plugins;
272
+ return mergeViteConfig(inlineConfig, {
273
+ plugins,
274
+ });
259
275
  }
260
276
  async function createCustomBlocksPlugins(ctx) {
261
277
  const plugins = [];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "histoire",
3
- "version": "0.5.3",
3
+ "version": "0.6.1",
4
4
  "description": "A fast story book powered by Vite",
5
5
  "license": "MIT",
6
6
  "author": {
@@ -33,7 +33,7 @@
33
33
  "histoire": "./bin.mjs"
34
34
  },
35
35
  "dependencies": {
36
- "@histoire/controls": "^0.5.3",
36
+ "@histoire/controls": "^0.6.1",
37
37
  "@iconify/vue": "^3.2.1",
38
38
  "@types/markdown-it": "^12.2.3",
39
39
  "@vueuse/core": "^8.2.5",
@@ -9,7 +9,7 @@ export default {
9
9
  import { files as rawFiles, tree as rawTree, onUpdate } from '$histoire-stories'
10
10
  import StoryList from './components/tree/StoryList.vue'
11
11
  import BaseSplitPane from './components/base/BaseSplitPane.vue'
12
- import { computed, ref, watch } from 'vue'
12
+ import { computed, onMounted, ref, watch } from 'vue'
13
13
  import AppHeader from './components/app/AppHeader.vue'
14
14
  import type { StoryFile, Tree } from './types'
15
15
  import { useStoryStore } from './stores/story'
@@ -76,14 +76,17 @@ onKeyboardShortcut(['ctrl+k', 'meta+k'], (event) => {
76
76
 
77
77
  const loading = ref(false)
78
78
 
79
- // @ts-expect-error vite hot api
80
79
  if (import.meta.hot && !rawFiles.length) {
81
80
  loading.value = true
82
- // @ts-expect-error vite hot api
83
81
  import.meta.hot.on('histoire:all-stories-loaded', () => {
84
82
  loading.value = false
85
83
  })
86
84
  }
85
+
86
+ const mounted = ref(false)
87
+ onMounted(() => {
88
+ mounted.value = true
89
+ })
87
90
  </script>
88
91
 
89
92
  <template>
@@ -97,7 +100,13 @@ if (import.meta.hot && !rawFiles.length) {
97
100
  />
98
101
  </div>
99
102
 
100
- <div class="htw-h-screen htw-bg-white dark:htw-bg-gray-700 dark:htw-text-gray-100">
103
+ <div
104
+ class="htw-h-screen htw-bg-white dark:htw-bg-gray-700 dark:htw-text-gray-100"
105
+ :style="{
106
+ // Prevent flash of content
107
+ opacity: mounted && !loading ? 1 : 0,
108
+ }"
109
+ >
101
110
  <div
102
111
  v-if="isMobile"
103
112
  class="htw-h-full htw-flex htw-flex-col htw-divide-y htw-divide-gray-100 dark:htw-divide-gray-800"
@@ -142,11 +151,11 @@ if (import.meta.hot && !rawFiles.length) {
142
151
  :shown="isSearchOpen"
143
152
  @close="isSearchOpen = false"
144
153
  />
145
-
146
- <transition name="__histoire-fade">
147
- <InitialLoading
148
- v-if="loading"
149
- />
150
- </transition>
151
154
  </div>
155
+
156
+ <transition name="__histoire-fade">
157
+ <InitialLoading
158
+ v-if="loading"
159
+ />
160
+ </transition>
152
161
  </template>
@@ -8,9 +8,7 @@ const progress = reactive({
8
8
 
9
9
  const maxCols = window.innerWidth / 20
10
10
 
11
- // @ts-expect-error vite hot api
12
11
  if (import.meta.hot) {
13
- // @ts-expect-error vite hot api
14
12
  import.meta.hot.on('histoire:stories-loading-progress', (data) => {
15
13
  progress.loaded = data.loadedFileCount
16
14
  progress.total = data.totalFileCount
@@ -71,7 +71,7 @@ const canReset = computed(() => props.variant.state?._hPropState?.[props.compone
71
71
  :is="comp"
72
72
  v-if="comp"
73
73
  v-model="model"
74
- :title="definition.name"
74
+ :title="`${definition.name}${canReset ? ' *' : ''}`"
75
75
  :placeholder="isJSON ? 'Enter JSON' : null"
76
76
  >
77
77
  <template #actions>
@@ -30,9 +30,7 @@ export function mountMainApp () {
30
30
  registerGlobalComponents(app)
31
31
  app.mount('#app')
32
32
 
33
- // @ts-expect-error vite hot api
34
33
  if (import.meta.hot) {
35
- // @ts-expect-error vite hot api
36
34
  import.meta.hot.send('histoire:mount', {})
37
35
  }
38
36
  }
@@ -1,7 +1,6 @@
1
1
  import { createRouter, createWebHistory } from 'vue-router'
2
2
 
3
- // @ts-expect-error env not defined
4
- export const base = import.meta.env.BASE_URL
3
+ export const base = import.meta.env.BASE_URL as string
5
4
 
6
5
  export const router = createRouter({
7
6
  history: createWebHistory(base),
@@ -1,3 +1,5 @@
1
+ /// <reference types="vite/client" />
2
+
1
3
  declare module '*.vue' {
2
4
  import { ComponentOptions } from 'vue'
3
5
  const comp: ComponentOptions
package/src/node/bin.ts CHANGED
@@ -7,6 +7,8 @@ const __dirname = dirname(fileURLToPath(import.meta.url))
7
7
 
8
8
  const { version } = JSON.parse(fs.readFileSync(resolve(__dirname, '../../package.json'), 'utf8'))
9
9
 
10
+ process.env.NODE_ENV = 'development'
11
+
10
12
  const program = sade('histoire')
11
13
  program.version(version)
12
14
 
package/src/node/build.ts CHANGED
@@ -1,12 +1,17 @@
1
1
  import { join } from 'pathe'
2
- import { build as viteBuild, createServer as createViteServer, ResolvedConfig as ViteConfig, resolveConfig as resolveViteConfig } from 'vite'
2
+ import {
3
+ build as viteBuild,
4
+ createServer as createViteServer,
5
+ ResolvedConfig as ViteConfig,
6
+ mergeConfig as mergeViteConfig,
7
+ } from 'vite'
3
8
  import fs from 'fs-extra'
4
9
  import { lookup as lookupMime } from 'mrmime'
5
10
  import pc from 'picocolors'
6
11
  import { performance } from 'perf_hooks'
7
12
  import { APP_PATH } from './alias.js'
8
13
  import { Context } from './context.js'
9
- import { createVitePlugins } from './vite.js'
14
+ import { getViteConfigWithPlugins, resolveViteConfig } from './vite.js'
10
15
  import { findAllStories } from './stories.js'
11
16
  import type { RollupOutput } from 'rollup'
12
17
  import { useCollectStories } from './collect/index.js'
@@ -28,9 +33,9 @@ export async function build (ctx: Context) {
28
33
  const startTime = performance.now()
29
34
  await findAllStories(ctx)
30
35
 
31
- const server = await createViteServer({
32
- plugins: await createVitePlugins(true, ctx),
33
- })
36
+ const resolvedViteConfig = await resolveViteConfig(ctx)
37
+
38
+ const server = await createViteServer(await getViteConfigWithPlugins(true, ctx))
34
39
  await server.pluginContainer.buildStart({})
35
40
 
36
41
  const moduleLoader = useModuleLoader({
@@ -60,8 +65,8 @@ export async function build (ctx: Context) {
60
65
  const variantCount = ctx.storyFiles.reduce((sum, file) => sum + (file.story?.variants.length ?? 0), 0)
61
66
  const emptyStoryCount = ctx.storyFiles.length - storyCount
62
67
 
63
- const results = await viteBuild({
64
- plugins: await createVitePlugins(false, ctx),
68
+ const results = await viteBuild(mergeViteConfig(await getViteConfigWithPlugins(false, ctx), {
69
+ mode: 'development',
65
70
  build: {
66
71
  rollupOptions: {
67
72
  input: [
@@ -70,7 +75,7 @@ export async function build (ctx: Context) {
70
75
  ],
71
76
  output: {
72
77
  manualChunks (id) {
73
- if (!id.includes('histoire/dist/client') && id.includes('node_modules')) {
78
+ if (!id.includes('histoire/dist/client') && !id.includes('histoire/dist/bundled') && id.includes('node_modules')) {
74
79
  return 'vendor'
75
80
  }
76
81
  },
@@ -81,13 +86,9 @@ export async function build (ctx: Context) {
81
86
  cssCodeSplit: false,
82
87
  minify: false,
83
88
  },
84
- })
89
+ }))
85
90
  const result = Array.isArray(results) ? results[0] : results as RollupOutput
86
91
 
87
- const resolvedViteConfig = await resolveViteConfig({
88
- plugins: await createVitePlugins(false, ctx),
89
- }, 'build')
90
-
91
92
  const styleOutput = result.output.find(o => o.name === 'style.css' && o.type === 'asset')
92
93
 
93
94
  // Preload
@@ -1,7 +1,6 @@
1
- import { resolveConfig as resolveViteConfig } from 'vite'
2
1
  import pc from 'picocolors'
3
2
  import { createContext } from '../context.js'
4
- import { createVitePlugins } from '../vite.js'
3
+ import { resolveViteConfig } from '../vite.js'
5
4
  import { startPreview } from '../preview.js'
6
5
 
7
6
  export interface PreviewOptions {
@@ -12,9 +11,7 @@ export async function previewCommand (options: PreviewOptions) {
12
11
  const ctx = await createContext({
13
12
  mode: 'build',
14
13
  })
15
- const viteConfig = await resolveViteConfig({
16
- plugins: await createVitePlugins(false, ctx),
17
- }, 'build')
14
+ const viteConfig = await resolveViteConfig(ctx)
18
15
 
19
16
  const { baseUrl } = await startPreview(viteConfig, options.port, ctx)
20
17
  console.log(`Preview server listening on ${pc.cyan(baseUrl)}`)
@@ -1,21 +1,17 @@
1
1
  import { createServer as createViteServer } from 'vite'
2
2
  import { Context } from './context.js'
3
- import { createVitePlugins, RESOLVED_SEARCH_TITLE_DATA_ID, RESOLVED_STORIES_ID } from './vite.js'
4
- import { notifyStoryChange, onStoryChange, watchStories } from './stories.js'
3
+ import { getViteConfigWithPlugins, RESOLVED_SEARCH_TITLE_DATA_ID, RESOLVED_STORIES_ID } from './vite.js'
4
+ import { onStoryChange, watchStories } from './stories.js'
5
5
  import { useCollectStories } from './collect/index.js'
6
6
  import type { StoryFile } from './types.js'
7
7
  import { DevPluginApi } from './plugin.js'
8
8
  import { useModuleLoader } from './load.js'
9
9
 
10
10
  export async function createServer (ctx: Context, port: number) {
11
- const server = await createViteServer({
12
- plugins: await createVitePlugins(false, ctx),
13
- })
11
+ const server = await createViteServer(await getViteConfigWithPlugins(false, ctx))
14
12
  await server.pluginContainer.buildStart({})
15
13
 
16
- const nodeServer = await createViteServer({
17
- plugins: await createVitePlugins(true, ctx),
18
- })
14
+ const nodeServer = await createViteServer(await getViteConfigWithPlugins(true, ctx))
19
15
  await nodeServer.pluginContainer.buildStart({})
20
16
 
21
17
  const moduleLoader = useModuleLoader({
package/src/node/vite.ts CHANGED
@@ -1,6 +1,13 @@
1
1
  import { createRequire } from 'module'
2
2
  import { relative, dirname } from 'pathe'
3
- import { resolveConfig as resolveViteConfig, Plugin as VitePlugin } from 'vite'
3
+ import {
4
+ resolveConfig as resolveViteConfigInternal,
5
+ Plugin as VitePlugin,
6
+ UserConfig as ViteConfig,
7
+ ResolvedConfig,
8
+ InlineConfig,
9
+ mergeConfig as mergeViteConfig,
10
+ } from 'vite'
4
11
  import { lookup as lookupMime } from 'mrmime'
5
12
  import { APP_PATH, DIST_PATH, TEMP_PATH } from './alias.js'
6
13
  import { Context } from './context.js'
@@ -25,19 +32,34 @@ export const RESOLVED_SEARCH_TITLE_DATA_ID = `/${SEARCH_TITLE_DATA_ID}-resolved`
25
32
  export const SEARCH_DOCS_DATA_ID = '$histoire-search-docs-data'
26
33
  export const RESOLVED_SEARCH_DOCS_DATA_ID = `/${SEARCH_DOCS_DATA_ID}-resolved`
27
34
 
28
- export async function createVitePlugins (server: boolean, ctx: Context): Promise<VitePlugin[]> {
29
- const viteConfig = await resolveViteConfig({}, ctx.mode === 'dev' ? 'serve' : 'build')
30
-
31
- const plugins: VitePlugin[] = []
35
+ export async function resolveViteConfig (ctx: Context): Promise<ResolvedConfig> {
36
+ const command = ctx.mode === 'dev' ? 'serve' : 'build'
37
+ let viteConfig = (await resolveViteConfigInternal({}, command)) as unknown
38
+ viteConfig = mergeHistoireViteConfig(viteConfig, ctx)
39
+ return viteConfig as ResolvedConfig
40
+ }
32
41
 
42
+ async function mergeHistoireViteConfig (viteConfig: InlineConfig, ctx: Context) {
33
43
  if (ctx.config.vite) {
34
- plugins.push({
35
- name: 'histoire-vite-config-override',
36
- config (config, env) {
37
- return typeof ctx.config.vite === 'function' ? ctx.config.vite(config, env) : ctx.config.vite
38
- },
39
- })
44
+ const command = ctx.mode === 'dev' ? 'serve' : 'build'
45
+ const overrides = typeof ctx.config.vite === 'function'
46
+ ? await ctx.config.vite(viteConfig as ViteConfig, {
47
+ mode: ctx.mode,
48
+ command,
49
+ })
50
+ : ctx.config.vite
51
+ if (overrides) {
52
+ viteConfig = mergeViteConfig(viteConfig, overrides)
53
+ }
40
54
  }
55
+ return viteConfig
56
+ }
57
+
58
+ export async function getViteConfigWithPlugins (server: boolean, ctx: Context): Promise<InlineConfig> {
59
+ const resolvedViteConfig = await resolveViteConfig(ctx)
60
+
61
+ const inlineConfig = await mergeHistoireViteConfig({}, ctx)
62
+ const plugins: VitePlugin[] = []
41
63
 
42
64
  plugins.push({
43
65
  name: 'histoire-vite-plugin',
@@ -65,7 +87,7 @@ export async function createVitePlugins (server: boolean, ctx: Context): Promise
65
87
  },
66
88
  server: {
67
89
  fs: {
68
- allow: [DIST_PATH, TEMP_PATH, viteConfig.root, process.cwd()],
90
+ allow: [DIST_PATH, TEMP_PATH, resolvedViteConfig.root, process.cwd()],
69
91
  },
70
92
  },
71
93
  define: {
@@ -263,7 +285,7 @@ if (import.meta.hot) {
263
285
  transform (code, id) {
264
286
  if (exclude.some(r => r.test(id))) return
265
287
  if (include.some(r => r.test(id))) {
266
- const file = relative(viteConfig.root, id)
288
+ const file = relative(resolvedViteConfig.root, id)
267
289
  const index = code.indexOf('export default')
268
290
  const result = `${code.substring(0, index)}_sfc_main.__file = '${file}'\n${code.substring(index)}`
269
291
  return result
@@ -272,7 +294,9 @@ if (import.meta.hot) {
272
294
  })
273
295
  }
274
296
 
275
- return plugins
297
+ return mergeViteConfig(inlineConfig, {
298
+ plugins,
299
+ }) as InlineConfig
276
300
  }
277
301
 
278
302
  async function createCustomBlocksPlugins (ctx) {