histoire 0.0.4 → 0.1.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 +23 -3
- package/dist/node/config.js +4 -1
- package/dist/node/plugin.js +8 -2
- package/package.json +4 -4
- package/src/node/build.ts +28 -3
- package/src/node/config.ts +4 -1
- package/src/node/plugin.ts +9 -2
package/dist/node/build.js
CHANGED
|
@@ -8,6 +8,14 @@ import { APP_PATH } from './alias.js';
|
|
|
8
8
|
import { createVitePlugins } from './plugin.js';
|
|
9
9
|
import { findAllStories } from './stories.js';
|
|
10
10
|
import { useCollectStories } from './collect.js';
|
|
11
|
+
const PRELOAD_MODULES = [
|
|
12
|
+
'vendor',
|
|
13
|
+
];
|
|
14
|
+
const PREFETCHED_MODULES = [
|
|
15
|
+
'StoryView',
|
|
16
|
+
'reactivity',
|
|
17
|
+
'global-components',
|
|
18
|
+
];
|
|
11
19
|
export async function build(ctx) {
|
|
12
20
|
const startTime = performance.now();
|
|
13
21
|
await findAllStories(ctx);
|
|
@@ -44,19 +52,27 @@ export async function build(ctx) {
|
|
|
44
52
|
});
|
|
45
53
|
const result = Array.isArray(results) ? results[0] : results;
|
|
46
54
|
const styleOutput = result.output.find(o => o.name === 'style.css' && o.type === 'asset');
|
|
55
|
+
// Preload
|
|
56
|
+
const preloadOutputs = result.output.filter(o => PRELOAD_MODULES.includes(o.name) && o.type === 'chunk');
|
|
57
|
+
const preloadHtml = generateScriptLinks(preloadOutputs.map(o => o.fileName), 'preload');
|
|
58
|
+
// Prefetch
|
|
59
|
+
const prefetchOutputs = result.output.filter(o => PREFETCHED_MODULES.includes(o.name) && o.type === 'chunk');
|
|
60
|
+
const prefetchHtml = generateScriptLinks(prefetchOutputs.map(o => o.fileName), 'prefetch');
|
|
47
61
|
// Index
|
|
48
62
|
const indexOutput = result.output.find(o => o.name === 'index' && o.type === 'chunk');
|
|
49
|
-
await writeHtml(indexOutput.fileName, styleOutput.fileName, 'index.html',
|
|
63
|
+
await writeHtml(indexOutput.fileName, styleOutput.fileName, 'index.html', {
|
|
64
|
+
HEAD: `${preloadHtml}${prefetchHtml}`,
|
|
65
|
+
}, ctx);
|
|
50
66
|
// Sandbox
|
|
51
67
|
const sandboxOutput = result.output.find(o => o.name === 'sandbox' && o.type === 'chunk');
|
|
52
|
-
await writeHtml(sandboxOutput.fileName, styleOutput.fileName, '__sandbox.html', ctx);
|
|
68
|
+
await writeHtml(sandboxOutput.fileName, styleOutput.fileName, '__sandbox.html', {}, ctx);
|
|
53
69
|
const duration = performance.now() - startTime;
|
|
54
70
|
if (emptyStoryCount) {
|
|
55
71
|
console.warn(pc.yellow(`⚠️ ${emptyStoryCount} empty story file`));
|
|
56
72
|
}
|
|
57
73
|
console.log(pc.green(`✅ Built ${storyCount} stories (${variantCount} variants) in ${Math.round(duration / 1000 * 100) / 100}s`));
|
|
58
74
|
}
|
|
59
|
-
async function writeHtml(jsEntryFile, cssEntryFile, htmlFileName, ctx) {
|
|
75
|
+
async function writeHtml(jsEntryFile, cssEntryFile, htmlFileName, variables, ctx) {
|
|
60
76
|
const code = `<!DOCTYPE html>
|
|
61
77
|
<html>
|
|
62
78
|
<head>
|
|
@@ -66,6 +82,7 @@ async function writeHtml(jsEntryFile, cssEntryFile, htmlFileName, ctx) {
|
|
|
66
82
|
<meta name="description" content="">
|
|
67
83
|
<link rel="stylesheet" href="/${cssEntryFile}">
|
|
68
84
|
${ctx.config.theme?.favicon ? `<link rel="icon" type="${lookupMime(ctx.config.theme.favicon)}" href="${ctx.config.theme.favicon}"/>` : ''}
|
|
85
|
+
${variables.HEAD ?? ''}
|
|
69
86
|
</head>
|
|
70
87
|
<body>
|
|
71
88
|
<div id="app"></div>
|
|
@@ -74,3 +91,6 @@ async function writeHtml(jsEntryFile, cssEntryFile, htmlFileName, ctx) {
|
|
|
74
91
|
</html>`;
|
|
75
92
|
await fs.writeFile(join(ctx.config.outDir, htmlFileName), code, 'utf8');
|
|
76
93
|
}
|
|
94
|
+
function generateScriptLinks(prefetchScripts, rel) {
|
|
95
|
+
return prefetchScripts.map(s => `<link rel="${rel}" href="${s}" as="script" crossOrigin="anonymous">`).join('');
|
|
96
|
+
}
|
package/dist/node/config.js
CHANGED
|
@@ -10,7 +10,10 @@ export function getDefaultConfig() {
|
|
|
10
10
|
return {
|
|
11
11
|
outDir: 'histoire-dist',
|
|
12
12
|
storyMatch: ['**/*.story.vue'],
|
|
13
|
-
storyIgnored: [
|
|
13
|
+
storyIgnored: [
|
|
14
|
+
'**/node_modules/**',
|
|
15
|
+
'**/dist/**',
|
|
16
|
+
],
|
|
14
17
|
tree: {
|
|
15
18
|
file: 'title',
|
|
16
19
|
order: 'asc',
|
package/dist/node/plugin.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { createRequire } from 'module';
|
|
2
|
+
import { relative, dirname } from 'pathe';
|
|
2
3
|
import { resolveConfig as resolveViteConfig } from 'vite';
|
|
3
4
|
import { lookup as lookupMime } from 'mrmime';
|
|
4
5
|
import { APP_PATH, DIST_CLIENT_PATH } from './alias.js';
|
|
@@ -6,6 +7,7 @@ import { notifyStoryChange } from './stories.js';
|
|
|
6
7
|
import { makeTree } from './tree.js';
|
|
7
8
|
import { parseColor } from './colors.js';
|
|
8
9
|
import { createMarkdownRenderer } from './markdown.js';
|
|
10
|
+
const require = createRequire(import.meta.url);
|
|
9
11
|
export const STORIES_ID = '$histoire-stories';
|
|
10
12
|
export const RESOLVED_STORIES_ID = `/${STORIES_ID}-resolved`;
|
|
11
13
|
export const SETUP_ID = '$histoire-setup';
|
|
@@ -37,7 +39,11 @@ export async function createVitePlugins(ctx) {
|
|
|
37
39
|
// force include vue to avoid duplicated copies when linked + optimized
|
|
38
40
|
include: [
|
|
39
41
|
'vue',
|
|
40
|
-
'@vue/runtime-core',
|
|
42
|
+
dirname(require.resolve('@vue/runtime-core/package.json')),
|
|
43
|
+
dirname(require.resolve('shiki/package.json')),
|
|
44
|
+
dirname(require.resolve('vscode-textmate/package.json')),
|
|
45
|
+
dirname(require.resolve('vscode-oniguruma/package.json')),
|
|
46
|
+
dirname(require.resolve('case/package.json')),
|
|
41
47
|
],
|
|
42
48
|
},
|
|
43
49
|
server: {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "histoire",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.1.1",
|
|
4
4
|
"description": "A fast story book powered by Vite",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": {
|
|
@@ -33,7 +33,8 @@
|
|
|
33
33
|
"histoire": "./bin.mjs"
|
|
34
34
|
},
|
|
35
35
|
"dependencies": {
|
|
36
|
-
"@
|
|
36
|
+
"@iconify/vue": "^3.1.3",
|
|
37
|
+
"@histoire/controls": "^0.1.1",
|
|
37
38
|
"@vitejs/plugin-vue": "^2.2.0",
|
|
38
39
|
"@vueuse/core": "^7.6.2",
|
|
39
40
|
"case": "^1.6.3",
|
|
@@ -59,11 +60,11 @@
|
|
|
59
60
|
"vue-router": "^4.0.12"
|
|
60
61
|
},
|
|
61
62
|
"peerDependencies": {
|
|
63
|
+
"@vue/runtime-core": "^3.2.31",
|
|
62
64
|
"vite": "^2.8.3",
|
|
63
65
|
"vue": "^3.2.31"
|
|
64
66
|
},
|
|
65
67
|
"devDependencies": {
|
|
66
|
-
"@iconify/vue": "^3.1.3",
|
|
67
68
|
"@peeky/test": "^0.13.5",
|
|
68
69
|
"@tailwindcss/typography": "^0.5.2",
|
|
69
70
|
"@types/fs-extra": "^9.0.13",
|
|
@@ -71,7 +72,6 @@
|
|
|
71
72
|
"@types/node": "^17.0.18",
|
|
72
73
|
"autoprefixer": "^10.4.2",
|
|
73
74
|
"concurrently": "^7.0.0",
|
|
74
|
-
"globby": "^13.1.1",
|
|
75
75
|
"postcss": "^8.4.6",
|
|
76
76
|
"postcss-import": "^14.0.2",
|
|
77
77
|
"tailwindcss": "^3.0.23",
|
package/src/node/build.ts
CHANGED
|
@@ -11,6 +11,16 @@ import { findAllStories } from './stories.js'
|
|
|
11
11
|
import type { RollupOutput } from 'rollup'
|
|
12
12
|
import { useCollectStories } from './collect.js'
|
|
13
13
|
|
|
14
|
+
const PRELOAD_MODULES = [
|
|
15
|
+
'vendor',
|
|
16
|
+
]
|
|
17
|
+
|
|
18
|
+
const PREFETCHED_MODULES = [
|
|
19
|
+
'StoryView',
|
|
20
|
+
'reactivity',
|
|
21
|
+
'global-components',
|
|
22
|
+
]
|
|
23
|
+
|
|
14
24
|
export async function build (ctx: Context) {
|
|
15
25
|
const startTime = performance.now()
|
|
16
26
|
await findAllStories(ctx)
|
|
@@ -52,13 +62,23 @@ export async function build (ctx: Context) {
|
|
|
52
62
|
|
|
53
63
|
const styleOutput = result.output.find(o => o.name === 'style.css' && o.type === 'asset')
|
|
54
64
|
|
|
65
|
+
// Preload
|
|
66
|
+
const preloadOutputs = result.output.filter(o => PRELOAD_MODULES.includes(o.name) && o.type === 'chunk')
|
|
67
|
+
const preloadHtml = generateScriptLinks(preloadOutputs.map(o => o.fileName), 'preload')
|
|
68
|
+
|
|
69
|
+
// Prefetch
|
|
70
|
+
const prefetchOutputs = result.output.filter(o => PREFETCHED_MODULES.includes(o.name) && o.type === 'chunk')
|
|
71
|
+
const prefetchHtml = generateScriptLinks(prefetchOutputs.map(o => o.fileName), 'prefetch')
|
|
72
|
+
|
|
55
73
|
// Index
|
|
56
74
|
const indexOutput = result.output.find(o => o.name === 'index' && o.type === 'chunk')
|
|
57
|
-
await writeHtml(indexOutput.fileName, styleOutput.fileName, 'index.html',
|
|
75
|
+
await writeHtml(indexOutput.fileName, styleOutput.fileName, 'index.html', {
|
|
76
|
+
HEAD: `${preloadHtml}${prefetchHtml}`,
|
|
77
|
+
}, ctx)
|
|
58
78
|
|
|
59
79
|
// Sandbox
|
|
60
80
|
const sandboxOutput = result.output.find(o => o.name === 'sandbox' && o.type === 'chunk')
|
|
61
|
-
await writeHtml(sandboxOutput.fileName, styleOutput.fileName, '__sandbox.html', ctx)
|
|
81
|
+
await writeHtml(sandboxOutput.fileName, styleOutput.fileName, '__sandbox.html', {}, ctx)
|
|
62
82
|
|
|
63
83
|
const duration = performance.now() - startTime
|
|
64
84
|
if (emptyStoryCount) {
|
|
@@ -67,7 +87,7 @@ export async function build (ctx: Context) {
|
|
|
67
87
|
console.log(pc.green(`✅ Built ${storyCount} stories (${variantCount} variants) in ${Math.round(duration / 1000 * 100) / 100}s`))
|
|
68
88
|
}
|
|
69
89
|
|
|
70
|
-
async function writeHtml (jsEntryFile: string, cssEntryFile: string, htmlFileName: string, ctx: Context) {
|
|
90
|
+
async function writeHtml (jsEntryFile: string, cssEntryFile: string, htmlFileName: string, variables: { HEAD?: string }, ctx: Context) {
|
|
71
91
|
const code = `<!DOCTYPE html>
|
|
72
92
|
<html>
|
|
73
93
|
<head>
|
|
@@ -77,6 +97,7 @@ async function writeHtml (jsEntryFile: string, cssEntryFile: string, htmlFileNam
|
|
|
77
97
|
<meta name="description" content="">
|
|
78
98
|
<link rel="stylesheet" href="/${cssEntryFile}">
|
|
79
99
|
${ctx.config.theme?.favicon ? `<link rel="icon" type="${lookupMime(ctx.config.theme.favicon)}" href="${ctx.config.theme.favicon}"/>` : ''}
|
|
100
|
+
${variables.HEAD ?? ''}
|
|
80
101
|
</head>
|
|
81
102
|
<body>
|
|
82
103
|
<div id="app"></div>
|
|
@@ -85,3 +106,7 @@ async function writeHtml (jsEntryFile: string, cssEntryFile: string, htmlFileNam
|
|
|
85
106
|
</html>`
|
|
86
107
|
await fs.writeFile(join(ctx.config.outDir, htmlFileName), code, 'utf8')
|
|
87
108
|
}
|
|
109
|
+
|
|
110
|
+
function generateScriptLinks (prefetchScripts: string[], rel: string) {
|
|
111
|
+
return prefetchScripts.map(s => `<link rel="${rel}" href="${s}" as="script" crossOrigin="anonymous">`).join('')
|
|
112
|
+
}
|
package/src/node/config.ts
CHANGED
|
@@ -135,7 +135,10 @@ export function getDefaultConfig (): HistoireConfig {
|
|
|
135
135
|
return {
|
|
136
136
|
outDir: 'histoire-dist',
|
|
137
137
|
storyMatch: ['**/*.story.vue'],
|
|
138
|
-
storyIgnored: [
|
|
138
|
+
storyIgnored: [
|
|
139
|
+
'**/node_modules/**',
|
|
140
|
+
'**/dist/**',
|
|
141
|
+
],
|
|
139
142
|
tree: {
|
|
140
143
|
file: 'title',
|
|
141
144
|
order: 'asc',
|
package/src/node/plugin.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { createRequire } from 'module'
|
|
2
|
+
import { relative, dirname } from 'pathe'
|
|
2
3
|
import { resolveConfig as resolveViteConfig, Plugin as VitePlugin } from 'vite'
|
|
3
4
|
import { lookup as lookupMime } from 'mrmime'
|
|
4
5
|
import { APP_PATH, DIST_CLIENT_PATH } from './alias.js'
|
|
@@ -8,6 +9,8 @@ import { makeTree } from './tree.js'
|
|
|
8
9
|
import { parseColor } from './colors.js'
|
|
9
10
|
import { createMarkdownRenderer } from './markdown.js'
|
|
10
11
|
|
|
12
|
+
const require = createRequire(import.meta.url)
|
|
13
|
+
|
|
11
14
|
export const STORIES_ID = '$histoire-stories'
|
|
12
15
|
export const RESOLVED_STORIES_ID = `/${STORIES_ID}-resolved`
|
|
13
16
|
export const SETUP_ID = '$histoire-setup'
|
|
@@ -45,7 +48,11 @@ export async function createVitePlugins (ctx: Context): Promise<VitePlugin[]> {
|
|
|
45
48
|
// force include vue to avoid duplicated copies when linked + optimized
|
|
46
49
|
include: [
|
|
47
50
|
'vue',
|
|
48
|
-
'@vue/runtime-core',
|
|
51
|
+
dirname(require.resolve('@vue/runtime-core/package.json')),
|
|
52
|
+
dirname(require.resolve('shiki/package.json')),
|
|
53
|
+
dirname(require.resolve('vscode-textmate/package.json')),
|
|
54
|
+
dirname(require.resolve('vscode-oniguruma/package.json')),
|
|
55
|
+
dirname(require.resolve('case/package.json')),
|
|
49
56
|
],
|
|
50
57
|
},
|
|
51
58
|
server: {
|