minista 2.7.4 → 2.8.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/README.md +11 -1
- package/dist/app.js +1 -0
- package/dist/beautify.js +1 -0
- package/dist/build.d.ts +56 -14
- package/dist/build.js +146 -57
- package/dist/bundle.js +1 -0
- package/dist/cli.js +4 -19
- package/dist/comment.js +1 -0
- package/dist/config.d.ts +2 -1
- package/dist/config.js +93 -25
- package/dist/css.js +13 -24
- package/dist/define.js +1 -0
- package/dist/download.js +9 -2
- package/dist/empty.js +1 -0
- package/dist/esbuild.js +2 -17
- package/dist/generate.d.ts +2 -2
- package/dist/generate.js +63 -20
- package/dist/head.js +5 -30
- package/dist/index.js +1 -0
- package/dist/link.js +10 -35
- package/dist/main.js +1 -0
- package/dist/mdx.js +1 -0
- package/dist/migrate.js +1 -0
- package/dist/optimize.js +1 -0
- package/dist/page.js +20 -31
- package/dist/pages.js +3 -1
- package/dist/path.js +1 -0
- package/dist/preview.js +1 -0
- package/dist/render.js +3 -1
- package/dist/search.js +25 -62
- package/dist/server.js +1 -0
- package/dist/system.js +1 -0
- package/dist/types.d.ts +24 -7
- package/dist/types.js +1 -0
- package/dist/user.js +1 -0
- package/dist/utils.d.ts +1 -0
- package/dist/utils.js +6 -0
- package/dist/vite.d.ts +7 -3
- package/dist/vite.js +20 -33
- package/package.json +18 -14
package/README.md
CHANGED
|
@@ -92,12 +92,22 @@ export default defineConfig({
|
|
|
92
92
|
srcExt: ["tsx", "jsx", "md", "mdx"], // string[]
|
|
93
93
|
},
|
|
94
94
|
assets: {
|
|
95
|
-
entry: "",
|
|
95
|
+
entry: "",
|
|
96
|
+
// | string
|
|
97
|
+
// | string[]
|
|
98
|
+
// | { [key: string]: string }
|
|
99
|
+
// | {
|
|
100
|
+
// name?: string
|
|
101
|
+
// input: string
|
|
102
|
+
// insertPages: string | string[] | { include: string[]; exclude?: string[] }
|
|
103
|
+
// }[]
|
|
96
104
|
outDir: "assets", // string
|
|
105
|
+
outName: "[name]", // string
|
|
97
106
|
bundle: {
|
|
98
107
|
outName: "bundle", // string
|
|
99
108
|
},
|
|
100
109
|
partial: {
|
|
110
|
+
useSplitPerPage: false, // boolean
|
|
101
111
|
usePreact: false, // boolean
|
|
102
112
|
useIntersectionObserver: true, // boolean
|
|
103
113
|
outName: "partial", // string
|
package/dist/app.js
CHANGED
package/dist/beautify.js
CHANGED
package/dist/build.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { Options as MdxOptions } from "@mdx-js/esbuild";
|
|
2
2
|
import type { Config as SvgrOptions } from "@svgr/core";
|
|
3
3
|
import type { InlineConfig } from "vite";
|
|
4
|
-
import type { MinistaResolveConfig, RootStaticContent, RootJsxContent, GlobalStaticData, GetGlobalStaticData, PageJsxContent, StaticData, StaticDataItem, GetStaticData, AliasArray, PartialModules, CssOptions } from "./types.js";
|
|
4
|
+
import type { MinistaResolveConfig, RootStaticContent, RootJsxContent, GlobalStaticData, GetGlobalStaticData, PageJsxContent, StaticData, StaticDataItem, GetStaticData, AliasArray, PartialModules, CssOptions, EntryObject } from "./types.js";
|
|
5
5
|
export declare function buildTempPages(entryPoints: string[], buildOptions: {
|
|
6
6
|
outBase: string;
|
|
7
7
|
outDir: string;
|
|
@@ -10,12 +10,15 @@ export declare function buildTempPages(entryPoints: string[], buildOptions: {
|
|
|
10
10
|
svgrOptions: SvgrOptions;
|
|
11
11
|
cssOptions: CssOptions;
|
|
12
12
|
}): Promise<void>;
|
|
13
|
-
export declare function buildStaticPages({ entryPoints, tempRootFilePath, outBase, outDir,
|
|
13
|
+
export declare function buildStaticPages({ entryPoints, tempRootFilePath, outBase, outDir, assetsTagArray, showLog, }: {
|
|
14
14
|
entryPoints: string[];
|
|
15
15
|
tempRootFilePath: string;
|
|
16
16
|
outBase: string;
|
|
17
17
|
outDir: string;
|
|
18
|
-
|
|
18
|
+
assetsTagArray: {
|
|
19
|
+
pattern: string[];
|
|
20
|
+
tag: string;
|
|
21
|
+
}[];
|
|
19
22
|
showLog: boolean;
|
|
20
23
|
}): Promise<void>;
|
|
21
24
|
export declare function buildRootEsmContent(tempRootFilePath: string): Promise<{
|
|
@@ -23,21 +26,27 @@ export declare function buildRootEsmContent(tempRootFilePath: string): Promise<{
|
|
|
23
26
|
staticData: GlobalStaticData;
|
|
24
27
|
}>;
|
|
25
28
|
export declare function buildGlobalStaticData(getGlobalStaticData: GetGlobalStaticData): Promise<GlobalStaticData>;
|
|
26
|
-
export declare function buildStaticPage({ entryPoint, outFile, rootStaticContent,
|
|
29
|
+
export declare function buildStaticPage({ entryPoint, outFile, rootStaticContent, assetsTagArray, outDir, showLog, }: {
|
|
27
30
|
entryPoint: string;
|
|
28
31
|
outFile: string;
|
|
29
32
|
rootStaticContent: RootStaticContent;
|
|
30
|
-
|
|
33
|
+
assetsTagArray: {
|
|
34
|
+
pattern: string[];
|
|
35
|
+
tag: string;
|
|
36
|
+
}[];
|
|
31
37
|
outDir: string;
|
|
32
38
|
showLog: boolean;
|
|
33
39
|
}): Promise<void>;
|
|
34
40
|
export declare function buildStaticData(getStaticData: GetStaticData): Promise<StaticData>;
|
|
35
|
-
export declare function buildHtmlPage({ pageJsxContent, staticDataItem, routePath, rootStaticContent,
|
|
41
|
+
export declare function buildHtmlPage({ pageJsxContent, staticDataItem, routePath, rootStaticContent, assetsTagArray, frontmatter, outDir, showLog, }: {
|
|
36
42
|
pageJsxContent: PageJsxContent;
|
|
37
43
|
staticDataItem: StaticDataItem;
|
|
38
44
|
routePath: string;
|
|
39
45
|
rootStaticContent: RootStaticContent;
|
|
40
|
-
|
|
46
|
+
assetsTagArray: {
|
|
47
|
+
pattern: string[];
|
|
48
|
+
tag: string;
|
|
49
|
+
}[];
|
|
41
50
|
frontmatter: any;
|
|
42
51
|
outDir: string;
|
|
43
52
|
showLog: boolean;
|
|
@@ -48,15 +57,28 @@ export declare function buildTempAssets(viteConfig: InlineConfig, buildOptions:
|
|
|
48
57
|
outDir: string;
|
|
49
58
|
assetDir: string;
|
|
50
59
|
}): Promise<void>;
|
|
51
|
-
export declare function
|
|
60
|
+
export declare function buildAssetsTagArray({ entryPoints, // (*.css|*.js)
|
|
61
|
+
outBase, hrefBase, entryPattern, bundlePattern, partialPattern, }: {
|
|
62
|
+
entryPoints: string[];
|
|
52
63
|
outBase: string;
|
|
53
|
-
|
|
54
|
-
|
|
64
|
+
hrefBase: string;
|
|
65
|
+
entryPattern?: EntryObject[];
|
|
66
|
+
bundlePattern?: EntryObject[];
|
|
67
|
+
partialPattern?: EntryObject[];
|
|
68
|
+
}): {
|
|
69
|
+
pattern: string[];
|
|
70
|
+
tag: string;
|
|
71
|
+
}[];
|
|
72
|
+
export declare function buildAssetsTagStr({ pathname, assetsTagArray, }: {
|
|
73
|
+
pathname: string;
|
|
74
|
+
assetsTagArray: {
|
|
75
|
+
pattern: string[];
|
|
76
|
+
tag: string;
|
|
77
|
+
}[];
|
|
78
|
+
}): string;
|
|
55
79
|
export declare function buildViteImporterRoots(config: MinistaResolveConfig): Promise<void>;
|
|
56
80
|
export declare function buildViteImporterRoutes(config: MinistaResolveConfig): Promise<void>;
|
|
57
|
-
export declare function buildViteImporterAssets(entry:
|
|
58
|
-
[key: string]: string;
|
|
59
|
-
}): Promise<void>;
|
|
81
|
+
export declare function buildViteImporterAssets(entry: EntryObject[]): Promise<void>;
|
|
60
82
|
export declare function buildViteImporterBlankAssets(): Promise<void>;
|
|
61
83
|
export declare function buildPartialModules(moduleFilePaths: string[], config: MinistaResolveConfig): Promise<PartialModules>;
|
|
62
84
|
export declare function buildPartialStringIndex(partialModules: PartialModules, buildOptions: {
|
|
@@ -72,10 +94,30 @@ export declare function buildPartialStringBundle(entryPoint: string, buildOption
|
|
|
72
94
|
export declare function buildPartialStringInitial(entryPoint: string, partialModules: PartialModules, buildOptions: {
|
|
73
95
|
outFile: string;
|
|
74
96
|
}): Promise<void>;
|
|
97
|
+
export declare function buildPartialHydratePages(partialModules: PartialModules, config: MinistaResolveConfig, buildOptions: {
|
|
98
|
+
roots: string[];
|
|
99
|
+
pages: string[];
|
|
100
|
+
outBase: string;
|
|
101
|
+
outFile: string;
|
|
102
|
+
}): Promise<{
|
|
103
|
+
name: string;
|
|
104
|
+
insertPages: string[];
|
|
105
|
+
hasPartialModules: {
|
|
106
|
+
id: string;
|
|
107
|
+
phId: string;
|
|
108
|
+
phDomId: string;
|
|
109
|
+
htmlId: string;
|
|
110
|
+
targetsId: string;
|
|
111
|
+
importer: string;
|
|
112
|
+
rootAttr: string;
|
|
113
|
+
rootDOMElement: string;
|
|
114
|
+
rootStyleStr: string;
|
|
115
|
+
}[];
|
|
116
|
+
}[]>;
|
|
75
117
|
export declare function buildPartialHydrateIndex(partialModules: PartialModules, config: MinistaResolveConfig, buildOptions: {
|
|
76
118
|
outFile: string;
|
|
77
119
|
}): Promise<void>;
|
|
78
|
-
export declare function
|
|
120
|
+
export declare function buildPartialHydrateAsset(viteConfig: InlineConfig, config: MinistaResolveConfig, buildOptions: {
|
|
79
121
|
input: string;
|
|
80
122
|
bundleOutName: string;
|
|
81
123
|
outDir: string;
|
package/dist/build.js
CHANGED
|
@@ -1,22 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
var __defProps = Object.defineProperties;
|
|
3
|
-
var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
|
|
4
|
-
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
5
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
-
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
7
|
-
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
8
|
-
var __spreadValues = (a, b) => {
|
|
9
|
-
for (var prop in b || (b = {}))
|
|
10
|
-
if (__hasOwnProp.call(b, prop))
|
|
11
|
-
__defNormalProp(a, prop, b[prop]);
|
|
12
|
-
if (__getOwnPropSymbols)
|
|
13
|
-
for (var prop of __getOwnPropSymbols(b)) {
|
|
14
|
-
if (__propIsEnum.call(b, prop))
|
|
15
|
-
__defNormalProp(a, prop, b[prop]);
|
|
16
|
-
}
|
|
17
|
-
return a;
|
|
18
|
-
};
|
|
19
|
-
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
1
|
+
"use strict";
|
|
20
2
|
import React from "react";
|
|
21
3
|
import fs from "fs-extra";
|
|
22
4
|
import path from "path";
|
|
@@ -32,6 +14,7 @@ import {
|
|
|
32
14
|
} from "vite";
|
|
33
15
|
import { parse } from "node-html-parser";
|
|
34
16
|
import mojigiri from "mojigiri";
|
|
17
|
+
import picomatch from "picomatch";
|
|
35
18
|
import { systemConfig } from "./system.js";
|
|
36
19
|
import { getFilePath } from "./path.js";
|
|
37
20
|
import {
|
|
@@ -42,7 +25,7 @@ import {
|
|
|
42
25
|
} from "./esbuild.js";
|
|
43
26
|
import { resolveaAssetFileName } from "./vite.js";
|
|
44
27
|
import { renderHtml } from "./render.js";
|
|
45
|
-
import { slashEnd, reactStylesToString } from "./utils.js";
|
|
28
|
+
import { slashEnd, reactStylesToString, getFilename } from "./utils.js";
|
|
46
29
|
import { cssModulePlugin } from "./css.js";
|
|
47
30
|
const __filename = url.fileURLToPath(import.meta.url);
|
|
48
31
|
const __dirname = path.dirname(__filename);
|
|
@@ -108,7 +91,7 @@ async function buildStaticPages({
|
|
|
108
91
|
tempRootFilePath,
|
|
109
92
|
outBase,
|
|
110
93
|
outDir,
|
|
111
|
-
|
|
94
|
+
assetsTagArray,
|
|
112
95
|
showLog
|
|
113
96
|
}) {
|
|
114
97
|
const rootStaticContent = await buildRootEsmContent(tempRootFilePath);
|
|
@@ -122,7 +105,7 @@ async function buildStaticPages({
|
|
|
122
105
|
entryPoint,
|
|
123
106
|
outFile: filename,
|
|
124
107
|
rootStaticContent,
|
|
125
|
-
|
|
108
|
+
assetsTagArray,
|
|
126
109
|
outDir,
|
|
127
110
|
showLog
|
|
128
111
|
});
|
|
@@ -151,7 +134,7 @@ async function buildStaticPage({
|
|
|
151
134
|
entryPoint,
|
|
152
135
|
outFile,
|
|
153
136
|
rootStaticContent,
|
|
154
|
-
|
|
137
|
+
assetsTagArray,
|
|
155
138
|
outDir,
|
|
156
139
|
showLog
|
|
157
140
|
}) {
|
|
@@ -168,27 +151,27 @@ async function buildStaticPage({
|
|
|
168
151
|
staticDataItem,
|
|
169
152
|
routePath: outFile,
|
|
170
153
|
rootStaticContent,
|
|
171
|
-
|
|
154
|
+
assetsTagArray,
|
|
172
155
|
frontmatter,
|
|
173
156
|
outDir,
|
|
174
157
|
showLog
|
|
175
158
|
});
|
|
176
159
|
}
|
|
177
160
|
if ("props" in staticData && "paths" in staticData === false) {
|
|
178
|
-
const staticDataItem =
|
|
161
|
+
const staticDataItem = { ...defaultStaticDataItem, ...staticData };
|
|
179
162
|
return await buildHtmlPage({
|
|
180
163
|
pageJsxContent,
|
|
181
164
|
staticDataItem,
|
|
182
165
|
routePath: outFile,
|
|
183
166
|
rootStaticContent,
|
|
184
|
-
|
|
167
|
+
assetsTagArray,
|
|
185
168
|
frontmatter,
|
|
186
169
|
outDir,
|
|
187
170
|
showLog
|
|
188
171
|
});
|
|
189
172
|
}
|
|
190
173
|
if ("paths" in staticData) {
|
|
191
|
-
const staticDataItem =
|
|
174
|
+
const staticDataItem = { ...defaultStaticDataItem, ...staticData };
|
|
192
175
|
let fixedOutfile = outFile;
|
|
193
176
|
for await (const [key, value] of Object.entries(staticDataItem.paths)) {
|
|
194
177
|
const reg = new RegExp("\\[" + key + "\\]", "g");
|
|
@@ -199,7 +182,7 @@ async function buildStaticPage({
|
|
|
199
182
|
staticDataItem,
|
|
200
183
|
routePath: fixedOutfile,
|
|
201
184
|
rootStaticContent,
|
|
202
|
-
|
|
185
|
+
assetsTagArray,
|
|
203
186
|
frontmatter,
|
|
204
187
|
outDir,
|
|
205
188
|
showLog
|
|
@@ -208,7 +191,7 @@ async function buildStaticPage({
|
|
|
208
191
|
if (Array.isArray(staticData) && staticData.length > 0) {
|
|
209
192
|
const entryPoints = staticData;
|
|
210
193
|
await Promise.all(entryPoints.map(async (entryPoint2) => {
|
|
211
|
-
const staticDataItem =
|
|
194
|
+
const staticDataItem = { ...defaultStaticDataItem, ...entryPoint2 };
|
|
212
195
|
let fixedOutfile = outFile;
|
|
213
196
|
for await (const [key, value] of Object.entries(staticDataItem.paths)) {
|
|
214
197
|
const reg = new RegExp("\\[" + key + "\\]", "g");
|
|
@@ -219,7 +202,7 @@ async function buildStaticPage({
|
|
|
219
202
|
staticDataItem,
|
|
220
203
|
routePath: fixedOutfile,
|
|
221
204
|
rootStaticContent,
|
|
222
|
-
|
|
205
|
+
assetsTagArray,
|
|
223
206
|
frontmatter,
|
|
224
207
|
outDir,
|
|
225
208
|
showLog
|
|
@@ -236,7 +219,7 @@ async function buildHtmlPage({
|
|
|
236
219
|
staticDataItem,
|
|
237
220
|
routePath,
|
|
238
221
|
rootStaticContent,
|
|
239
|
-
|
|
222
|
+
assetsTagArray,
|
|
240
223
|
frontmatter,
|
|
241
224
|
outDir,
|
|
242
225
|
showLog
|
|
@@ -258,28 +241,38 @@ async function buildHtmlPage({
|
|
|
258
241
|
if (PageComponent === Fragment) {
|
|
259
242
|
return /* @__PURE__ */ React.createElement(Fragment, null);
|
|
260
243
|
} else {
|
|
261
|
-
return /* @__PURE__ */ React.createElement(PageComponent,
|
|
244
|
+
return /* @__PURE__ */ React.createElement(PageComponent, {
|
|
245
|
+
...globalStaticData == null ? void 0 : globalStaticData.props,
|
|
246
|
+
...staticProps,
|
|
262
247
|
frontmatter,
|
|
263
248
|
location
|
|
264
|
-
})
|
|
249
|
+
});
|
|
265
250
|
}
|
|
266
251
|
})());
|
|
267
252
|
} else {
|
|
268
|
-
return /* @__PURE__ */ React.createElement(RootComponent,
|
|
253
|
+
return /* @__PURE__ */ React.createElement(RootComponent, {
|
|
254
|
+
...globalStaticData == null ? void 0 : globalStaticData.props,
|
|
255
|
+
...staticProps,
|
|
269
256
|
frontmatter,
|
|
270
257
|
location
|
|
271
|
-
}
|
|
258
|
+
}, (() => {
|
|
272
259
|
if (PageComponent === Fragment) {
|
|
273
260
|
return /* @__PURE__ */ React.createElement(Fragment, null);
|
|
274
261
|
} else {
|
|
275
|
-
return /* @__PURE__ */ React.createElement(PageComponent,
|
|
262
|
+
return /* @__PURE__ */ React.createElement(PageComponent, {
|
|
263
|
+
...globalStaticData == null ? void 0 : globalStaticData.props,
|
|
264
|
+
...staticProps,
|
|
276
265
|
frontmatter,
|
|
277
266
|
location
|
|
278
|
-
})
|
|
267
|
+
});
|
|
279
268
|
}
|
|
280
269
|
})());
|
|
281
270
|
}
|
|
282
271
|
};
|
|
272
|
+
const assetsTagStr = buildAssetsTagStr({
|
|
273
|
+
pathname: location.pathname,
|
|
274
|
+
assetsTagArray
|
|
275
|
+
});
|
|
283
276
|
const renderdHtml = await renderHtml(/* @__PURE__ */ React.createElement(RenderComponent, null), assetsTagStr);
|
|
284
277
|
const html = [renderdHtml];
|
|
285
278
|
const stringInitial = getFilePath(systemConfig.temp.partialHydration.outDir, "string-initial", "json");
|
|
@@ -330,18 +323,51 @@ async function buildTempAssets(viteConfig, buildOptions) {
|
|
|
330
323
|
});
|
|
331
324
|
}
|
|
332
325
|
}
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
326
|
+
function buildAssetsTagArray({
|
|
327
|
+
entryPoints,
|
|
328
|
+
outBase,
|
|
329
|
+
hrefBase,
|
|
330
|
+
entryPattern = [],
|
|
331
|
+
bundlePattern = [],
|
|
332
|
+
partialPattern = []
|
|
333
|
+
}) {
|
|
334
|
+
const winOutBase = outBase.replaceAll("/", "\\");
|
|
335
|
+
const assets = entryPoints.map((entryPoint) => {
|
|
336
|
+
const assetPath = entryPoint.replace(outBase, hrefBase).replace(winOutBase, hrefBase).replaceAll("\\", "/");
|
|
337
|
+
const name = getFilename(assetPath);
|
|
337
338
|
if (assetPath.endsWith(".css")) {
|
|
338
|
-
return `<link rel="stylesheet" href="${assetPath}"
|
|
339
|
-
} else
|
|
340
|
-
return `<script defer src="${assetPath}"><\/script
|
|
339
|
+
return { name, tag: `<link rel="stylesheet" href="${assetPath}">` };
|
|
340
|
+
} else {
|
|
341
|
+
return { name, tag: `<script defer src="${assetPath}"><\/script>` };
|
|
341
342
|
}
|
|
342
343
|
});
|
|
343
|
-
const
|
|
344
|
-
|
|
344
|
+
const patterns = [...entryPattern, ...bundlePattern, ...partialPattern];
|
|
345
|
+
const result = assets.map((asset) => {
|
|
346
|
+
const targetPattern = patterns.find((pattern) => pattern.name === asset.name);
|
|
347
|
+
if (targetPattern) {
|
|
348
|
+
return { pattern: targetPattern.insertPages, tag: asset.tag };
|
|
349
|
+
} else {
|
|
350
|
+
return { pattern: ["**/*"], tag: asset.tag };
|
|
351
|
+
}
|
|
352
|
+
});
|
|
353
|
+
return result;
|
|
354
|
+
}
|
|
355
|
+
function buildAssetsTagStr({
|
|
356
|
+
pathname,
|
|
357
|
+
assetsTagArray
|
|
358
|
+
}) {
|
|
359
|
+
if (!assetsTagArray.length) {
|
|
360
|
+
return "";
|
|
361
|
+
}
|
|
362
|
+
const result = assetsTagArray.map((item) => {
|
|
363
|
+
const check = picomatch.isMatch(pathname, item.pattern);
|
|
364
|
+
if (check) {
|
|
365
|
+
return item.tag;
|
|
366
|
+
} else {
|
|
367
|
+
return "";
|
|
368
|
+
}
|
|
369
|
+
}).join("");
|
|
370
|
+
return result;
|
|
345
371
|
}
|
|
346
372
|
async function buildViteImporterRoots(config) {
|
|
347
373
|
const outFile = systemConfig.temp.viteImporter.outDir + "/roots.js";
|
|
@@ -405,14 +431,24 @@ async function buildViteImporterRoutes(config) {
|
|
|
405
431
|
}
|
|
406
432
|
async function buildViteImporterAssets(entry) {
|
|
407
433
|
const outFile = systemConfig.temp.viteImporter.outDir + "/assets.js";
|
|
408
|
-
const
|
|
409
|
-
const
|
|
410
|
-
const
|
|
411
|
-
return `import("/${
|
|
434
|
+
const globalEntry = entry.filter((item) => item.insertPages.length === 1 && item.insertPages[0] === "**/*");
|
|
435
|
+
const globalJsEntry = globalEntry.filter((item) => item.input.match(/\.(js|cjs|mjs|jsx|ts|tsx)$/));
|
|
436
|
+
const globalJsImportArray = globalJsEntry.map((item) => {
|
|
437
|
+
return `import("/${item.input}")`;
|
|
412
438
|
});
|
|
413
|
-
const
|
|
414
|
-
const
|
|
415
|
-
|
|
439
|
+
const globalJsImportStr = globalJsImportArray.join("\n ");
|
|
440
|
+
const otherEntry = entry.filter((item) => !(item.insertPages.length === 1 && item.insertPages[0] === "**/*"));
|
|
441
|
+
const otherImportArray = otherEntry.map((item) => {
|
|
442
|
+
const insertPagesStr = item.insertPages.map((pattern) => `"${pattern}"`).join();
|
|
443
|
+
return ` if (picomatch.isMatch(pathname, [${insertPagesStr}])) {
|
|
444
|
+
import("/${item.input}")
|
|
445
|
+
}`;
|
|
446
|
+
});
|
|
447
|
+
const otherImportStr = otherImportArray.join("\n ");
|
|
448
|
+
const template = `import picomatch from "picomatch-browser"
|
|
449
|
+
export const getAssets = (pathname) => {
|
|
450
|
+
${globalJsImportStr}
|
|
451
|
+
${otherImportStr}
|
|
416
452
|
}`;
|
|
417
453
|
await fs.outputFile(outFile, template).catch((err) => {
|
|
418
454
|
console.error(err);
|
|
@@ -522,10 +558,61 @@ async function buildPartialStringInitial(entryPoint, partialModules, buildOption
|
|
|
522
558
|
html: replacedHtml
|
|
523
559
|
};
|
|
524
560
|
});
|
|
525
|
-
const template =
|
|
526
|
-
await fs.
|
|
561
|
+
const template = { items };
|
|
562
|
+
await fs.outputJson(outFile, template, { spaces: 2 }).catch((err) => {
|
|
563
|
+
console.error(err);
|
|
564
|
+
});
|
|
565
|
+
}
|
|
566
|
+
async function buildPartialHydratePages(partialModules, config, buildOptions) {
|
|
567
|
+
async function searchHasPhIds(targetPath, phIds2) {
|
|
568
|
+
const targetPathRelative = path.relative(".", targetPath);
|
|
569
|
+
const code = await fs.readFile(targetPathRelative, "utf8");
|
|
570
|
+
const codeWithPhIds = phIds2.filter((phId) => code.includes(phId));
|
|
571
|
+
return { path: targetPath, hasPhIds: codeWithPhIds };
|
|
572
|
+
}
|
|
573
|
+
const phIds = partialModules.map((item) => item.id);
|
|
574
|
+
const roots = [];
|
|
575
|
+
const pages = [];
|
|
576
|
+
await Promise.all(buildOptions.roots.map(async (item) => {
|
|
577
|
+
const root = await searchHasPhIds(item, phIds);
|
|
578
|
+
return roots.push(root);
|
|
579
|
+
}));
|
|
580
|
+
await Promise.all(buildOptions.pages.map(async (item) => {
|
|
581
|
+
const page = await searchHasPhIds(item, phIds);
|
|
582
|
+
return pages.push(page);
|
|
583
|
+
}));
|
|
584
|
+
const rootHasPhIds = roots.length > 0 ? roots[0].hasPhIds : "";
|
|
585
|
+
const pagesWithRoot = pages.map((item) => ({
|
|
586
|
+
path: item.path,
|
|
587
|
+
hasPhIds: [.../* @__PURE__ */ new Set([...item.hasPhIds, ...rootHasPhIds])].sort(),
|
|
588
|
+
groupId: [.../* @__PURE__ */ new Set([...item.hasPhIds, ...rootHasPhIds])].sort().join("-")
|
|
589
|
+
}));
|
|
590
|
+
const groupIds = [
|
|
591
|
+
...new Set(pagesWithRoot.map((item) => item.groupId).filter((item) => item))
|
|
592
|
+
].sort();
|
|
593
|
+
const groups = groupIds.map((item) => ({
|
|
594
|
+
groupId: item,
|
|
595
|
+
pages: pagesWithRoot.filter((childItem) => childItem.groupId === item)
|
|
596
|
+
}));
|
|
597
|
+
const hydratePages = groups.map((item, index) => {
|
|
598
|
+
const name = `${config.assets.partial.outName}-${index + 1}`;
|
|
599
|
+
const winOutBase = buildOptions.outBase.replaceAll("/", "\\");
|
|
600
|
+
const reg1 = new RegExp(`^${buildOptions.outBase}|index.mjs`, "g");
|
|
601
|
+
const reg2 = new RegExp(`.mjs`, "g");
|
|
602
|
+
const insertPages = item.pages.map((childItem) => childItem.path.replace(reg1, "").replace(reg2, "").replace(winOutBase, "").replaceAll("\\", "/"));
|
|
603
|
+
const reg = new RegExp(`(${item.pages[0].hasPhIds.join("|")})`, "g");
|
|
604
|
+
const hasPartialModules = partialModules.filter((item2) => item2.id.match(reg));
|
|
605
|
+
return {
|
|
606
|
+
name,
|
|
607
|
+
insertPages,
|
|
608
|
+
hasPartialModules
|
|
609
|
+
};
|
|
610
|
+
});
|
|
611
|
+
const template = hydratePages;
|
|
612
|
+
await fs.outputJson(buildOptions.outFile, template, { spaces: 2 }).catch((err) => {
|
|
527
613
|
console.error(err);
|
|
528
614
|
});
|
|
615
|
+
return hydratePages;
|
|
529
616
|
}
|
|
530
617
|
async function buildPartialHydrateIndex(partialModules, config, buildOptions) {
|
|
531
618
|
const tmpImporters = partialModules.map((module) => {
|
|
@@ -567,7 +654,7 @@ ${tmpRendersStr}`;
|
|
|
567
654
|
console.error(err);
|
|
568
655
|
});
|
|
569
656
|
}
|
|
570
|
-
async function
|
|
657
|
+
async function buildPartialHydrateAsset(viteConfig, config, buildOptions) {
|
|
571
658
|
var _a;
|
|
572
659
|
const activePreact = buildOptions.usePreact && userPkgHasPreact;
|
|
573
660
|
const resolveAliasPreact = [
|
|
@@ -773,12 +860,14 @@ async function buildCopyDir(targetDir, outDir, log) {
|
|
|
773
860
|
}
|
|
774
861
|
}
|
|
775
862
|
export {
|
|
863
|
+
buildAssetsTagArray,
|
|
776
864
|
buildAssetsTagStr,
|
|
777
865
|
buildCopyDir,
|
|
778
866
|
buildGlobalStaticData,
|
|
779
867
|
buildHtmlPage,
|
|
780
|
-
|
|
868
|
+
buildPartialHydrateAsset,
|
|
781
869
|
buildPartialHydrateIndex,
|
|
870
|
+
buildPartialHydratePages,
|
|
782
871
|
buildPartialModules,
|
|
783
872
|
buildPartialStringBundle,
|
|
784
873
|
buildPartialStringIndex,
|
package/dist/bundle.js
CHANGED
package/dist/cli.js
CHANGED
|
@@ -1,19 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
3
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
4
|
-
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
5
|
-
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
6
|
-
var __spreadValues = (a, b) => {
|
|
7
|
-
for (var prop in b || (b = {}))
|
|
8
|
-
if (__hasOwnProp.call(b, prop))
|
|
9
|
-
__defNormalProp(a, prop, b[prop]);
|
|
10
|
-
if (__getOwnPropSymbols)
|
|
11
|
-
for (var prop of __getOwnPropSymbols(b)) {
|
|
12
|
-
if (__propIsEnum.call(b, prop))
|
|
13
|
-
__defNormalProp(a, prop, b[prop]);
|
|
14
|
-
}
|
|
15
|
-
return a;
|
|
16
|
-
};
|
|
1
|
+
"use strict";
|
|
17
2
|
import React from "react";
|
|
18
3
|
import fs from "fs-extra";
|
|
19
4
|
import { cac } from "cac";
|
|
@@ -41,7 +26,7 @@ import {
|
|
|
41
26
|
} from "./generate.js";
|
|
42
27
|
const cli = cac("minista");
|
|
43
28
|
function cleanOptions(options) {
|
|
44
|
-
const ret =
|
|
29
|
+
const ret = { ...options };
|
|
45
30
|
delete ret["--"];
|
|
46
31
|
return ret;
|
|
47
32
|
}
|
|
@@ -66,7 +51,7 @@ cli.command("[root]", "start dev server").alias("dev").option("--host [host]", `
|
|
|
66
51
|
emptyResolveDir(systemConfig.temp.icons.outDir),
|
|
67
52
|
emptyResolveDir(systemConfig.temp.partialHydration.outDir)
|
|
68
53
|
]);
|
|
69
|
-
await generateViteImporters(config
|
|
54
|
+
await generateViteImporters(config);
|
|
70
55
|
await Promise.all([
|
|
71
56
|
createDevServer(viteConfig),
|
|
72
57
|
createDevServerAssets(config, mdxConfig)
|
|
@@ -90,7 +75,7 @@ cli.command("build [root]", "build for production").action(async () => {
|
|
|
90
75
|
emptyResolveDir(systemConfig.temp.partialHydration.outDir),
|
|
91
76
|
emptyResolveDir(config.out)
|
|
92
77
|
]);
|
|
93
|
-
await Promise.all([generateViteImporters(config
|
|
78
|
+
await Promise.all([generateViteImporters(config)]);
|
|
94
79
|
await Promise.all([
|
|
95
80
|
generateTempRoot(config, mdxConfig),
|
|
96
81
|
generateTempPages(config, mdxConfig),
|
package/dist/comment.js
CHANGED
package/dist/config.d.ts
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import type { AliasOptions as ViteAliasOptions } from "vite";
|
|
2
|
-
import type { MinistaConfig, MinistaUserConfig, MinistaResolveConfig, MinistaResolveAliasInput, AliasArray } from "./types.js";
|
|
2
|
+
import type { MinistaConfig, MinistaUserConfig, MinistaResolveConfig, MinistaEntry, EntryObject, MinistaResolveAliasInput, AliasArray } from "./types.js";
|
|
3
3
|
export declare const defaultConfig: MinistaConfig;
|
|
4
4
|
export declare function mergeConfig(userConfig: MinistaUserConfig): Promise<MinistaConfig>;
|
|
5
|
+
export declare function resolveEntry(entry: MinistaEntry): Promise<EntryObject[]>;
|
|
5
6
|
export declare function mergeAlias(configAlias: MinistaResolveAliasInput, viteConfigAlias: ViteAliasOptions): Promise<AliasArray>;
|
|
6
7
|
export declare function resolveConfig(config: MinistaConfig): Promise<MinistaResolveConfig>;
|
|
7
8
|
export declare function getConfig(userConfig: MinistaUserConfig): Promise<MinistaResolveConfig>;
|