histoire 0.12.4 → 0.13.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.
- package/dist/node/build.js +17 -11
- package/dist/node/builtin-plugins/pinceau-tokens.d.ts +6 -0
- package/dist/node/builtin-plugins/pinceau-tokens.js +505 -0
- package/dist/node/collect/index.js +1 -0
- package/dist/node/index.d.ts +7 -0
- package/dist/node/server.js +7 -6
- package/dist/node/util/vendors.d.ts +1 -0
- package/dist/node/util/vendors.js +7 -2
- package/dist/node/virtual/index.d.ts +34 -0
- package/dist/node/virtual/index.js +46 -0
- package/dist/node/virtual/markdown.d.ts +2 -0
- package/dist/node/virtual/markdown.js +19 -0
- package/dist/node/virtual/noop.d.ts +1 -0
- package/dist/node/virtual/noop.js +1 -0
- package/dist/node/virtual/resolved-config.d.ts +2 -0
- package/dist/node/virtual/resolved-config.js +10 -0
- package/dist/node/virtual/resolved-generated-global-setup.d.ts +2 -0
- package/dist/node/virtual/resolved-generated-global-setup.js +23 -0
- package/dist/node/virtual/resolved-generated-setup-code.d.ts +2 -0
- package/dist/node/virtual/resolved-generated-setup-code.js +5 -0
- package/dist/node/virtual/resolved-markdown-files.d.ts +2 -0
- package/dist/node/virtual/resolved-markdown-files.js +17 -0
- package/dist/node/virtual/resolved-stories.d.ts +2 -0
- package/dist/node/virtual/resolved-stories.js +41 -0
- package/dist/node/virtual/resolved-support-plugins-client.d.ts +2 -0
- package/dist/node/virtual/resolved-support-plugins-client.js +11 -0
- package/dist/node/virtual/resolved-support-plugins-collect.d.ts +2 -0
- package/dist/node/virtual/resolved-support-plugins-collect.js +11 -0
- package/dist/node/virtual/resolved-theme.d.ts +2 -0
- package/dist/node/virtual/resolved-theme.js +12 -0
- package/dist/node/virtual/story-source.d.ts +2 -0
- package/dist/node/virtual/story-source.js +16 -0
- package/dist/node/virtual/story.d.ts +2 -0
- package/dist/node/virtual/story.js +7 -0
- package/dist/node/virtual/util.d.ts +2 -0
- package/dist/node/virtual/util.js +4 -0
- package/dist/node/virtual/vite-plugin.d.ts +3 -0
- package/dist/node/virtual/vite-plugin.js +118 -0
- package/dist/node/vite.d.ts +0 -22
- package/dist/node/vite.js +27 -281
- package/package.json +9 -9
- package/src/node/build.ts +19 -11
- package/src/node/builtin-plugins/pinceau-tokens.ts +521 -0
- package/src/node/collect/index.ts +1 -0
- package/src/node/index.ts +8 -0
- package/src/node/server.ts +7 -6
- package/src/node/util/vendors.ts +9 -2
- package/src/node/virtual/index.ts +47 -0
- package/src/node/virtual/markdown.ts +21 -0
- package/src/node/virtual/noop.ts +1 -0
- package/src/node/virtual/resolved-config.ts +12 -0
- package/src/node/virtual/resolved-generated-global-setup.ts +24 -0
- package/src/node/virtual/resolved-generated-setup-code.ts +7 -0
- package/src/node/virtual/resolved-markdown-files.ts +19 -0
- package/src/node/virtual/resolved-stories.ts +43 -0
- package/src/node/virtual/resolved-support-plugins-client.ts +14 -0
- package/src/node/virtual/resolved-support-plugins-collect.ts +14 -0
- package/src/node/virtual/resolved-theme.ts +14 -0
- package/src/node/virtual/story-source.ts +17 -0
- package/src/node/virtual/story.ts +9 -0
- package/src/node/virtual/util.ts +5 -0
- package/src/node/virtual/vite-plugin.ts +135 -0
- package/src/node/vite.ts +28 -294
package/dist/node/vite.js
CHANGED
|
@@ -1,54 +1,12 @@
|
|
|
1
1
|
import { createRequire } from 'node:module';
|
|
2
|
-
import { relative,
|
|
2
|
+
import { relative, join, dirname } from 'pathe';
|
|
3
3
|
import { mergeConfig as mergeViteConfig, loadConfigFromFile as loadViteConfigFromFile, } from 'vite';
|
|
4
4
|
import { lookup as lookupMime } from 'mrmime';
|
|
5
|
-
import fs from 'fs-extra';
|
|
6
5
|
import { APP_PATH, TEMP_PATH } from './alias.js';
|
|
7
6
|
import { notifyStoryChange } from './stories.js';
|
|
8
|
-
import { makeTree } from './tree.js';
|
|
9
|
-
import { parseColor } from './colors.js';
|
|
10
7
|
import { createMarkdownPlugins } from './markdown.js';
|
|
11
|
-
import {
|
|
12
|
-
import { getInjectedImport } from './util/vendors.js';
|
|
8
|
+
import { createVirtualFilesPlugin } from './virtual/vite-plugin.js';
|
|
13
9
|
const require = createRequire(import.meta.url);
|
|
14
|
-
// @TODO wait for virtual modules HMR to work in vite to use `virtual:` and `\0` prefix
|
|
15
|
-
// https://github.com/vitejs/vite/pull/10313
|
|
16
|
-
export const STORIES_ID = 'virtual:$histoire-stories';
|
|
17
|
-
export const RESOLVED_STORIES_ID = `/__resolved__${STORIES_ID}`;
|
|
18
|
-
// export const RESOLVED_STORIES_ID = `\0${STORIES_ID}`
|
|
19
|
-
export const SETUP_ID = 'virtual:$histoire-setup';
|
|
20
|
-
export const NOOP_ID = 'virtual:$histoire-noop';
|
|
21
|
-
export const CONFIG_ID = 'virtual:$histoire-config';
|
|
22
|
-
export const RESOLVED_CONFIG_ID = `/__resolved__${CONFIG_ID}`;
|
|
23
|
-
// export const RESOLVED_CONFIG_ID = `\0${CONFIG_ID}`
|
|
24
|
-
export const THEME_ID = 'virtual:$histoire-theme';
|
|
25
|
-
export const RESOLVED_THEME_ID = `/__resolved__${THEME_ID}.css`;
|
|
26
|
-
// export const RESOLVED_THEME_ID = `\0${THEME_ID}.css`
|
|
27
|
-
export const SEARCH_TITLE_DATA_ID = 'virtual:$histoire-search-title-data';
|
|
28
|
-
export const RESOLVED_SEARCH_TITLE_DATA_ID = `/__resolved__${SEARCH_TITLE_DATA_ID}`;
|
|
29
|
-
// export const RESOLVED_SEARCH_TITLE_DATA_ID = `\0${SEARCH_TITLE_DATA_ID}`
|
|
30
|
-
export const SEARCH_DOCS_DATA_ID = 'virtual:$histoire-search-docs-data';
|
|
31
|
-
export const RESOLVED_SEARCH_DOCS_DATA_ID = `/__resolved__${SEARCH_DOCS_DATA_ID}`;
|
|
32
|
-
// export const RESOLVED_SEARCH_DOCS_DATA_ID = `\0${SEARCH_DOCS_DATA_ID}`
|
|
33
|
-
export const GENERATED_GLOBAL_SETUP = 'virtual:$histoire-generated-global-setup';
|
|
34
|
-
export const RESOLVED_GENERATED_GLOBAL_SETUP = `/__resolved__${GENERATED_GLOBAL_SETUP}`;
|
|
35
|
-
// export const RESOLVED_GENERATED_GLOBAL_SETUP = `\0${GENERATED_GLOBAL_SETUP}`
|
|
36
|
-
export const GENERATED_SETUP_CODE = 'virtual:$histoire-generated-setup-code';
|
|
37
|
-
export const RESOLVED_GENERATED_SETUP_CODE = `/__resolved__${GENERATED_SETUP_CODE}`;
|
|
38
|
-
// export const RESOLVED_GENERATED_SETUP_CODE = `\0${GENERATED_SETUP_CODE}`
|
|
39
|
-
export const SUPPORT_PLUGINS_CLIENT = 'virtual:$histoire-support-plugins-client';
|
|
40
|
-
export const RESOLVED_SUPPORT_PLUGINS_CLIENT = `/__resolved__${SUPPORT_PLUGINS_CLIENT}`;
|
|
41
|
-
// export const RESOLVED_SUPPORT_PLUGINS_CLIENT = `\0${SUPPORT_PLUGINS_CLIENT}`
|
|
42
|
-
export const SUPPORT_PLUGINS_COLLECT = 'virtual:$histoire-support-plugins-collect';
|
|
43
|
-
export const RESOLVED_SUPPORT_PLUGINS_COLLECT = `/__resolved__${SUPPORT_PLUGINS_COLLECT}`;
|
|
44
|
-
// export const RESOLVED_SUPPORT_PLUGINS_COLLECT = `\0${SUPPORT_PLUGINS_COLLECT}`
|
|
45
|
-
export const MARKDOWN_FILES = 'virtual:$histoire-markdown-files';
|
|
46
|
-
export const RESOLVED_MARKDOWN_FILES = `/__resolved__${MARKDOWN_FILES}`;
|
|
47
|
-
// export const RESOLVED_MARKDOWN_FILES = `\0${MARKDOWN_FILES}`
|
|
48
|
-
const ID_SEPARATOR = '__-__';
|
|
49
|
-
const PLUGINS_HAVE_DEV = [
|
|
50
|
-
'@histoire/plugin-vue',
|
|
51
|
-
];
|
|
52
10
|
export async function mergeHistoireViteConfig(viteConfig, ctx) {
|
|
53
11
|
if (ctx.config.vite) {
|
|
54
12
|
const command = ctx.mode === 'dev' ? 'serve' : 'build';
|
|
@@ -110,6 +68,15 @@ export async function getViteConfigWithPlugins(isServer, ctx) {
|
|
|
110
68
|
alias: {
|
|
111
69
|
'histoire-style': join(APP_PATH, process.env.HISTOIRE_DEV ? 'app/style/main.pcss' : 'style.css'),
|
|
112
70
|
},
|
|
71
|
+
...(isServer
|
|
72
|
+
? {
|
|
73
|
+
// Force resolving deps like Node.JS resolution algorithm (in case some modules are not loaded with ssr: true e.g. .vue files)
|
|
74
|
+
conditions: ['node'],
|
|
75
|
+
// eslint-disable-next-line @typescript-eslint/prefer-ts-expect-error
|
|
76
|
+
// @ts-ignore we support Vite ^3.0, but browserField is available in Vite ^3.2
|
|
77
|
+
browserField: false,
|
|
78
|
+
}
|
|
79
|
+
: {}),
|
|
113
80
|
},
|
|
114
81
|
optimizeDeps: {
|
|
115
82
|
entries: [
|
|
@@ -145,253 +112,31 @@ export async function getViteConfigWithPlugins(isServer, ctx) {
|
|
|
145
112
|
watch: {
|
|
146
113
|
ignored: [`!**/node_modules/.histoire/**`, '**/vite.config.*'],
|
|
147
114
|
},
|
|
115
|
+
...isServer
|
|
116
|
+
? {
|
|
117
|
+
hmr: false,
|
|
118
|
+
}
|
|
119
|
+
: {},
|
|
148
120
|
},
|
|
149
121
|
define: {
|
|
150
122
|
// We need to force this to be able to use `devtoolsRawSetupState`
|
|
151
123
|
__VUE_PROD_DEVTOOLS__: 'true',
|
|
152
124
|
// Disable warnings
|
|
153
125
|
'process.env.NODE_ENV': JSON.stringify(isServer ? 'production' : process.env.NODE_ENV ?? 'development'),
|
|
154
|
-
|
|
155
|
-
|
|
126
|
+
...!isServer
|
|
127
|
+
? {
|
|
128
|
+
// Collect flag
|
|
129
|
+
'process.env.HST_COLLECT': 'false',
|
|
130
|
+
}
|
|
131
|
+
: {},
|
|
156
132
|
},
|
|
157
133
|
cacheDir: isServer ? 'node_modules/.hst-vite-server' : 'node_modules/.hst-vite',
|
|
158
134
|
};
|
|
159
135
|
},
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
}
|
|
164
|
-
if (id.startsWith(SETUP_ID)) {
|
|
165
|
-
const setupFileConfig = ctx.config.setupFile;
|
|
166
|
-
if (setupFileConfig) {
|
|
167
|
-
let file;
|
|
168
|
-
if (typeof setupFileConfig === 'string') {
|
|
169
|
-
file = setupFileConfig;
|
|
170
|
-
}
|
|
171
|
-
else if (isServer && 'server' in setupFileConfig) {
|
|
172
|
-
file = setupFileConfig.server;
|
|
173
|
-
}
|
|
174
|
-
else if (!isServer && 'browser' in setupFileConfig) {
|
|
175
|
-
file = setupFileConfig.browser;
|
|
176
|
-
}
|
|
177
|
-
if (file) {
|
|
178
|
-
return this.resolve(resolve(ctx.root, file), importer, {
|
|
179
|
-
skipSelf: true,
|
|
180
|
-
});
|
|
181
|
-
}
|
|
182
|
-
}
|
|
183
|
-
return NOOP_ID;
|
|
184
|
-
}
|
|
185
|
-
if (id.startsWith(CONFIG_ID)) {
|
|
186
|
-
return RESOLVED_CONFIG_ID;
|
|
187
|
-
}
|
|
188
|
-
if (id.startsWith(THEME_ID)) {
|
|
189
|
-
return RESOLVED_THEME_ID;
|
|
190
|
-
}
|
|
191
|
-
if (id.startsWith(SEARCH_TITLE_DATA_ID)) {
|
|
192
|
-
return RESOLVED_SEARCH_TITLE_DATA_ID;
|
|
193
|
-
}
|
|
194
|
-
if (id.startsWith(SEARCH_DOCS_DATA_ID)) {
|
|
195
|
-
return RESOLVED_SEARCH_DOCS_DATA_ID;
|
|
196
|
-
}
|
|
197
|
-
if (id.startsWith(GENERATED_GLOBAL_SETUP)) {
|
|
198
|
-
return RESOLVED_GENERATED_GLOBAL_SETUP;
|
|
199
|
-
}
|
|
200
|
-
if (id.startsWith(GENERATED_SETUP_CODE)) {
|
|
201
|
-
const [, index] = id.split(ID_SEPARATOR);
|
|
202
|
-
return `${RESOLVED_GENERATED_SETUP_CODE}${ID_SEPARATOR}${index}`;
|
|
203
|
-
}
|
|
204
|
-
if (id.startsWith(SUPPORT_PLUGINS_CLIENT)) {
|
|
205
|
-
return RESOLVED_SUPPORT_PLUGINS_CLIENT;
|
|
206
|
-
}
|
|
207
|
-
if (id.startsWith(SUPPORT_PLUGINS_COLLECT)) {
|
|
208
|
-
return RESOLVED_SUPPORT_PLUGINS_COLLECT;
|
|
209
|
-
}
|
|
210
|
-
if (id.startsWith(MARKDOWN_FILES)) {
|
|
211
|
-
return RESOLVED_MARKDOWN_FILES;
|
|
212
|
-
}
|
|
213
|
-
if (id.startsWith('virtual:story:')) {
|
|
214
|
-
return `\0${id}`;
|
|
215
|
-
}
|
|
216
|
-
if (id.startsWith('virtual:story-source:')) {
|
|
217
|
-
return `/__resolved__${id}`;
|
|
218
|
-
// @TODO
|
|
219
|
-
// return `\0${id}`
|
|
220
|
-
}
|
|
221
|
-
if (id.startsWith('virtual:md:')) {
|
|
222
|
-
return `/__resolved__${id}`;
|
|
223
|
-
// @TODO
|
|
224
|
-
// return `\0${id}`
|
|
225
|
-
}
|
|
226
|
-
},
|
|
227
|
-
async load(id) {
|
|
228
|
-
if (id === RESOLVED_STORIES_ID) {
|
|
229
|
-
const resolvedStories = ctx.storyFiles.filter(s => !!s.story);
|
|
230
|
-
const files = resolvedStories.map((file, index) => {
|
|
231
|
-
return {
|
|
232
|
-
id: file.id,
|
|
233
|
-
path: file.treePath,
|
|
234
|
-
filePath: file.relativePath,
|
|
235
|
-
story: {
|
|
236
|
-
...file.story,
|
|
237
|
-
docsText: undefined,
|
|
238
|
-
},
|
|
239
|
-
supportPluginId: file.supportPluginId,
|
|
240
|
-
index,
|
|
241
|
-
};
|
|
242
|
-
});
|
|
243
|
-
return `${ctx.supportPlugins.map(p => p.importStoriesPrepend).filter(Boolean).join('\n')}
|
|
244
|
-
${resolvedStories.map((file, index) => {
|
|
245
|
-
const supportPlugin = ctx.supportPlugins.find(p => p.id === file.supportPluginId);
|
|
246
|
-
if (!supportPlugin) {
|
|
247
|
-
throw new Error(`Could not find support plugin for story ${file.path}: ${file.supportPluginId}`);
|
|
248
|
-
}
|
|
249
|
-
return supportPlugin.importStoryComponent(file, index);
|
|
250
|
-
}).filter(Boolean).join('\n')}
|
|
251
|
-
export let files = [${files.map((file) => `{${JSON.stringify(file).slice(1, -1)}, component: Comp${file.index}, source: () => import('virtual:story-source:${file.story.id}')}`).join(',\n')}]
|
|
252
|
-
export let tree = ${JSON.stringify(makeTree(ctx.config, resolvedStories))}
|
|
253
|
-
const handlers = []
|
|
254
|
-
export function onUpdate (cb) {
|
|
255
|
-
handlers.push(cb)
|
|
256
|
-
}
|
|
257
|
-
if (import.meta.hot) {
|
|
258
|
-
import.meta.hot.accept(newModule => {
|
|
259
|
-
files = newModule.files
|
|
260
|
-
tree = newModule.tree
|
|
261
|
-
handlers.forEach(h => {
|
|
262
|
-
h(newModule.files, newModule.tree)
|
|
263
|
-
newModule.onUpdate(h)
|
|
264
|
-
})
|
|
265
|
-
})
|
|
266
|
-
}`;
|
|
267
|
-
}
|
|
268
|
-
if (id === NOOP_ID) {
|
|
269
|
-
return `export default () => {}`;
|
|
270
|
-
}
|
|
271
|
-
if (id === RESOLVED_CONFIG_ID) {
|
|
272
|
-
let js = `export const config = ${JSON.stringify(ctx.config)}\n`;
|
|
273
|
-
if (ctx.config.theme?.logo) {
|
|
274
|
-
for (const key in ctx.config.theme.logo) {
|
|
275
|
-
js += `import Logo_${key} from '${ctx.config.theme.logo[key]}'\n`;
|
|
276
|
-
}
|
|
277
|
-
}
|
|
278
|
-
js += `export const logos = {${Object.keys(ctx.config.theme?.logo ?? {}).map(key => `${key}: Logo_${key}`).join(', ')}}\n`;
|
|
279
|
-
return js;
|
|
280
|
-
}
|
|
281
|
-
if (id === RESOLVED_THEME_ID) {
|
|
282
|
-
let css = '*, ::before, ::after {';
|
|
283
|
-
// Colors
|
|
284
|
-
for (const color in ctx.config.theme?.colors ?? {}) {
|
|
285
|
-
for (const key in ctx.config.theme.colors[color]) {
|
|
286
|
-
css += `--_histoire-color-${color}-${key}: ${parseColor(ctx.config.theme.colors[color][key]).color.join(' ')};`;
|
|
287
|
-
}
|
|
288
|
-
}
|
|
289
|
-
css += '}';
|
|
290
|
-
return css;
|
|
291
|
-
}
|
|
292
|
-
if (id === RESOLVED_SEARCH_TITLE_DATA_ID) {
|
|
293
|
-
return getSearchDataJS(await generateTitleSearchData(ctx));
|
|
294
|
-
}
|
|
295
|
-
if (id === RESOLVED_SEARCH_DOCS_DATA_ID) {
|
|
296
|
-
return getSearchDataJS(await generateDocSearchData(ctx));
|
|
297
|
-
}
|
|
298
|
-
if (id === RESOLVED_GENERATED_GLOBAL_SETUP) {
|
|
299
|
-
if (ctx.config.setupCode) {
|
|
300
|
-
return [
|
|
301
|
-
// Import
|
|
302
|
-
`${ctx.config.setupCode.map((c, index) => `import * as setup_${index} from '${GENERATED_SETUP_CODE}${ID_SEPARATOR}${index}'`).join('\n')}`,
|
|
303
|
-
// List
|
|
304
|
-
`const setupList = [${ctx.config.setupCode.map((c, index) => `setup_${index}`).join(', ')}]`,
|
|
305
|
-
// Setups
|
|
306
|
-
...ctx.supportPlugins.map(p => p.setupFn).map(fnName => `export async function ${fnName} (payload) {
|
|
307
|
-
for (const setup of setupList) {
|
|
308
|
-
if (setup?.${fnName}) {
|
|
309
|
-
await setup.${fnName}(payload)
|
|
310
|
-
}
|
|
311
|
-
}
|
|
312
|
-
}`),
|
|
313
|
-
].join('\n');
|
|
314
|
-
}
|
|
315
|
-
else {
|
|
316
|
-
return '';
|
|
317
|
-
}
|
|
318
|
-
}
|
|
319
|
-
if (id.startsWith(RESOLVED_GENERATED_SETUP_CODE)) {
|
|
320
|
-
const [, index] = id.split(ID_SEPARATOR);
|
|
321
|
-
return ctx.config.setupCode?.[index] ?? '';
|
|
322
|
-
}
|
|
323
|
-
if (id === RESOLVED_SUPPORT_PLUGINS_CLIENT) {
|
|
324
|
-
const plugins = ctx.supportPlugins.map(p => `'${p.id}': () => import(${JSON.stringify(require.resolve(`${p.moduleName}/client${process.env.HISTOIRE_DEV && PLUGINS_HAVE_DEV.includes(p.moduleName) ? '-dev' : ''}`, {
|
|
325
|
-
paths: [ctx.root, import.meta.url],
|
|
326
|
-
}))})`);
|
|
327
|
-
return `export const clientSupportPlugins = {
|
|
328
|
-
${plugins.join(',\n ')}
|
|
329
|
-
}`;
|
|
330
|
-
}
|
|
331
|
-
if (id === RESOLVED_SUPPORT_PLUGINS_COLLECT) {
|
|
332
|
-
const plugins = ctx.supportPlugins.map(p => `'${p.id}': () => import(${JSON.stringify(require.resolve(`${p.moduleName}/collect${process.env.HISTOIRE_DEV && PLUGINS_HAVE_DEV.includes(p.moduleName) ? '-dev' : ''}`, {
|
|
333
|
-
paths: [ctx.root, import.meta.url],
|
|
334
|
-
}))})`);
|
|
335
|
-
return `export const collectSupportPlugins = {
|
|
336
|
-
${plugins.join(',\n ')}
|
|
337
|
-
}`;
|
|
338
|
-
}
|
|
339
|
-
if (id === RESOLVED_MARKDOWN_FILES) {
|
|
340
|
-
const filesJs = ctx.markdownFiles.map(f => `${JSON.stringify(f.relativePath)}: () => import(${JSON.stringify(`virtual:md:${f.id}`)})`).join(',');
|
|
341
|
-
return `import { reactive } from ${process.env.HISTOIRE_DEV ? `'vue'` : getInjectedImport('@histoire/vendors/vue')}
|
|
342
|
-
export const markdownFiles = reactive({${filesJs}})
|
|
343
|
-
if (import.meta.hot) {
|
|
344
|
-
if (!window.__hst_md_hmr) {
|
|
345
|
-
window.__hst_md_hmr = (newModule) => {
|
|
346
|
-
markdownFiles[newModule.relativePath] = () => newModule
|
|
347
|
-
}
|
|
348
|
-
}
|
|
349
|
-
|
|
350
|
-
import.meta.hot.accept(newModule => {
|
|
351
|
-
Object.assign(markdownFiles, newModule.markdownFiles)
|
|
352
|
-
})
|
|
353
|
-
}`;
|
|
354
|
-
}
|
|
355
|
-
if (id.startsWith('\0virtual:story:')) {
|
|
356
|
-
const moduleId = id.replace('\0', '');
|
|
357
|
-
const storyFile = ctx.storyFiles.find(f => f.moduleId === moduleId && f.virtual);
|
|
358
|
-
if (storyFile) {
|
|
359
|
-
return storyFile.moduleCode;
|
|
360
|
-
}
|
|
361
|
-
}
|
|
362
|
-
if (id.startsWith('/__resolved__virtual:story-source:')) {
|
|
363
|
-
const storyId = id.slice('/__resolved__virtual:story-source:'.length);
|
|
364
|
-
const storyFile = ctx.storyFiles.find(f => f.story?.id === storyId);
|
|
365
|
-
if (storyFile) {
|
|
366
|
-
let source;
|
|
367
|
-
if (storyFile.virtual) {
|
|
368
|
-
source = storyFile.moduleCode;
|
|
369
|
-
}
|
|
370
|
-
else {
|
|
371
|
-
source = await fs.readFile(resolve(ctx.root, storyFile.relativePath), 'utf-8');
|
|
372
|
-
}
|
|
373
|
-
return `export default ${JSON.stringify(source)}`;
|
|
374
|
-
}
|
|
375
|
-
}
|
|
376
|
-
if (id.startsWith('/__resolved__virtual:md:')) {
|
|
377
|
-
const fileId = id.slice('/__resolved__virtual:md:'.length);
|
|
378
|
-
const file = ctx.markdownFiles.find(f => f.id === fileId);
|
|
379
|
-
if (!file) {
|
|
380
|
-
throw new Error(`Markdown file not found: ${fileId}`);
|
|
381
|
-
}
|
|
382
|
-
const { html, frontmatter, relativePath } = file;
|
|
383
|
-
return `export const html = ${JSON.stringify(html)}
|
|
384
|
-
export const frontmatter = ${JSON.stringify(frontmatter)}
|
|
385
|
-
export const relativePath = ${JSON.stringify(relativePath)}
|
|
386
|
-
|
|
387
|
-
if (import.meta.hot) {
|
|
388
|
-
import.meta.hot.accept(newModule => {
|
|
389
|
-
if (newModule) {
|
|
390
|
-
window.__hst_md_hmr(newModule)
|
|
391
|
-
}
|
|
392
|
-
})
|
|
393
|
-
}`;
|
|
394
|
-
}
|
|
136
|
+
options() {
|
|
137
|
+
this.meta.histoire = {
|
|
138
|
+
isCollecting: isServer,
|
|
139
|
+
};
|
|
395
140
|
},
|
|
396
141
|
handleHotUpdate(updateContext) {
|
|
397
142
|
const story = ctx.storyFiles.find(file => file.path === updateContext.file);
|
|
@@ -475,6 +220,7 @@ if (import.meta.hot) {
|
|
|
475
220
|
};
|
|
476
221
|
},
|
|
477
222
|
});
|
|
223
|
+
plugins.push(createVirtualFilesPlugin(ctx, isServer));
|
|
478
224
|
// Markdown
|
|
479
225
|
plugins.push(...await createMarkdownPlugins(ctx));
|
|
480
226
|
if (ctx.mode === 'build') {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "histoire",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.13.1",
|
|
4
4
|
"description": "A fast story book powered by Vite",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": {
|
|
@@ -33,10 +33,10 @@
|
|
|
33
33
|
"histoire": "./bin.mjs"
|
|
34
34
|
},
|
|
35
35
|
"dependencies": {
|
|
36
|
-
"@histoire/app": "^0.
|
|
37
|
-
"@histoire/controls": "^0.
|
|
38
|
-
"@histoire/shared": "^0.
|
|
39
|
-
"@histoire/vendors": "^0.
|
|
36
|
+
"@histoire/app": "^0.13.1",
|
|
37
|
+
"@histoire/controls": "^0.13.1",
|
|
38
|
+
"@histoire/shared": "^0.13.1",
|
|
39
|
+
"@histoire/vendors": "^0.13.1",
|
|
40
40
|
"@types/flexsearch": "^0.7.3",
|
|
41
41
|
"@types/markdown-it": "^12.2.3",
|
|
42
42
|
"birpc": "^0.1.1",
|
|
@@ -60,10 +60,10 @@
|
|
|
60
60
|
"pathe": "^0.2.0",
|
|
61
61
|
"picocolors": "^1.0.0",
|
|
62
62
|
"sade": "^1.8.1",
|
|
63
|
-
"shiki-es": "^0.
|
|
63
|
+
"shiki-es": "^0.2.0",
|
|
64
64
|
"sirv": "^2.0.2",
|
|
65
65
|
"tinypool": "^0.1.2",
|
|
66
|
-
"vite-node": "0.
|
|
66
|
+
"vite-node": "0.28.4"
|
|
67
67
|
},
|
|
68
68
|
"peerDependencies": {
|
|
69
69
|
"vite": "^2.9.0 || ^3.0.0 || ^4.0.0"
|
|
@@ -76,8 +76,8 @@
|
|
|
76
76
|
"@types/micromatch": "^4.0.2",
|
|
77
77
|
"@types/node": "^17.0.32",
|
|
78
78
|
"rollup": "^3.5.1",
|
|
79
|
-
"typescript": "^4.
|
|
80
|
-
"vite": "^4.
|
|
79
|
+
"typescript": "^4.9.5",
|
|
80
|
+
"vite": "^4.1.0"
|
|
81
81
|
},
|
|
82
82
|
"scripts": {
|
|
83
83
|
"build": "rimraf dist && tsc -d",
|
package/src/node/build.ts
CHANGED
|
@@ -86,13 +86,6 @@ export async function build (ctx: Context) {
|
|
|
86
86
|
join(APP_PATH, 'bundle-main.js'),
|
|
87
87
|
join(APP_PATH, 'bundle-sandbox.js'),
|
|
88
88
|
],
|
|
89
|
-
output: {
|
|
90
|
-
manualChunks (id) {
|
|
91
|
-
if (!id.includes('@histoire/app') && id.includes('node_modules')) {
|
|
92
|
-
return 'vendor'
|
|
93
|
-
}
|
|
94
|
-
},
|
|
95
|
-
},
|
|
96
89
|
plugins: [
|
|
97
90
|
{
|
|
98
91
|
name: 'histoire-build-rollup-options-override',
|
|
@@ -104,10 +97,6 @@ export async function build (ctx: Context) {
|
|
|
104
97
|
},
|
|
105
98
|
],
|
|
106
99
|
},
|
|
107
|
-
outDir: ctx.config.outDir,
|
|
108
|
-
emptyOutDir: true,
|
|
109
|
-
cssCodeSplit: false,
|
|
110
|
-
minify: false,
|
|
111
100
|
},
|
|
112
101
|
})
|
|
113
102
|
|
|
@@ -145,6 +134,25 @@ export async function build (ctx: Context) {
|
|
|
145
134
|
config (config) {
|
|
146
135
|
// Don't externalize
|
|
147
136
|
config.build.rollupOptions.external = []
|
|
137
|
+
|
|
138
|
+
// Force chunk strategy
|
|
139
|
+
config.build.rollupOptions.output = {
|
|
140
|
+
manualChunks (id) {
|
|
141
|
+
if (!id.includes('@histoire/app') && id.includes('node_modules')) {
|
|
142
|
+
return 'vendor'
|
|
143
|
+
}
|
|
144
|
+
},
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
// Force vite build options
|
|
148
|
+
Object.assign(config.build, {
|
|
149
|
+
outDir: ctx.config.outDir,
|
|
150
|
+
emptyOutDir: true,
|
|
151
|
+
cssCodeSplit: false,
|
|
152
|
+
minify: false,
|
|
153
|
+
// Don't build in SSR mode
|
|
154
|
+
ssr: false,
|
|
155
|
+
})
|
|
148
156
|
},
|
|
149
157
|
})
|
|
150
158
|
|