histoire 0.5.4 → 0.6.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.
- package/dist/bundled/StoryView.js +1 -1
- package/dist/client/app/App.vue +0 -2
- package/dist/client/app/components/app/InitialLoading.vue +0 -2
- package/dist/client/app/components/panel/ControlsComponentPropItem.vue +1 -1
- package/dist/client/app/index.js +0 -2
- package/dist/client/app/router.d.ts +1 -1
- package/dist/client/app/router.js +0 -1
- package/dist/node/bin.js +1 -0
- package/dist/node/build.js +6 -11
- package/dist/node/commands/preview.js +2 -5
- package/dist/node/server.js +3 -7
- package/dist/node/vite.d.ts +3 -2
- package/dist/node/vite.js +29 -13
- package/package.json +2 -2
- package/src/client/app/App.vue +0 -2
- package/src/client/app/components/app/InitialLoading.vue +0 -2
- package/src/client/app/components/panel/ControlsComponentPropItem.vue +1 -1
- package/src/client/app/index.ts +0 -2
- package/src/client/app/router.ts +1 -2
- package/src/client/shim.d.ts +2 -0
- package/src/node/bin.ts +2 -0
- package/src/node/build.ts +12 -12
- package/src/node/commands/preview.ts +2 -5
- package/src/node/server.ts +4 -8
- package/src/node/vite.ts +38 -14
|
@@ -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(() => [
|
package/dist/client/app/App.vue
CHANGED
|
@@ -76,10 +76,8 @@ 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
|
})
|
|
@@ -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>
|
package/dist/client/app/index.js
CHANGED
|
@@ -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:
|
|
1
|
+
export declare const base: string;
|
|
2
2
|
export declare const router: import("vue-router").Router;
|
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')
|
package/dist/node/build.js
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import { join } from 'pathe';
|
|
2
|
-
import { build as viteBuild, createServer as createViteServer,
|
|
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 {
|
|
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
|
|
26
|
-
|
|
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,9 +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({
|
|
52
|
+
const results = await viteBuild(mergeViteConfig(await getViteConfigWithPlugins(false, ctx), {
|
|
54
53
|
mode: 'development',
|
|
55
|
-
plugins: await createVitePlugins(false, ctx),
|
|
56
54
|
build: {
|
|
57
55
|
rollupOptions: {
|
|
58
56
|
input: [
|
|
@@ -72,11 +70,8 @@ export async function build(ctx) {
|
|
|
72
70
|
cssCodeSplit: false,
|
|
73
71
|
minify: false,
|
|
74
72
|
},
|
|
75
|
-
});
|
|
73
|
+
}));
|
|
76
74
|
const result = Array.isArray(results) ? results[0] : results;
|
|
77
|
-
const resolvedViteConfig = await resolveViteConfig({
|
|
78
|
-
plugins: await createVitePlugins(false, ctx),
|
|
79
|
-
}, 'build');
|
|
80
75
|
const styleOutput = result.output.find(o => o.name === 'style.css' && o.type === 'asset');
|
|
81
76
|
// Preload
|
|
82
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 {
|
|
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
|
}
|
package/dist/node/server.js
CHANGED
|
@@ -1,17 +1,13 @@
|
|
|
1
1
|
import { createServer as createViteServer } from 'vite';
|
|
2
|
-
import {
|
|
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,
|
package/dist/node/vite.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
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
|
|
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
|
|
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
|
|
25
|
-
const
|
|
26
|
-
|
|
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
|
-
|
|
29
|
-
|
|
30
|
-
config(
|
|
31
|
-
|
|
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,
|
|
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(
|
|
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
|
|
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.
|
|
3
|
+
"version": "0.6.0",
|
|
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.
|
|
36
|
+
"@histoire/controls": "^0.6.0",
|
|
37
37
|
"@iconify/vue": "^3.2.1",
|
|
38
38
|
"@types/markdown-it": "^12.2.3",
|
|
39
39
|
"@vueuse/core": "^8.2.5",
|
package/src/client/app/App.vue
CHANGED
|
@@ -76,10 +76,8 @@ 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
|
})
|
|
@@ -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>
|
package/src/client/app/index.ts
CHANGED
package/src/client/app/router.ts
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { createRouter, createWebHistory } from 'vue-router'
|
|
2
2
|
|
|
3
|
-
|
|
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),
|
package/src/client/shim.d.ts
CHANGED
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 {
|
|
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 {
|
|
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
|
|
32
|
-
|
|
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,9 +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({
|
|
68
|
+
const results = await viteBuild(mergeViteConfig(await getViteConfigWithPlugins(false, ctx), {
|
|
64
69
|
mode: 'development',
|
|
65
|
-
plugins: await createVitePlugins(false, ctx),
|
|
66
70
|
build: {
|
|
67
71
|
rollupOptions: {
|
|
68
72
|
input: [
|
|
@@ -82,13 +86,9 @@ export async function build (ctx: Context) {
|
|
|
82
86
|
cssCodeSplit: false,
|
|
83
87
|
minify: false,
|
|
84
88
|
},
|
|
85
|
-
})
|
|
89
|
+
}))
|
|
86
90
|
const result = Array.isArray(results) ? results[0] : results as RollupOutput
|
|
87
91
|
|
|
88
|
-
const resolvedViteConfig = await resolveViteConfig({
|
|
89
|
-
plugins: await createVitePlugins(false, ctx),
|
|
90
|
-
}, 'build')
|
|
91
|
-
|
|
92
92
|
const styleOutput = result.output.find(o => o.name === 'style.css' && o.type === 'asset')
|
|
93
93
|
|
|
94
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 {
|
|
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)}`)
|
package/src/node/server.ts
CHANGED
|
@@ -1,21 +1,17 @@
|
|
|
1
1
|
import { createServer as createViteServer } from 'vite'
|
|
2
2
|
import { Context } from './context.js'
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
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 {
|
|
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
|
|
29
|
-
const
|
|
30
|
-
|
|
31
|
-
|
|
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
|
-
|
|
35
|
-
|
|
36
|
-
config
|
|
37
|
-
|
|
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,
|
|
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(
|
|
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
|
|
297
|
+
return mergeViteConfig(inlineConfig, {
|
|
298
|
+
plugins,
|
|
299
|
+
}) as InlineConfig
|
|
276
300
|
}
|
|
277
301
|
|
|
278
302
|
async function createCustomBlocksPlugins (ctx) {
|