minista 2.3.2 → 2.4.2
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 +15 -1
- package/client.d.ts +7 -0
- package/dist/build.d.ts +26 -1
- package/dist/build.js +264 -27
- package/dist/cli.js +15 -4
- package/dist/config.js +14 -0
- package/dist/download.js +3 -3
- package/dist/esbuild.d.ts +1 -0
- package/dist/esbuild.js +57 -25
- package/dist/generate.d.ts +4 -2
- package/dist/generate.js +65 -10
- package/dist/system.js +3 -0
- package/dist/types.d.ts +45 -0
- package/dist/utils.d.ts +2 -0
- package/dist/utils.js +10 -0
- package/package.json +16 -15
package/README.md
CHANGED
|
@@ -31,7 +31,7 @@ $ npm init minista@latest
|
|
|
31
31
|
### Manual Setup
|
|
32
32
|
|
|
33
33
|
```bash
|
|
34
|
-
$ npm install --save-dev minista react react-dom
|
|
34
|
+
$ npm install --save-dev minista react@17 react-dom@17
|
|
35
35
|
```
|
|
36
36
|
|
|
37
37
|
```bash
|
|
@@ -97,6 +97,20 @@ export default defineConfig({
|
|
|
97
97
|
bundle: {
|
|
98
98
|
outName: "bundle", // string
|
|
99
99
|
},
|
|
100
|
+
partial: {
|
|
101
|
+
usePreact: false, // boolean
|
|
102
|
+
useIntersectionObserver: true, // boolean
|
|
103
|
+
outName: "partial", // string
|
|
104
|
+
rootAttrSuffix: "partial-hydration", // string
|
|
105
|
+
rootValuePrefix: "ph", // string
|
|
106
|
+
rootDOMElement: "div", // "div" | "span"
|
|
107
|
+
rootStyle: { display: "contents" }, // React.CSSProperties
|
|
108
|
+
intersectionObserverOptions: {
|
|
109
|
+
root: null, // Element | null
|
|
110
|
+
rootMargin: "0px", // string
|
|
111
|
+
thresholds: [1], // ReadonlyArray<number>
|
|
112
|
+
},
|
|
113
|
+
},
|
|
100
114
|
images: {
|
|
101
115
|
outDir: "assets/images", // string
|
|
102
116
|
outName: "[name]", // string
|
package/client.d.ts
CHANGED
|
@@ -16,6 +16,13 @@ declare module "*.svg" {
|
|
|
16
16
|
export default ReactComponent
|
|
17
17
|
}
|
|
18
18
|
|
|
19
|
+
declare module "*?ph" {
|
|
20
|
+
import * as React from "react"
|
|
21
|
+
|
|
22
|
+
const ReactComponent: React.FunctionComponent<React.PropsWithChildren>
|
|
23
|
+
export default ReactComponent
|
|
24
|
+
}
|
|
25
|
+
|
|
19
26
|
declare module "*?raw" {
|
|
20
27
|
const src: string
|
|
21
28
|
export default src
|
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 } from "./types.js";
|
|
4
|
+
import type { MinistaResolveConfig, RootStaticContent, RootJsxContent, GlobalStaticData, GetGlobalStaticData, PageJsxContent, StaticData, StaticDataItem, GetStaticData, PartialModules } from "./types.js";
|
|
5
5
|
export declare function buildTempPages(entryPoints: string[], buildOptions: {
|
|
6
6
|
outBase: string;
|
|
7
7
|
outDir: string;
|
|
@@ -21,9 +21,11 @@ export declare function buildStaticPage(entryPoint: string, outFile: string, roo
|
|
|
21
21
|
export declare function buildStaticData(getStaticData: GetStaticData): Promise<StaticData>;
|
|
22
22
|
export declare function buildHtmlPage(pageJsxContent: PageJsxContent, staticDataItem: StaticDataItem, routePath: string, rootStaticContent: RootStaticContent, assetsTagStr: string, frontmatter: any, outDir: string): Promise<void>;
|
|
23
23
|
export declare function buildTempAssets(viteConfig: InlineConfig, buildOptions: {
|
|
24
|
+
input: string;
|
|
24
25
|
bundleOutName: string;
|
|
25
26
|
outDir: string;
|
|
26
27
|
assetDir: string;
|
|
28
|
+
generateJs: boolean;
|
|
27
29
|
}): Promise<void>;
|
|
28
30
|
export declare function buildAssetsTagStr(entryPoints: string[], buildOptions: {
|
|
29
31
|
outBase: string;
|
|
@@ -35,4 +37,27 @@ export declare function buildViteImporterAssets(entry: {
|
|
|
35
37
|
[key: string]: string;
|
|
36
38
|
}): Promise<void>;
|
|
37
39
|
export declare function buildViteImporterBlankAssets(): Promise<void>;
|
|
40
|
+
export declare function buildPartialModules(moduleFilePaths: string[], config: MinistaResolveConfig): Promise<PartialModules>;
|
|
41
|
+
export declare function buildPartialStringIndex(partialModules: PartialModules, buildOptions: {
|
|
42
|
+
outFile: string;
|
|
43
|
+
}): Promise<void>;
|
|
44
|
+
export declare function buildPartialStringBundle(entryPoint: string, buildOptions: {
|
|
45
|
+
outFile: string;
|
|
46
|
+
mdxConfig: MdxOptions;
|
|
47
|
+
svgrOptions: SvgrOptions;
|
|
48
|
+
}): Promise<void>;
|
|
49
|
+
export declare function buildPartialStringInitial(entryPoint: string, partialModules: PartialModules, buildOptions: {
|
|
50
|
+
outFile: string;
|
|
51
|
+
}): Promise<void>;
|
|
52
|
+
export declare function buildPartialHydrateIndex(partialModules: PartialModules, config: MinistaResolveConfig, buildOptions: {
|
|
53
|
+
outFile: string;
|
|
54
|
+
}): Promise<void>;
|
|
55
|
+
export declare function buildPartialHydrateAssets(viteConfig: InlineConfig, buildOptions: {
|
|
56
|
+
input: string;
|
|
57
|
+
bundleOutName: string;
|
|
58
|
+
outDir: string;
|
|
59
|
+
assetDir: string;
|
|
60
|
+
generateJs: boolean;
|
|
61
|
+
usePreact: boolean;
|
|
62
|
+
}): Promise<void>;
|
|
38
63
|
export declare function buildCopyDir(targetDir: string, outDir: string, log?: "public" | "assets"): Promise<void>;
|
package/dist/build.js
CHANGED
|
@@ -25,31 +25,50 @@ import pc from "picocolors";
|
|
|
25
25
|
import { Fragment } from "react";
|
|
26
26
|
import { build as esBuild } from "esbuild";
|
|
27
27
|
import mdx from "@mdx-js/esbuild";
|
|
28
|
-
import {
|
|
28
|
+
import {
|
|
29
|
+
build as viteBuild,
|
|
30
|
+
defineConfig as defineViteConfig,
|
|
31
|
+
mergeConfig as mergeViteConfig
|
|
32
|
+
} from "vite";
|
|
29
33
|
import { systemConfig } from "./system.js";
|
|
30
|
-
import {
|
|
34
|
+
import { getFilePath } from "./path.js";
|
|
35
|
+
import {
|
|
36
|
+
resolvePlugin,
|
|
37
|
+
svgrPlugin,
|
|
38
|
+
rawPlugin,
|
|
39
|
+
partialHydrationPlugin
|
|
40
|
+
} from "./esbuild.js";
|
|
31
41
|
import { renderHtml } from "./render.js";
|
|
32
|
-
import { slashEnd } from "./utils.js";
|
|
42
|
+
import { slashEnd, reactStylesToString } from "./utils.js";
|
|
33
43
|
const __filename = url.fileURLToPath(import.meta.url);
|
|
34
44
|
const __dirname = path.dirname(__filename);
|
|
45
|
+
const userPkgPath = path.resolve("package.json");
|
|
46
|
+
const userPkgFilePath = path.relative(process.cwd(), userPkgPath);
|
|
47
|
+
const userPkg = JSON.parse(fs.readFileSync(userPkgFilePath, "utf8"));
|
|
48
|
+
const esbuildExternals = [
|
|
49
|
+
"react",
|
|
50
|
+
"react/*",
|
|
51
|
+
"react-dom",
|
|
52
|
+
"react-dom/*",
|
|
53
|
+
"react-helmet",
|
|
54
|
+
"react-helmet/*"
|
|
55
|
+
];
|
|
56
|
+
const esbuildLoaders = {
|
|
57
|
+
".jpg": "file",
|
|
58
|
+
".jpeg": "file",
|
|
59
|
+
".png": "file",
|
|
60
|
+
".gif": "file",
|
|
61
|
+
".webp": "file",
|
|
62
|
+
".avif": "file",
|
|
63
|
+
".eot": "file",
|
|
64
|
+
".woff": "file",
|
|
65
|
+
".woff2": "file"
|
|
66
|
+
};
|
|
67
|
+
const userPkgHasPreact = [
|
|
68
|
+
...Object.keys(userPkg.dependencies || {}),
|
|
69
|
+
...Object.keys(userPkg.devDependencies || {})
|
|
70
|
+
].includes("preact");
|
|
35
71
|
async function buildTempPages(entryPoints, buildOptions) {
|
|
36
|
-
const ministaPkgUrl = path.resolve(__dirname + "/../package.json");
|
|
37
|
-
const ministaPkgUrlRelative = path.relative(".", ministaPkgUrl);
|
|
38
|
-
const ministaPkg = JSON.parse(fs.readFileSync(ministaPkgUrlRelative, "utf8"));
|
|
39
|
-
const userPkgPath = path.resolve("package.json");
|
|
40
|
-
const userPkgFilePath = path.relative(process.cwd(), userPkgPath);
|
|
41
|
-
const userPkg = JSON.parse(fs.readFileSync(userPkgFilePath, "utf8"));
|
|
42
|
-
const esbuildExternal = [
|
|
43
|
-
...Object.keys(ministaPkg.dependencies || {}),
|
|
44
|
-
...Object.keys(ministaPkg.devDependencies || {}),
|
|
45
|
-
...Object.keys(ministaPkg.peerDependencies || {}),
|
|
46
|
-
...Object.keys(userPkg.dependencies || {}),
|
|
47
|
-
...Object.keys(userPkg.devDependencies || {}),
|
|
48
|
-
...Object.keys(userPkg.peerDependencies || {}),
|
|
49
|
-
"*.css",
|
|
50
|
-
"*.scss",
|
|
51
|
-
"*.sass"
|
|
52
|
-
];
|
|
53
72
|
await esBuild({
|
|
54
73
|
entryPoints,
|
|
55
74
|
outbase: buildOptions.outBase,
|
|
@@ -62,14 +81,16 @@ async function buildTempPages(entryPoints, buildOptions) {
|
|
|
62
81
|
path.resolve(__dirname + "/../lib/shim-react.js"),
|
|
63
82
|
path.resolve(__dirname + "/../lib/shim-fetch.js")
|
|
64
83
|
],
|
|
65
|
-
external:
|
|
84
|
+
external: esbuildExternals,
|
|
85
|
+
loader: esbuildLoaders,
|
|
66
86
|
plugins: [
|
|
67
87
|
mdx(buildOptions.mdxConfig),
|
|
68
88
|
resolvePlugin({
|
|
69
89
|
"react/jsx-runtime": "react/jsx-runtime.js"
|
|
70
90
|
}),
|
|
71
91
|
svgrPlugin(buildOptions.svgrOptions),
|
|
72
|
-
rawPlugin()
|
|
92
|
+
rawPlugin(),
|
|
93
|
+
partialHydrationPlugin()
|
|
73
94
|
]
|
|
74
95
|
}).catch(() => process.exit(1));
|
|
75
96
|
}
|
|
@@ -184,8 +205,21 @@ async function buildHtmlPage(pageJsxContent, staticDataItem, routePath, rootStat
|
|
|
184
205
|
})());
|
|
185
206
|
}
|
|
186
207
|
};
|
|
187
|
-
const
|
|
188
|
-
const
|
|
208
|
+
const renderdHtml = await renderHtml(/* @__PURE__ */ React.createElement(RenderComponent, null), assetsTagStr);
|
|
209
|
+
const html = [renderdHtml];
|
|
210
|
+
const stringInitial = getFilePath(systemConfig.temp.partialHydration.outDir, "string-initial", "json");
|
|
211
|
+
if (stringInitial) {
|
|
212
|
+
const targetRelative = path.relative(".", stringInitial);
|
|
213
|
+
const targetJson = JSON.parse(fs.readFileSync(targetRelative, "utf8"));
|
|
214
|
+
const items = targetJson.items;
|
|
215
|
+
items.map((item) => {
|
|
216
|
+
const dummy = `<div data-partial-hydration="${item.id}"></div>`;
|
|
217
|
+
const reg = new RegExp(`${dummy}`, "g");
|
|
218
|
+
html[0] = html[0].replace(reg, item.html);
|
|
219
|
+
return;
|
|
220
|
+
});
|
|
221
|
+
}
|
|
222
|
+
const replacedHtml = html[0].replace(/<div class="minista-comment" hidden="">(.+?)<\/div>/g, "\n<!-- $1 -->");
|
|
189
223
|
await fs.outputFile(routePath, replacedHtml).then(() => {
|
|
190
224
|
console.log(`${pc.bold(pc.green("BUILD"))} ${pc.bold(routePath)}`);
|
|
191
225
|
}).catch((err) => {
|
|
@@ -193,16 +227,16 @@ async function buildHtmlPage(pageJsxContent, staticDataItem, routePath, rootStat
|
|
|
193
227
|
});
|
|
194
228
|
}
|
|
195
229
|
async function buildTempAssets(viteConfig, buildOptions) {
|
|
196
|
-
const customConfig = {
|
|
230
|
+
const customConfig = defineViteConfig({
|
|
197
231
|
build: {
|
|
198
232
|
write: false,
|
|
199
233
|
rollupOptions: {
|
|
200
234
|
input: {
|
|
201
|
-
__minista_bundle_assets:
|
|
235
|
+
__minista_bundle_assets: buildOptions.input
|
|
202
236
|
}
|
|
203
237
|
}
|
|
204
238
|
}
|
|
205
|
-
};
|
|
239
|
+
});
|
|
206
240
|
const mergedConfig = mergeViteConfig(viteConfig, customConfig);
|
|
207
241
|
const result = await viteBuild(mergedConfig);
|
|
208
242
|
const items = result.output;
|
|
@@ -212,6 +246,10 @@ async function buildTempAssets(viteConfig, buildOptions) {
|
|
|
212
246
|
const customFileName = slashEnd(buildOptions.outDir) + buildOptions.bundleOutName + ".css";
|
|
213
247
|
return (item == null ? void 0 : item.source) && fs.outputFile(customFileName, item == null ? void 0 : item.source);
|
|
214
248
|
} else if (item.fileName.match(/__minista_bundle_assets\.js/)) {
|
|
249
|
+
if (buildOptions.generateJs) {
|
|
250
|
+
const customFileName = slashEnd(buildOptions.outDir) + buildOptions.bundleOutName + ".js";
|
|
251
|
+
return (item == null ? void 0 : item.code) && fs.outputFile(customFileName, item == null ? void 0 : item.code);
|
|
252
|
+
}
|
|
215
253
|
return;
|
|
216
254
|
} else {
|
|
217
255
|
const customFileName = buildOptions.outDir + item.fileName.replace(buildOptions.assetDir, "");
|
|
@@ -317,6 +355,199 @@ async function buildViteImporterBlankAssets() {
|
|
|
317
355
|
console.error(err);
|
|
318
356
|
});
|
|
319
357
|
}
|
|
358
|
+
async function buildPartialModules(moduleFilePaths, config) {
|
|
359
|
+
const moduleData = [];
|
|
360
|
+
await Promise.all(moduleFilePaths.map(async (entryPoint) => {
|
|
361
|
+
const entryPointRelative = path.relative(".", entryPoint);
|
|
362
|
+
const underUniqueId = path.parse(entryPoint).name;
|
|
363
|
+
const importer = await fs.readFile(entryPointRelative, "utf8");
|
|
364
|
+
moduleData.push({ id: underUniqueId, importer });
|
|
365
|
+
return;
|
|
366
|
+
}));
|
|
367
|
+
const sortedModuleData = moduleData.sort((a, b) => {
|
|
368
|
+
const nameA = a.importer.toUpperCase();
|
|
369
|
+
const nameB = b.importer.toUpperCase();
|
|
370
|
+
if (nameA < nameB) {
|
|
371
|
+
return -1;
|
|
372
|
+
}
|
|
373
|
+
if (nameA > nameB) {
|
|
374
|
+
return 1;
|
|
375
|
+
}
|
|
376
|
+
return 0;
|
|
377
|
+
});
|
|
378
|
+
const rootStyle = config.assets.partial.rootStyle;
|
|
379
|
+
const hasRootStyle = Object.entries(rootStyle).length !== 0;
|
|
380
|
+
const partialModules = sortedModuleData.map((item, index) => {
|
|
381
|
+
return {
|
|
382
|
+
id: item.id,
|
|
383
|
+
phId: `PH_${index + 1}`,
|
|
384
|
+
phDomId: `${config.assets.partial.rootValuePrefix}-${index + 1}`,
|
|
385
|
+
htmlId: `html_${index + 1}`,
|
|
386
|
+
targetsId: `targets_${index + 1}`,
|
|
387
|
+
importer: item.importer,
|
|
388
|
+
rootAttr: `data-${config.assets.partial.rootAttrSuffix}`,
|
|
389
|
+
rootDOMElement: config.assets.partial.rootDOMElement,
|
|
390
|
+
rootStyleStr: hasRootStyle ? reactStylesToString(rootStyle) : ""
|
|
391
|
+
};
|
|
392
|
+
});
|
|
393
|
+
return partialModules;
|
|
394
|
+
}
|
|
395
|
+
async function buildPartialStringIndex(partialModules, buildOptions) {
|
|
396
|
+
const tmpImporters = partialModules.map((module) => {
|
|
397
|
+
return `import ${module.phId} from "${module.importer}"`;
|
|
398
|
+
});
|
|
399
|
+
const tmpRenders = partialModules.map((module) => {
|
|
400
|
+
return `// ${module.phId}
|
|
401
|
+
const ${module.htmlId} = renderToString(React.createElement(${module.phId}))`;
|
|
402
|
+
});
|
|
403
|
+
const tmpExports = partialModules.map((module) => module.htmlId);
|
|
404
|
+
const tmpImporterStr = tmpImporters.join("\n");
|
|
405
|
+
const tmpRendersStr = tmpRenders.join("\n");
|
|
406
|
+
const tmpExportsStr = tmpExports.join(", ");
|
|
407
|
+
const outFile = buildOptions.outFile;
|
|
408
|
+
const template = `import { renderToString } from "react-dom/server.js"
|
|
409
|
+
${tmpImporterStr}
|
|
410
|
+
|
|
411
|
+
${tmpRendersStr}
|
|
412
|
+
|
|
413
|
+
export { ${tmpExportsStr} }`;
|
|
414
|
+
await fs.outputFile(outFile, template).catch((err) => {
|
|
415
|
+
console.error(err);
|
|
416
|
+
});
|
|
417
|
+
}
|
|
418
|
+
async function buildPartialStringBundle(entryPoint, buildOptions) {
|
|
419
|
+
await esBuild({
|
|
420
|
+
entryPoints: [entryPoint],
|
|
421
|
+
outfile: buildOptions.outFile,
|
|
422
|
+
bundle: true,
|
|
423
|
+
format: "esm",
|
|
424
|
+
platform: "node",
|
|
425
|
+
inject: [
|
|
426
|
+
path.resolve(__dirname + "/../lib/shim-react.js")
|
|
427
|
+
],
|
|
428
|
+
external: esbuildExternals,
|
|
429
|
+
loader: esbuildLoaders,
|
|
430
|
+
plugins: [
|
|
431
|
+
mdx(buildOptions.mdxConfig),
|
|
432
|
+
resolvePlugin({
|
|
433
|
+
"react/jsx-runtime": "react/jsx-runtime.js"
|
|
434
|
+
}),
|
|
435
|
+
svgrPlugin(buildOptions.svgrOptions),
|
|
436
|
+
rawPlugin()
|
|
437
|
+
]
|
|
438
|
+
}).catch(() => process.exit(1));
|
|
439
|
+
}
|
|
440
|
+
async function buildPartialStringInitial(entryPoint, partialModules, buildOptions) {
|
|
441
|
+
const outFile = buildOptions.outFile;
|
|
442
|
+
const targetFilePath = url.pathToFileURL(entryPoint).href;
|
|
443
|
+
const partialString = await import(targetFilePath);
|
|
444
|
+
const items = partialModules.map((module) => {
|
|
445
|
+
const html = partialString[module.htmlId];
|
|
446
|
+
const dom = module.rootDOMElement;
|
|
447
|
+
const dataId = `${module.rootAttr}="${module.phDomId}"`;
|
|
448
|
+
const style = module.rootStyleStr ? ` style="${module.rootStyleStr}"` : "";
|
|
449
|
+
const replacedHtml = `<${dom} ${dataId}${style}>${html}</${dom}>`;
|
|
450
|
+
return {
|
|
451
|
+
id: module.id,
|
|
452
|
+
html: replacedHtml
|
|
453
|
+
};
|
|
454
|
+
});
|
|
455
|
+
const template = JSON.stringify({ items });
|
|
456
|
+
await fs.outputFile(outFile, template).catch((err) => {
|
|
457
|
+
console.error(err);
|
|
458
|
+
});
|
|
459
|
+
}
|
|
460
|
+
async function buildPartialHydrateIndex(partialModules, config, buildOptions) {
|
|
461
|
+
const tmpImporters = partialModules.map((module) => {
|
|
462
|
+
return `import ${module.phId} from "${module.importer}"`;
|
|
463
|
+
});
|
|
464
|
+
const tempFunctionIntersectionObserver = `const options = {
|
|
465
|
+
root: ${config.assets.partial.intersectionObserverOptions.root},
|
|
466
|
+
rootMargin: "${config.assets.partial.intersectionObserverOptions.rootMargin}",
|
|
467
|
+
thresholds: ${config.assets.partial.intersectionObserverOptions.thresholds},
|
|
468
|
+
}
|
|
469
|
+
const observer = new IntersectionObserver(hydrate, options)
|
|
470
|
+
observer.observe(target)
|
|
471
|
+
|
|
472
|
+
function hydrate() {
|
|
473
|
+
ReactDOM.hydrate(App, target)
|
|
474
|
+
observer.unobserve(target)
|
|
475
|
+
}`;
|
|
476
|
+
const tempFunctionImmediateExecution = `ReactDOM.hydrate(App, target)`;
|
|
477
|
+
const tempFunction = config.assets.partial.useIntersectionObserver ? tempFunctionIntersectionObserver : tempFunctionImmediateExecution;
|
|
478
|
+
const tmpRenders = partialModules.map((module) => {
|
|
479
|
+
return `
|
|
480
|
+
// ${module.phId}
|
|
481
|
+
const ${module.targetsId} = document.querySelectorAll('[${module.rootAttr}="${module.phDomId}"]')
|
|
482
|
+
if (${module.targetsId}) {
|
|
483
|
+
${module.targetsId}.forEach(target => {
|
|
484
|
+
const App = React.createElement(${module.phId})
|
|
485
|
+
${tempFunction}
|
|
486
|
+
})
|
|
487
|
+
}`;
|
|
488
|
+
});
|
|
489
|
+
const tmpImporterStr = tmpImporters.join("\n");
|
|
490
|
+
const tmpRendersStr = tmpRenders.join("\n");
|
|
491
|
+
const outFile = buildOptions.outFile;
|
|
492
|
+
const template = `import React from "react"
|
|
493
|
+
import ReactDOM from "react-dom"
|
|
494
|
+
${tmpImporterStr}
|
|
495
|
+
${tmpRendersStr}`;
|
|
496
|
+
await fs.outputFile(outFile, template).catch((err) => {
|
|
497
|
+
console.error(err);
|
|
498
|
+
});
|
|
499
|
+
}
|
|
500
|
+
async function buildPartialHydrateAssets(viteConfig, buildOptions) {
|
|
501
|
+
var _a;
|
|
502
|
+
const activePreact = buildOptions.usePreact && userPkgHasPreact;
|
|
503
|
+
const resolveAliasPreact = {
|
|
504
|
+
react: "preact/compat",
|
|
505
|
+
"react-dom": "preact/compat"
|
|
506
|
+
};
|
|
507
|
+
const customConfig = defineViteConfig({
|
|
508
|
+
base: viteConfig.base,
|
|
509
|
+
build: {
|
|
510
|
+
write: false,
|
|
511
|
+
assetsInlineLimit: 0,
|
|
512
|
+
minify: (_a = viteConfig.build) == null ? void 0 : _a.minify,
|
|
513
|
+
rollupOptions: {
|
|
514
|
+
input: {
|
|
515
|
+
__minista_bundle_assets: buildOptions.input
|
|
516
|
+
},
|
|
517
|
+
output: {
|
|
518
|
+
manualChunks: void 0
|
|
519
|
+
}
|
|
520
|
+
}
|
|
521
|
+
},
|
|
522
|
+
esbuild: viteConfig.esbuild,
|
|
523
|
+
plugins: viteConfig.plugins,
|
|
524
|
+
resolve: {
|
|
525
|
+
alias: activePreact ? resolveAliasPreact : {}
|
|
526
|
+
},
|
|
527
|
+
customLogger: viteConfig.customLogger
|
|
528
|
+
});
|
|
529
|
+
const mergedConfig = mergeViteConfig({}, customConfig);
|
|
530
|
+
const result = await viteBuild(mergedConfig);
|
|
531
|
+
const items = result.output;
|
|
532
|
+
if (Array.isArray(items) && items.length > 0) {
|
|
533
|
+
items.map((item) => {
|
|
534
|
+
if (item.fileName.match(/\.css/)) {
|
|
535
|
+
const customFileName = slashEnd(buildOptions.outDir) + buildOptions.bundleOutName + ".css";
|
|
536
|
+
return (item == null ? void 0 : item.source) && fs.outputFile(customFileName, item == null ? void 0 : item.source);
|
|
537
|
+
} else if (item.fileName.match(/\.js/)) {
|
|
538
|
+
if (buildOptions.generateJs) {
|
|
539
|
+
const customFileName = slashEnd(buildOptions.outDir) + buildOptions.bundleOutName + ".js";
|
|
540
|
+
return (item == null ? void 0 : item.code) && fs.outputFile(customFileName, item == null ? void 0 : item.code);
|
|
541
|
+
}
|
|
542
|
+
return;
|
|
543
|
+
} else {
|
|
544
|
+
const customFileName = buildOptions.outDir + item.fileName.replace(buildOptions.assetDir, "");
|
|
545
|
+
const customCode = (item == null ? void 0 : item.source) ? item == null ? void 0 : item.source : (item == null ? void 0 : item.code) ? item == null ? void 0 : item.code : "";
|
|
546
|
+
return customCode && fs.outputFile(customFileName, customCode);
|
|
547
|
+
}
|
|
548
|
+
});
|
|
549
|
+
}
|
|
550
|
+
}
|
|
320
551
|
async function buildCopyDir(targetDir, outDir, log) {
|
|
321
552
|
const checkTargetDir = await fs.pathExists(targetDir);
|
|
322
553
|
if (checkTargetDir) {
|
|
@@ -339,6 +570,12 @@ export {
|
|
|
339
570
|
buildCopyDir,
|
|
340
571
|
buildGlobalStaticData,
|
|
341
572
|
buildHtmlPage,
|
|
573
|
+
buildPartialHydrateAssets,
|
|
574
|
+
buildPartialHydrateIndex,
|
|
575
|
+
buildPartialModules,
|
|
576
|
+
buildPartialStringBundle,
|
|
577
|
+
buildPartialStringIndex,
|
|
578
|
+
buildPartialStringInitial,
|
|
342
579
|
buildRootEsmContent,
|
|
343
580
|
buildStaticData,
|
|
344
581
|
buildStaticPage,
|
package/dist/cli.js
CHANGED
|
@@ -29,9 +29,11 @@ import {
|
|
|
29
29
|
generateViteImporters,
|
|
30
30
|
generateTempRoot,
|
|
31
31
|
generateTempPages,
|
|
32
|
-
|
|
32
|
+
generateTempAssets,
|
|
33
|
+
generatePartialHydration,
|
|
33
34
|
generateNoStyleTemp,
|
|
34
35
|
generateHtmlPages,
|
|
36
|
+
generateAssets,
|
|
35
37
|
generatePublic,
|
|
36
38
|
generateDownload,
|
|
37
39
|
generateBeautify
|
|
@@ -77,16 +79,25 @@ cli.command("build [root]", "build for production").action(async () => {
|
|
|
77
79
|
emptyResolveDir(systemConfig.temp.assets.outDir),
|
|
78
80
|
emptyResolveDir(systemConfig.temp.pages.outDir),
|
|
79
81
|
emptyResolveDir(systemConfig.temp.viteImporter.outDir),
|
|
82
|
+
emptyResolveDir(systemConfig.temp.partialHydration.outDir),
|
|
80
83
|
emptyResolveDir(config.out)
|
|
81
84
|
]);
|
|
82
85
|
await Promise.all([generateViteImporters(config, viteConfig)]);
|
|
83
86
|
await Promise.all([
|
|
84
87
|
generateTempRoot(config, mdxConfig),
|
|
85
88
|
generateTempPages(config, mdxConfig),
|
|
86
|
-
|
|
89
|
+
generateTempAssets(config, viteConfig)
|
|
90
|
+
]);
|
|
91
|
+
await Promise.all([
|
|
92
|
+
generateNoStyleTemp(systemConfig.temp.root.outDir),
|
|
93
|
+
generateNoStyleTemp(systemConfig.temp.pages.outDir),
|
|
94
|
+
generatePartialHydration(config, mdxConfig, viteConfig)
|
|
95
|
+
]);
|
|
96
|
+
await Promise.all([
|
|
97
|
+
generateHtmlPages(config),
|
|
98
|
+
generateAssets(config),
|
|
99
|
+
generatePublic(config)
|
|
87
100
|
]);
|
|
88
|
-
await Promise.all([generateNoStyleTemp()]);
|
|
89
|
-
await Promise.all([generateHtmlPages(config), generatePublic(config)]);
|
|
90
101
|
await Promise.all([generateDownload(config)]);
|
|
91
102
|
await Promise.all([
|
|
92
103
|
generateBeautify(config, "html"),
|
package/dist/config.js
CHANGED
|
@@ -41,6 +41,20 @@ const defaultConfig = {
|
|
|
41
41
|
bundle: {
|
|
42
42
|
outName: "bundle"
|
|
43
43
|
},
|
|
44
|
+
partial: {
|
|
45
|
+
usePreact: false,
|
|
46
|
+
useIntersectionObserver: true,
|
|
47
|
+
outName: "partial",
|
|
48
|
+
rootAttrSuffix: "partial-hydration",
|
|
49
|
+
rootValuePrefix: "ph",
|
|
50
|
+
rootDOMElement: "div",
|
|
51
|
+
rootStyle: { display: "contents" },
|
|
52
|
+
intersectionObserverOptions: {
|
|
53
|
+
root: null,
|
|
54
|
+
rootMargin: "0px",
|
|
55
|
+
thresholds: [1]
|
|
56
|
+
}
|
|
57
|
+
},
|
|
44
58
|
images: {
|
|
45
59
|
outDir: "assets/images",
|
|
46
60
|
outName: "[name]"
|
package/dist/download.js
CHANGED
|
@@ -15,7 +15,7 @@ async function downloadFiles(entryPoints, remoteUrl, remoteName, downloadOutDir,
|
|
|
15
15
|
const html = await fs.readFile(entryPoint, "utf8");
|
|
16
16
|
const parsedHtml = parseHtml(html);
|
|
17
17
|
const imgTags = parsedHtml.getElementsByTagName("img");
|
|
18
|
-
const
|
|
18
|
+
const sourceTags = parsedHtml.getElementsByTagName("source");
|
|
19
19
|
if (imgTags.length > 0) {
|
|
20
20
|
for (const item of imgTags) {
|
|
21
21
|
const itemSrc = item.getAttribute("src");
|
|
@@ -34,8 +34,8 @@ async function downloadFiles(entryPoints, remoteUrl, remoteName, downloadOutDir,
|
|
|
34
34
|
}
|
|
35
35
|
}
|
|
36
36
|
}
|
|
37
|
-
if (
|
|
38
|
-
for (const item of
|
|
37
|
+
if (sourceTags.length > 0) {
|
|
38
|
+
for (const item of sourceTags) {
|
|
39
39
|
const itemSrc = item.getAttribute("src");
|
|
40
40
|
const itemSrcset = item.getAttribute("srcset");
|
|
41
41
|
if (itemSrc && matchSrcUrls(itemSrc, remoteUrl)) {
|
package/dist/esbuild.d.ts
CHANGED
|
@@ -8,3 +8,4 @@ export declare function resolvePlugin(options: {
|
|
|
8
8
|
export declare function svgrPlugin(options: SvgrOptions): Plugin;
|
|
9
9
|
/*! Fork: esbuild-plugin-resolve | https://github.com/hannoeru/esbuild-plugin-raw */
|
|
10
10
|
export declare function rawPlugin(): Plugin;
|
|
11
|
+
export declare function partialHydrationPlugin(): Plugin;
|
package/dist/esbuild.js
CHANGED
|
@@ -17,8 +17,33 @@ var __spreadValues = (a, b) => {
|
|
|
17
17
|
import React from "react";
|
|
18
18
|
import fs from "fs-extra";
|
|
19
19
|
import path from "path";
|
|
20
|
+
import { v4 as uuidv4 } from "uuid";
|
|
21
|
+
import { systemConfig } from "./system.js";
|
|
20
22
|
/*! Fork: esbuild-plugin-resolve | https://github.com/markwylde/esbuild-plugin-resolve */
|
|
21
23
|
function resolvePlugin(options) {
|
|
24
|
+
function resolvePluginIntercept(build, moduleName, moduleTarget) {
|
|
25
|
+
const filter = new RegExp("^" + moduleName + "(?:\\/.*)?$");
|
|
26
|
+
build.onResolve({ filter }, async (args) => {
|
|
27
|
+
if (args.resolveDir === "") {
|
|
28
|
+
return;
|
|
29
|
+
}
|
|
30
|
+
return {
|
|
31
|
+
path: args.path,
|
|
32
|
+
namespace: "esbuild-resolve",
|
|
33
|
+
pluginData: {
|
|
34
|
+
resolveDir: args.resolveDir,
|
|
35
|
+
moduleName
|
|
36
|
+
}
|
|
37
|
+
};
|
|
38
|
+
});
|
|
39
|
+
build.onLoad({ filter, namespace: "esbuild-resolve" }, async (args) => {
|
|
40
|
+
const importerCode = `
|
|
41
|
+
export * from '${args.path.replace(args.pluginData.moduleName, moduleTarget)}';
|
|
42
|
+
export { default } from '${args.path.replace(args.pluginData.moduleName, moduleTarget)}';
|
|
43
|
+
`;
|
|
44
|
+
return { contents: importerCode, resolveDir: args.pluginData.resolveDir };
|
|
45
|
+
});
|
|
46
|
+
}
|
|
22
47
|
return {
|
|
23
48
|
name: "esbuild-resolve",
|
|
24
49
|
setup: (build) => {
|
|
@@ -28,29 +53,6 @@ function resolvePlugin(options) {
|
|
|
28
53
|
}
|
|
29
54
|
};
|
|
30
55
|
}
|
|
31
|
-
function resolvePluginIntercept(build, moduleName, moduleTarget) {
|
|
32
|
-
const filter = new RegExp("^" + moduleName + "(?:\\/.*)?$");
|
|
33
|
-
build.onResolve({ filter }, async (args) => {
|
|
34
|
-
if (args.resolveDir === "") {
|
|
35
|
-
return;
|
|
36
|
-
}
|
|
37
|
-
return {
|
|
38
|
-
path: args.path,
|
|
39
|
-
namespace: "esbuild-resolve",
|
|
40
|
-
pluginData: {
|
|
41
|
-
resolveDir: args.resolveDir,
|
|
42
|
-
moduleName
|
|
43
|
-
}
|
|
44
|
-
};
|
|
45
|
-
});
|
|
46
|
-
build.onLoad({ filter, namespace: "esbuild-resolve" }, async (args) => {
|
|
47
|
-
const importerCode = `
|
|
48
|
-
export * from '${args.path.replace(args.pluginData.moduleName, moduleTarget)}';
|
|
49
|
-
export { default } from '${args.path.replace(args.pluginData.moduleName, moduleTarget)}';
|
|
50
|
-
`;
|
|
51
|
-
return { contents: importerCode, resolveDir: args.pluginData.resolveDir };
|
|
52
|
-
});
|
|
53
|
-
}
|
|
54
56
|
/*! Fork: esbuild-plugin-svgr | https://github.com/kazijawad/esbuild-plugin-svgr */
|
|
55
57
|
function svgrPlugin(options) {
|
|
56
58
|
return {
|
|
@@ -58,7 +60,7 @@ function svgrPlugin(options) {
|
|
|
58
60
|
setup(build) {
|
|
59
61
|
build.onLoad({ filter: /\.svg$/ }, async (args) => {
|
|
60
62
|
const { transform: transformSvgr } = await import("@svgr/core");
|
|
61
|
-
const svg = await fs.
|
|
63
|
+
const svg = await fs.readFile(args.path, "utf8");
|
|
62
64
|
const contents = await transformSvgr(svg, __spreadValues({}, options), { filePath: args.path });
|
|
63
65
|
return {
|
|
64
66
|
contents,
|
|
@@ -81,14 +83,44 @@ function rawPlugin() {
|
|
|
81
83
|
});
|
|
82
84
|
build.onLoad({ filter: /\?raw$/, namespace: "raw-loader" }, async (args) => {
|
|
83
85
|
return {
|
|
84
|
-
contents: await fs.
|
|
86
|
+
contents: await fs.readFile(args.path.replace(/\?raw$/, "")),
|
|
85
87
|
loader: "text"
|
|
86
88
|
};
|
|
87
89
|
});
|
|
88
90
|
}
|
|
89
91
|
};
|
|
90
92
|
}
|
|
93
|
+
function partialHydrationPlugin() {
|
|
94
|
+
return {
|
|
95
|
+
name: "esbuild-partial-hydration",
|
|
96
|
+
setup(build) {
|
|
97
|
+
build.onResolve({ filter: /\?ph$/ }, (args) => {
|
|
98
|
+
return {
|
|
99
|
+
path: path.isAbsolute(args.path) ? args.path : path.join(args.resolveDir, args.path),
|
|
100
|
+
namespace: "partial-hydration-loader"
|
|
101
|
+
};
|
|
102
|
+
});
|
|
103
|
+
build.onLoad({ filter: /\?ph$/, namespace: "partial-hydration-loader" }, async (args) => {
|
|
104
|
+
const jsPath = args.path.replace(/\?ph$/, "");
|
|
105
|
+
const uniqueId = uuidv4();
|
|
106
|
+
const underUniqueId = uniqueId.replace(/-/g, "_");
|
|
107
|
+
const outDir = systemConfig.temp.partialHydration.outDir;
|
|
108
|
+
const outFile = `${outDir}/modules/${underUniqueId}.txt`;
|
|
109
|
+
const template = `${jsPath}`;
|
|
110
|
+
await fs.outputFile(outFile, template).catch((err) => {
|
|
111
|
+
console.error(err);
|
|
112
|
+
});
|
|
113
|
+
const dummy = `export default () => <div data-partial-hydration="${underUniqueId}"></div>`;
|
|
114
|
+
return {
|
|
115
|
+
contents: dummy,
|
|
116
|
+
loader: "tsx"
|
|
117
|
+
};
|
|
118
|
+
});
|
|
119
|
+
}
|
|
120
|
+
};
|
|
121
|
+
}
|
|
91
122
|
export {
|
|
123
|
+
partialHydrationPlugin,
|
|
92
124
|
rawPlugin,
|
|
93
125
|
resolvePlugin,
|
|
94
126
|
svgrPlugin
|
package/dist/generate.d.ts
CHANGED
|
@@ -4,9 +4,11 @@ import type { MinistaResolveConfig } from "./types.js";
|
|
|
4
4
|
export declare function generateViteImporters(config: MinistaResolveConfig, viteConfig: ViteConfig): Promise<void>;
|
|
5
5
|
export declare function generateTempRoot(config: MinistaResolveConfig, mdxConfig: MdxOptions): Promise<void>;
|
|
6
6
|
export declare function generateTempPages(config: MinistaResolveConfig, mdxConfig: MdxOptions): Promise<void>;
|
|
7
|
-
export declare function
|
|
8
|
-
export declare function
|
|
7
|
+
export declare function generateTempAssets(config: MinistaResolveConfig, viteConfig: InlineConfig): Promise<void>;
|
|
8
|
+
export declare function generatePartialHydration(config: MinistaResolveConfig, mdxConfig: MdxOptions, viteConfig: InlineConfig): Promise<void>;
|
|
9
|
+
export declare function generateNoStyleTemp(targetDir: string): Promise<void>;
|
|
9
10
|
export declare function generateHtmlPages(config: MinistaResolveConfig): Promise<void>;
|
|
11
|
+
export declare function generateAssets(config: MinistaResolveConfig): Promise<void>;
|
|
10
12
|
export declare function generatePublic(config: MinistaResolveConfig): Promise<void>;
|
|
11
13
|
export declare function generateDownload(config: MinistaResolveConfig): Promise<void>;
|
|
12
14
|
export declare function generateBeautify(config: MinistaResolveConfig, target: "html" | "css" | "js"): Promise<void>;
|
package/dist/generate.js
CHANGED
|
@@ -1,4 +1,7 @@
|
|
|
1
1
|
import React from "react";
|
|
2
|
+
import fs from "fs-extra";
|
|
3
|
+
import path from "path";
|
|
4
|
+
import url from "url";
|
|
2
5
|
import { systemConfig } from "./system.js";
|
|
3
6
|
import { getFilePath, getFilePaths, getSameFilePaths } from "./path.js";
|
|
4
7
|
import { slashEnd, noSlashEnd } from "./utils.js";
|
|
@@ -11,11 +14,19 @@ import {
|
|
|
11
14
|
buildViteImporterRoots,
|
|
12
15
|
buildViteImporterRoutes,
|
|
13
16
|
buildViteImporterAssets,
|
|
14
|
-
buildViteImporterBlankAssets
|
|
17
|
+
buildViteImporterBlankAssets,
|
|
18
|
+
buildPartialModules,
|
|
19
|
+
buildPartialStringIndex,
|
|
20
|
+
buildPartialStringBundle,
|
|
21
|
+
buildPartialStringInitial,
|
|
22
|
+
buildPartialHydrateIndex,
|
|
23
|
+
buildPartialHydrateAssets
|
|
15
24
|
} from "./build.js";
|
|
16
25
|
import { optimizeCommentOutStyleImport } from "./optimize.js";
|
|
17
26
|
import { downloadFiles } from "./download.js";
|
|
18
27
|
import { beautifyFiles } from "./beautify.js";
|
|
28
|
+
const __filename = url.fileURLToPath(import.meta.url);
|
|
29
|
+
const __dirname = path.dirname(__filename);
|
|
19
30
|
async function generateViteImporters(config, viteConfig) {
|
|
20
31
|
var _a, _b;
|
|
21
32
|
const viteEntry = ((_b = (_a = viteConfig.build) == null ? void 0 : _a.rollupOptions) == null ? void 0 : _b.input) || {};
|
|
@@ -49,21 +60,60 @@ async function generateTempPages(config, mdxConfig) {
|
|
|
49
60
|
svgrOptions: config.assets.svgr.svgrOptions
|
|
50
61
|
});
|
|
51
62
|
}
|
|
52
|
-
async function
|
|
63
|
+
async function generateTempAssets(config, viteConfig) {
|
|
53
64
|
await buildTempAssets(viteConfig, {
|
|
65
|
+
input: path.resolve(__dirname + "/../dist/bundle.js"),
|
|
54
66
|
bundleOutName: config.assets.bundle.outName,
|
|
55
67
|
outDir: systemConfig.temp.assets.outDir,
|
|
56
|
-
assetDir: config.assets.outDir
|
|
68
|
+
assetDir: config.assets.outDir,
|
|
69
|
+
generateJs: false
|
|
57
70
|
});
|
|
58
71
|
await buildCopyDir(systemConfig.temp.assets.outDir, slashEnd(config.out) + noSlashEnd(config.assets.outDir), "assets");
|
|
59
72
|
}
|
|
60
|
-
async function
|
|
61
|
-
const
|
|
62
|
-
const
|
|
63
|
-
const
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
73
|
+
async function generatePartialHydration(config, mdxConfig, viteConfig) {
|
|
74
|
+
const moduleDir = systemConfig.temp.partialHydration.outDir + "/modules";
|
|
75
|
+
const moduleDirRelative = path.relative(".", moduleDir);
|
|
76
|
+
const moduleDirExists = fs.existsSync(moduleDirRelative);
|
|
77
|
+
if (!moduleDirExists) {
|
|
78
|
+
return;
|
|
79
|
+
}
|
|
80
|
+
const moduleFilePaths = await getFilePaths(moduleDir, "txt");
|
|
81
|
+
if (moduleFilePaths.length === 0) {
|
|
82
|
+
return;
|
|
83
|
+
}
|
|
84
|
+
const partialModules = await buildPartialModules(moduleFilePaths, config);
|
|
85
|
+
const outDir = systemConfig.temp.partialHydration.outDir;
|
|
86
|
+
const stringIndex = `${outDir}/string-index.mjs`;
|
|
87
|
+
const stringBundle = `${outDir}/string-bundle.mjs`;
|
|
88
|
+
const stringInitial = `${outDir}/string-initial.json`;
|
|
89
|
+
const hydrateIndex = `${outDir}/hydrate-index.mjs`;
|
|
90
|
+
await buildPartialStringIndex(partialModules, { outFile: stringIndex });
|
|
91
|
+
await buildPartialStringBundle(stringIndex, {
|
|
92
|
+
outFile: stringBundle,
|
|
93
|
+
mdxConfig,
|
|
94
|
+
svgrOptions: config.assets.svgr.svgrOptions
|
|
95
|
+
});
|
|
96
|
+
await optimizeCommentOutStyleImport([stringBundle]);
|
|
97
|
+
await buildPartialStringInitial(stringBundle, partialModules, {
|
|
98
|
+
outFile: stringInitial
|
|
99
|
+
});
|
|
100
|
+
await buildPartialHydrateIndex(partialModules, config, {
|
|
101
|
+
outFile: hydrateIndex
|
|
102
|
+
});
|
|
103
|
+
await buildPartialHydrateAssets(viteConfig, {
|
|
104
|
+
input: hydrateIndex,
|
|
105
|
+
bundleOutName: config.assets.partial.outName,
|
|
106
|
+
outDir: systemConfig.temp.assets.outDir,
|
|
107
|
+
assetDir: config.assets.outDir,
|
|
108
|
+
generateJs: true,
|
|
109
|
+
usePreact: config.assets.partial.usePreact
|
|
110
|
+
});
|
|
111
|
+
}
|
|
112
|
+
async function generateNoStyleTemp(targetDir) {
|
|
113
|
+
const targetFiles = await getFilePaths(targetDir, "mjs");
|
|
114
|
+
if (targetFiles.length !== 0) {
|
|
115
|
+
await optimizeCommentOutStyleImport(targetFiles);
|
|
116
|
+
}
|
|
67
117
|
}
|
|
68
118
|
async function generateHtmlPages(config) {
|
|
69
119
|
const tempRootName = config.root.srcName;
|
|
@@ -85,6 +135,9 @@ async function generateHtmlPages(config) {
|
|
|
85
135
|
outDir: config.pagesOutDir
|
|
86
136
|
}, assetsTagStr);
|
|
87
137
|
}
|
|
138
|
+
async function generateAssets(config) {
|
|
139
|
+
await buildCopyDir(systemConfig.temp.assets.outDir, slashEnd(config.out) + noSlashEnd(config.assets.outDir), "assets");
|
|
140
|
+
}
|
|
88
141
|
async function generatePublic(config) {
|
|
89
142
|
await buildCopyDir(config.public, config.publicOutDir, "public");
|
|
90
143
|
}
|
|
@@ -128,7 +181,9 @@ export {
|
|
|
128
181
|
generateDownload,
|
|
129
182
|
generateHtmlPages,
|
|
130
183
|
generateNoStyleTemp,
|
|
184
|
+
generatePartialHydration,
|
|
131
185
|
generatePublic,
|
|
186
|
+
generateTempAssets,
|
|
132
187
|
generateTempPages,
|
|
133
188
|
generateTempRoot,
|
|
134
189
|
generateViteImporters
|
package/dist/system.js
CHANGED
package/dist/types.d.ts
CHANGED
|
@@ -26,6 +26,20 @@ export declare type MinistaConfig = {
|
|
|
26
26
|
bundle: {
|
|
27
27
|
outName: string;
|
|
28
28
|
};
|
|
29
|
+
partial: {
|
|
30
|
+
usePreact: boolean;
|
|
31
|
+
useIntersectionObserver: boolean;
|
|
32
|
+
outName: string;
|
|
33
|
+
rootAttrSuffix: string;
|
|
34
|
+
rootValuePrefix: string;
|
|
35
|
+
rootDOMElement: "div" | "span";
|
|
36
|
+
rootStyle: React.CSSProperties;
|
|
37
|
+
intersectionObserverOptions: {
|
|
38
|
+
root: Element | null;
|
|
39
|
+
rootMargin: string;
|
|
40
|
+
thresholds: ReadonlyArray<number>;
|
|
41
|
+
};
|
|
42
|
+
};
|
|
29
43
|
images: {
|
|
30
44
|
outDir: string;
|
|
31
45
|
outName: string;
|
|
@@ -87,6 +101,20 @@ export declare type MinistaUserConfig = {
|
|
|
87
101
|
bundle?: {
|
|
88
102
|
outName?: string;
|
|
89
103
|
};
|
|
104
|
+
partial?: {
|
|
105
|
+
usePreact?: boolean;
|
|
106
|
+
useIntersectionObserver?: boolean;
|
|
107
|
+
outName?: string;
|
|
108
|
+
rootAttrSuffix?: string;
|
|
109
|
+
rootValuePrefix?: string;
|
|
110
|
+
rootDOMElement?: "div" | "span";
|
|
111
|
+
rootStyle?: React.CSSProperties;
|
|
112
|
+
intersectionObserverOptions?: {
|
|
113
|
+
root?: Element | null;
|
|
114
|
+
rootMargin?: string;
|
|
115
|
+
thresholds?: ReadonlyArray<number>;
|
|
116
|
+
};
|
|
117
|
+
};
|
|
90
118
|
images?: {
|
|
91
119
|
outDir?: string;
|
|
92
120
|
outName?: string;
|
|
@@ -163,6 +191,9 @@ export declare type MinistaSystemConfig = {
|
|
|
163
191
|
viteImporter: {
|
|
164
192
|
outDir: string;
|
|
165
193
|
};
|
|
194
|
+
partialHydration: {
|
|
195
|
+
outDir: string;
|
|
196
|
+
};
|
|
166
197
|
root: {
|
|
167
198
|
outDir: string;
|
|
168
199
|
};
|
|
@@ -226,3 +257,17 @@ export declare type StaticDataCache = {
|
|
|
226
257
|
key: [StaticDataList];
|
|
227
258
|
} | {};
|
|
228
259
|
export declare type GetStaticData = () => Promise<StaticData>;
|
|
260
|
+
export declare type PartialModules = {
|
|
261
|
+
id: string;
|
|
262
|
+
phId: string;
|
|
263
|
+
phDomId: string;
|
|
264
|
+
htmlId: string;
|
|
265
|
+
targetsId: string;
|
|
266
|
+
importer: string;
|
|
267
|
+
rootAttr: string;
|
|
268
|
+
rootDOMElement: string;
|
|
269
|
+
rootStyleStr: string;
|
|
270
|
+
}[];
|
|
271
|
+
export declare type PartialString = {
|
|
272
|
+
[key: string]: string;
|
|
273
|
+
};
|
package/dist/utils.d.ts
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
|
+
/// <reference types="react" />
|
|
1
2
|
export declare function slashEnd(dir: string): string;
|
|
2
3
|
export declare function noSlashEnd(dir: string): string;
|
|
3
4
|
export declare function getFilename(fullPath: string): string;
|
|
4
5
|
export declare function getFilenameObject(fullPaths: string[]): any;
|
|
5
6
|
export declare function valueToStringObject(obj: {} | any | undefined): any;
|
|
6
7
|
export declare function sortObject(obj: {} | undefined): [string, unknown][] | undefined;
|
|
8
|
+
export declare function reactStylesToString(styles: React.CSSProperties): string;
|
package/dist/utils.js
CHANGED
|
@@ -54,10 +54,20 @@ function sortObject(obj) {
|
|
|
54
54
|
}
|
|
55
55
|
return sorted;
|
|
56
56
|
}
|
|
57
|
+
function reactStylesToString(styles) {
|
|
58
|
+
const result = Object.entries(styles).map(([key, value]) => {
|
|
59
|
+
const reg = new RegExp(/[A-Z]/g);
|
|
60
|
+
const cssKey = key.replace(reg, (v) => `-${v.toLowerCase()}`);
|
|
61
|
+
const cssValue = value;
|
|
62
|
+
return `${cssKey}:${cssValue};`;
|
|
63
|
+
}).join("");
|
|
64
|
+
return result;
|
|
65
|
+
}
|
|
57
66
|
export {
|
|
58
67
|
getFilename,
|
|
59
68
|
getFilenameObject,
|
|
60
69
|
noSlashEnd,
|
|
70
|
+
reactStylesToString,
|
|
61
71
|
slashEnd,
|
|
62
72
|
sortObject,
|
|
63
73
|
valueToStringObject
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "minista",
|
|
3
3
|
"description": "Next.js Like Development with 100% Static Generate",
|
|
4
|
-
"version": "2.
|
|
4
|
+
"version": "2.4.2",
|
|
5
5
|
"bin": {
|
|
6
6
|
"minista": "./bin/minista.js"
|
|
7
7
|
},
|
|
@@ -72,17 +72,16 @@
|
|
|
72
72
|
},
|
|
73
73
|
"dependencies": {
|
|
74
74
|
"@mdx-js/esbuild": "^2.1.1",
|
|
75
|
-
"@mdx-js/react": "^2.1.1",
|
|
76
75
|
"@mdx-js/rollup": "^2.1.1",
|
|
77
76
|
"@svgr/core": "^6.2.1",
|
|
78
|
-
"@vitejs/plugin-react": "^1.3.
|
|
77
|
+
"@vitejs/plugin-react": "^1.3.2",
|
|
79
78
|
"cac": "^6.7.12",
|
|
80
|
-
"deepmerge-ts": "^4.0.
|
|
81
|
-
"esbuild": "^0.14.
|
|
82
|
-
"fs-extra": "^10.0
|
|
83
|
-
"js-beautify": "^1.14.
|
|
79
|
+
"deepmerge-ts": "^4.0.3",
|
|
80
|
+
"esbuild": "^0.14.38",
|
|
81
|
+
"fs-extra": "^10.1.0",
|
|
82
|
+
"js-beautify": "^1.14.3",
|
|
84
83
|
"mime-types": "^2.1.35",
|
|
85
|
-
"node-fetch": "^3.2.
|
|
84
|
+
"node-fetch": "^3.2.4",
|
|
86
85
|
"node-html-parser": "^5.3.3",
|
|
87
86
|
"picocolors": "^1.0.0",
|
|
88
87
|
"react-helmet": "^6.1.0",
|
|
@@ -94,20 +93,22 @@
|
|
|
94
93
|
"srcset": "^5.0.0",
|
|
95
94
|
"svgstore": "^3.0.1",
|
|
96
95
|
"tiny-glob": "^0.2.9",
|
|
97
|
-
"
|
|
96
|
+
"uuid": "^8.3.2",
|
|
97
|
+
"vite": "^2.9.8"
|
|
98
98
|
},
|
|
99
99
|
"devDependencies": {
|
|
100
100
|
"@types/fs-extra": "^9.0.13",
|
|
101
101
|
"@types/js-beautify": "^1.13.3",
|
|
102
102
|
"@types/mime-types": "^2.1.1",
|
|
103
|
-
"@types/node": "^17.0.
|
|
104
|
-
"@types/react": "^17.0.
|
|
105
|
-
"@types/react-dom": "^17.0.
|
|
103
|
+
"@types/node": "^17.0.31",
|
|
104
|
+
"@types/react": "^17.0.45",
|
|
105
|
+
"@types/react-dom": "^17.0.16",
|
|
106
106
|
"@types/react-helmet": "^6.1.5",
|
|
107
|
+
"@types/uuid": "^8.3.4",
|
|
107
108
|
"react": "^17.0.2",
|
|
108
109
|
"react-dom": "^17.0.2",
|
|
109
|
-
"tsup": "^5.12.
|
|
110
|
-
"typescript": "^4.6.
|
|
111
|
-
"vitest": "^0.
|
|
110
|
+
"tsup": "^5.12.7",
|
|
111
|
+
"typescript": "^4.6.4",
|
|
112
|
+
"vitest": "^0.12.0"
|
|
112
113
|
}
|
|
113
114
|
}
|