histoire 0.14.2 → 0.15.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 +13 -0
- package/dist/node/commands/preview.js +5 -0
- package/dist/node/config.d.ts +9 -0
- package/dist/node/config.js +13 -0
- package/dist/node/plugin.d.ts +3 -1
- package/dist/node/plugin.js +4 -0
- package/dist/node/vite.js +1 -0
- package/package.json +5 -5
- package/src/node/build.ts +20 -0
- package/src/node/commands/preview.ts +6 -0
- package/src/node/config.ts +15 -0
- package/src/node/plugin.ts +6 -0
- package/src/node/vite.ts +1 -0
package/dist/node/build.js
CHANGED
|
@@ -36,12 +36,14 @@ export async function build(ctx) {
|
|
|
36
36
|
server,
|
|
37
37
|
throws: true,
|
|
38
38
|
});
|
|
39
|
+
const changeViteConfigCallbacks = [];
|
|
39
40
|
const buildEndCallbacks = [];
|
|
40
41
|
const previewStoryCallbacks = [];
|
|
41
42
|
for (const plugin of ctx.config.plugins) {
|
|
42
43
|
if (plugin.onBuild) {
|
|
43
44
|
const api = new BuildPluginApi(ctx, plugin, moduleLoader);
|
|
44
45
|
await plugin.onBuild(api);
|
|
46
|
+
changeViteConfigCallbacks.push(...api.changeViteConfigCallbacks);
|
|
45
47
|
buildEndCallbacks.push(...api.buildEndCallbacks);
|
|
46
48
|
previewStoryCallbacks.push(...api.previewStoryCallbacks);
|
|
47
49
|
}
|
|
@@ -116,6 +118,12 @@ export async function build(ctx) {
|
|
|
116
118
|
config.build.rollupOptions.output = {
|
|
117
119
|
manualChunks(id) {
|
|
118
120
|
if (!id.includes('@histoire/app') && id.includes('node_modules')) {
|
|
121
|
+
for (const test of ctx.config.build?.excludeFromVendorsChunk ?? []) {
|
|
122
|
+
if ((typeof test === 'string' && id.includes(test)) || (test instanceof RegExp && test.test(id))) {
|
|
123
|
+
// Excluded from vendor chunk
|
|
124
|
+
return;
|
|
125
|
+
}
|
|
126
|
+
}
|
|
119
127
|
return 'vendor';
|
|
120
128
|
}
|
|
121
129
|
},
|
|
@@ -129,8 +137,13 @@ export async function build(ctx) {
|
|
|
129
137
|
// Don't build in SSR mode
|
|
130
138
|
ssr: false,
|
|
131
139
|
});
|
|
140
|
+
config.define.__HST_COLLECT__ = false;
|
|
132
141
|
},
|
|
133
142
|
});
|
|
143
|
+
for (const cb of changeViteConfigCallbacks) {
|
|
144
|
+
console.log('vite config hook', cb);
|
|
145
|
+
await cb(buildViteConfig);
|
|
146
|
+
}
|
|
134
147
|
const results = await viteBuild(buildViteConfig);
|
|
135
148
|
const result = Array.isArray(results) ? results[0] : results;
|
|
136
149
|
const styleOutput = result.output.find(o => o.name === 'style.css' && o.type === 'asset');
|
|
@@ -5,6 +5,11 @@ export async function previewCommand(options) {
|
|
|
5
5
|
const ctx = await createContext({
|
|
6
6
|
mode: 'build',
|
|
7
7
|
});
|
|
8
|
+
for (const plugin of ctx.config.plugins) {
|
|
9
|
+
if (plugin.onPreview) {
|
|
10
|
+
await plugin.onPreview();
|
|
11
|
+
}
|
|
12
|
+
}
|
|
8
13
|
const { baseUrl } = await startPreview(options.port, ctx);
|
|
9
14
|
console.log(`Preview server listening on ${pc.cyan(baseUrl)}`);
|
|
10
15
|
}
|
package/dist/node/config.d.ts
CHANGED
|
@@ -4,6 +4,15 @@ export declare function getDefaultConfig(): HistoireConfig;
|
|
|
4
4
|
export declare const configFileNames: string[];
|
|
5
5
|
export declare function resolveConfigFile(cwd?: string): string;
|
|
6
6
|
export declare function loadConfigFile(configFile: string): Promise<Partial<HistoireConfig>>;
|
|
7
|
+
export declare const mergeBuildConfig: <Source extends {
|
|
8
|
+
[x: string]: any;
|
|
9
|
+
[x: number]: any;
|
|
10
|
+
[x: symbol]: any;
|
|
11
|
+
}, Defaults extends ({
|
|
12
|
+
[x: string]: any;
|
|
13
|
+
[x: number]: any;
|
|
14
|
+
[x: symbol]: any;
|
|
15
|
+
} | (number | boolean | any[] | Record<never, any>))[]>(source: Source, ...defaults: Defaults) => import("defu").Defu<Source, Defaults>;
|
|
7
16
|
export declare const mergeConfig: <Source extends {
|
|
8
17
|
[x: string]: any;
|
|
9
18
|
[x: number]: any;
|
package/dist/node/config.js
CHANGED
|
@@ -111,6 +111,9 @@ export function getDefaultConfig() {
|
|
|
111
111
|
],
|
|
112
112
|
sandboxDarkClass: 'dark',
|
|
113
113
|
routerMode: 'history',
|
|
114
|
+
build: {
|
|
115
|
+
excludeFromVendorsChunk: [],
|
|
116
|
+
},
|
|
114
117
|
vite: (config) => {
|
|
115
118
|
// Remove vite:legacy plugins https://github.com/histoire-dev/histoire/issues/156
|
|
116
119
|
const index = config.plugins?.findIndex(plugin => Array.isArray(plugin) &&
|
|
@@ -155,6 +158,12 @@ export async function loadConfigFile(configFile) {
|
|
|
155
158
|
throw e;
|
|
156
159
|
}
|
|
157
160
|
}
|
|
161
|
+
export const mergeBuildConfig = createDefu((obj, key, value) => {
|
|
162
|
+
if (obj[key] && key === 'excludeFromVendorsChunk') {
|
|
163
|
+
obj[key] = [...obj[key], ...value];
|
|
164
|
+
return true;
|
|
165
|
+
}
|
|
166
|
+
});
|
|
158
167
|
export const mergeConfig = createDefu((obj, key, value) => {
|
|
159
168
|
if (obj[key] && key === 'vite') {
|
|
160
169
|
const initialValue = obj[key];
|
|
@@ -200,6 +209,10 @@ export const mergeConfig = createDefu((obj, key, value) => {
|
|
|
200
209
|
}
|
|
201
210
|
return true;
|
|
202
211
|
}
|
|
212
|
+
if (obj[key] && key === 'build') {
|
|
213
|
+
obj[key] = mergeBuildConfig(obj[key], value);
|
|
214
|
+
return true;
|
|
215
|
+
}
|
|
203
216
|
// By default, arrays should be replaced
|
|
204
217
|
if (obj[key] && Array.isArray(obj[key])) {
|
|
205
218
|
obj[key] = value;
|
package/dist/node/plugin.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
2
|
import chokidar from 'chokidar';
|
|
3
3
|
import fs from 'fs-extra';
|
|
4
|
-
import type { Plugin, PluginApiBase, PluginApiDev, PluginApiBuild, BuildEndCallback, PreviewStoryCallback, ModuleLoader, ServerStory, PluginApiDevEvent, HistoireConfig } from '@histoire/shared';
|
|
4
|
+
import type { Plugin, PluginApiBase, PluginApiDev, PluginApiBuild, ChangeViteConfigCallback, BuildEndCallback, PreviewStoryCallback, ModuleLoader, ServerStory, PluginApiDevEvent, HistoireConfig } from '@histoire/shared';
|
|
5
5
|
import type { Context } from './context.js';
|
|
6
6
|
export declare class BasePluginApi implements PluginApiBase {
|
|
7
7
|
protected ctx: Context;
|
|
@@ -25,8 +25,10 @@ export declare class DevPluginApi extends BasePluginApi implements PluginApiDev
|
|
|
25
25
|
watcher: typeof chokidar;
|
|
26
26
|
}
|
|
27
27
|
export declare class BuildPluginApi extends BasePluginApi implements PluginApiBuild {
|
|
28
|
+
changeViteConfigCallbacks: ChangeViteConfigCallback[];
|
|
28
29
|
buildEndCallbacks: BuildEndCallback[];
|
|
29
30
|
previewStoryCallbacks: PreviewStoryCallback[];
|
|
31
|
+
changeViteConfig(cb: ChangeViteConfigCallback): void;
|
|
30
32
|
onBuildEnd(cb: BuildEndCallback): void;
|
|
31
33
|
onPreviewStory(cb: PreviewStoryCallback): void;
|
|
32
34
|
}
|
package/dist/node/plugin.js
CHANGED
|
@@ -44,8 +44,12 @@ export class DevPluginApi extends BasePluginApi {
|
|
|
44
44
|
watcher = chokidar;
|
|
45
45
|
}
|
|
46
46
|
export class BuildPluginApi extends BasePluginApi {
|
|
47
|
+
changeViteConfigCallbacks = [];
|
|
47
48
|
buildEndCallbacks = [];
|
|
48
49
|
previewStoryCallbacks = [];
|
|
50
|
+
changeViteConfig(cb) {
|
|
51
|
+
this.changeViteConfigCallbacks.push(cb);
|
|
52
|
+
}
|
|
49
53
|
onBuildEnd(cb) {
|
|
50
54
|
this.buildEndCallbacks.push(cb);
|
|
51
55
|
}
|
package/dist/node/vite.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "histoire",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.15.1",
|
|
4
4
|
"description": "A fast story book powered by Vite",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": {
|
|
@@ -37,10 +37,10 @@
|
|
|
37
37
|
"histoire": "./bin.mjs"
|
|
38
38
|
},
|
|
39
39
|
"dependencies": {
|
|
40
|
-
"@histoire/app": "^0.
|
|
41
|
-
"@histoire/controls": "^0.
|
|
42
|
-
"@histoire/shared": "^0.
|
|
43
|
-
"@histoire/vendors": "^0.
|
|
40
|
+
"@histoire/app": "^0.15.1",
|
|
41
|
+
"@histoire/controls": "^0.15.1",
|
|
42
|
+
"@histoire/shared": "^0.15.1",
|
|
43
|
+
"@histoire/vendors": "^0.15.1",
|
|
44
44
|
"@types/flexsearch": "^0.7.3",
|
|
45
45
|
"@types/markdown-it": "^12.2.3",
|
|
46
46
|
"birpc": "^0.1.1",
|
package/src/node/build.ts
CHANGED
|
@@ -11,6 +11,7 @@ import { lookup as lookupMime } from 'mrmime'
|
|
|
11
11
|
import pc from 'picocolors'
|
|
12
12
|
import { performance } from 'node:perf_hooks'
|
|
13
13
|
import type {
|
|
14
|
+
ChangeViteConfigCallback,
|
|
14
15
|
BuildEndCallback,
|
|
15
16
|
PreviewStoryCallback,
|
|
16
17
|
} from '@histoire/shared'
|
|
@@ -54,12 +55,14 @@ export async function build (ctx: Context) {
|
|
|
54
55
|
server,
|
|
55
56
|
throws: true,
|
|
56
57
|
})
|
|
58
|
+
const changeViteConfigCallbacks: ChangeViteConfigCallback[] = []
|
|
57
59
|
const buildEndCallbacks: BuildEndCallback[] = []
|
|
58
60
|
const previewStoryCallbacks: PreviewStoryCallback[] = []
|
|
59
61
|
for (const plugin of ctx.config.plugins) {
|
|
60
62
|
if (plugin.onBuild) {
|
|
61
63
|
const api = new BuildPluginApi(ctx, plugin, moduleLoader)
|
|
62
64
|
await plugin.onBuild(api)
|
|
65
|
+
changeViteConfigCallbacks.push(...api.changeViteConfigCallbacks)
|
|
63
66
|
buildEndCallbacks.push(...api.buildEndCallbacks)
|
|
64
67
|
previewStoryCallbacks.push(...api.previewStoryCallbacks)
|
|
65
68
|
}
|
|
@@ -140,6 +143,16 @@ export async function build (ctx: Context) {
|
|
|
140
143
|
config.build.rollupOptions.output = {
|
|
141
144
|
manualChunks (id) {
|
|
142
145
|
if (!id.includes('@histoire/app') && id.includes('node_modules')) {
|
|
146
|
+
for (const test of ctx.config.build?.excludeFromVendorsChunk ?? []) {
|
|
147
|
+
if ((
|
|
148
|
+
typeof test === 'string' && id.includes(test)
|
|
149
|
+
) || (
|
|
150
|
+
test instanceof RegExp && test.test(id)
|
|
151
|
+
)) {
|
|
152
|
+
// Excluded from vendor chunk
|
|
153
|
+
return
|
|
154
|
+
}
|
|
155
|
+
}
|
|
143
156
|
return 'vendor'
|
|
144
157
|
}
|
|
145
158
|
},
|
|
@@ -154,9 +167,16 @@ export async function build (ctx: Context) {
|
|
|
154
167
|
// Don't build in SSR mode
|
|
155
168
|
ssr: false,
|
|
156
169
|
})
|
|
170
|
+
|
|
171
|
+
config.define.__HST_COLLECT__ = false
|
|
157
172
|
},
|
|
158
173
|
})
|
|
159
174
|
|
|
175
|
+
for (const cb of changeViteConfigCallbacks) {
|
|
176
|
+
console.log('vite config hook', cb)
|
|
177
|
+
await cb(buildViteConfig)
|
|
178
|
+
}
|
|
179
|
+
|
|
160
180
|
const results = await viteBuild(buildViteConfig)
|
|
161
181
|
const result = Array.isArray(results) ? results[0] : results as RollupOutput
|
|
162
182
|
|
|
@@ -11,6 +11,12 @@ export async function previewCommand (options: PreviewOptions) {
|
|
|
11
11
|
mode: 'build',
|
|
12
12
|
})
|
|
13
13
|
|
|
14
|
+
for (const plugin of ctx.config.plugins) {
|
|
15
|
+
if (plugin.onPreview) {
|
|
16
|
+
await plugin.onPreview()
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
|
|
14
20
|
const { baseUrl } = await startPreview(options.port, ctx)
|
|
15
21
|
console.log(`Preview server listening on ${pc.cyan(baseUrl)}`)
|
|
16
22
|
}
|
package/src/node/config.ts
CHANGED
|
@@ -123,6 +123,9 @@ export function getDefaultConfig (): HistoireConfig {
|
|
|
123
123
|
],
|
|
124
124
|
sandboxDarkClass: 'dark',
|
|
125
125
|
routerMode: 'history',
|
|
126
|
+
build: {
|
|
127
|
+
excludeFromVendorsChunk: [],
|
|
128
|
+
},
|
|
126
129
|
vite: (config) => {
|
|
127
130
|
// Remove vite:legacy plugins https://github.com/histoire-dev/histoire/issues/156
|
|
128
131
|
const index = config.plugins?.findIndex(plugin => Array.isArray(plugin) &&
|
|
@@ -171,6 +174,13 @@ export async function loadConfigFile (configFile: string): Promise<Partial<Histo
|
|
|
171
174
|
}
|
|
172
175
|
}
|
|
173
176
|
|
|
177
|
+
export const mergeBuildConfig = createDefu((obj: any, key, value) => {
|
|
178
|
+
if (obj[key] && key === 'excludeFromVendorsChunk') {
|
|
179
|
+
obj[key] = [...obj[key], ...value]
|
|
180
|
+
return true
|
|
181
|
+
}
|
|
182
|
+
})
|
|
183
|
+
|
|
174
184
|
export const mergeConfig = createDefu((obj: any, key, value) => {
|
|
175
185
|
if (obj[key] && key === 'vite') {
|
|
176
186
|
const initialValue = obj[key]
|
|
@@ -218,6 +228,11 @@ export const mergeConfig = createDefu((obj: any, key, value) => {
|
|
|
218
228
|
return true
|
|
219
229
|
}
|
|
220
230
|
|
|
231
|
+
if (obj[key] && key === 'build') {
|
|
232
|
+
obj[key] = mergeBuildConfig(obj[key], value)
|
|
233
|
+
return true
|
|
234
|
+
}
|
|
235
|
+
|
|
221
236
|
// By default, arrays should be replaced
|
|
222
237
|
if (obj[key] && Array.isArray(obj[key])) {
|
|
223
238
|
obj[key] = value
|
package/src/node/plugin.ts
CHANGED
|
@@ -7,6 +7,7 @@ import type {
|
|
|
7
7
|
PluginApiBase,
|
|
8
8
|
PluginApiDev,
|
|
9
9
|
PluginApiBuild,
|
|
10
|
+
ChangeViteConfigCallback,
|
|
10
11
|
BuildEndCallback,
|
|
11
12
|
PreviewStoryCallback,
|
|
12
13
|
ModuleLoader,
|
|
@@ -65,9 +66,14 @@ export class DevPluginApi extends BasePluginApi implements PluginApiDev {
|
|
|
65
66
|
}
|
|
66
67
|
|
|
67
68
|
export class BuildPluginApi extends BasePluginApi implements PluginApiBuild {
|
|
69
|
+
changeViteConfigCallbacks: ChangeViteConfigCallback[] = []
|
|
68
70
|
buildEndCallbacks: BuildEndCallback[] = []
|
|
69
71
|
previewStoryCallbacks: PreviewStoryCallback[] = []
|
|
70
72
|
|
|
73
|
+
changeViteConfig (cb: ChangeViteConfigCallback) {
|
|
74
|
+
this.changeViteConfigCallbacks.push(cb)
|
|
75
|
+
}
|
|
76
|
+
|
|
71
77
|
onBuildEnd (cb: BuildEndCallback) {
|
|
72
78
|
this.buildEndCallbacks.push(cb)
|
|
73
79
|
}
|
package/src/node/vite.ts
CHANGED
|
@@ -151,6 +151,7 @@ export async function getViteConfigWithPlugins (isServer: boolean, ctx: Context)
|
|
|
151
151
|
'process.env.HST_COLLECT': 'false',
|
|
152
152
|
}
|
|
153
153
|
: {},
|
|
154
|
+
__HST_COLLECT__: isServer,
|
|
154
155
|
},
|
|
155
156
|
cacheDir: isServer ? 'node_modules/.hst-vite-server' : 'node_modules/.hst-vite',
|
|
156
157
|
}
|