minista 2.6.0 → 2.7.0

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 CHANGED
@@ -18,7 +18,7 @@ https://minista.qranoko.jp
18
18
 
19
19
  ## About
20
20
 
21
- minista(ミニスタ)は、React の JSX で書けるスタティックサイトジェネレーターです。Next.js 風の快適な環境で開発しながら 100% 静的な出力を行えます。SaaS の web テンプレートコーディング業務を想定しているため、ビルド後のデータが綺麗(ヒューマンリーダブル)です。
21
+ minista(ミニスタ)は、React の JSX で書けるスタティックサイトジェネレーターです。Next.js 風の快適な環境で開発しながら 100% 静的に出力できます。SaaS の web テンプレートコーディング業務を想定しているため、ビルド後のデータが綺麗(ヒューマンリーダブル)です。
22
22
 
23
23
  ## How To Use
24
24
 
@@ -165,6 +165,24 @@ export default defineConfig({
165
165
  rehypePlugins: [], // https://mdxjs.com/packages/mdx/#optionsrehypeplugins
166
166
  },
167
167
  },
168
+ search: {
169
+ useJson: false, // boolean
170
+ cache: false, // boolean
171
+ outDir: "assets", // string
172
+ outName: "search", // string
173
+ include: ["**/*"], // string[]
174
+ exclude: ["404"], // string[]
175
+ trimTitle: "", // string
176
+ targetSelector: "[data-search]", // string
177
+ hit: {
178
+ minLength: 3, // number
179
+ number: false, // boolean
180
+ english: true, // boolean
181
+ hiragana: false, // boolean
182
+ katakana: true, // boolean
183
+ kanji: true, // boolean
184
+ },
185
+ },
168
186
  beautify: {
169
187
  useHtml: true, // boolean
170
188
  useAssets: false, // boolean
package/dist/build.d.ts CHANGED
@@ -1,27 +1,47 @@
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, MinistaResolveAlias, RootStaticContent, RootJsxContent, GlobalStaticData, GetGlobalStaticData, PageJsxContent, StaticData, StaticDataItem, GetStaticData, PartialModules, CssOptions } from "./types.js";
4
+ import type { MinistaResolveConfig, RootStaticContent, RootJsxContent, GlobalStaticData, GetGlobalStaticData, PageJsxContent, StaticData, StaticDataItem, GetStaticData, AliasArray, PartialModules, CssOptions } from "./types.js";
5
5
  export declare function buildTempPages(entryPoints: string[], buildOptions: {
6
6
  outBase: string;
7
7
  outDir: string;
8
- alias: MinistaResolveAlias;
8
+ alias: AliasArray;
9
9
  mdxConfig: MdxOptions;
10
10
  svgrOptions: SvgrOptions;
11
11
  cssOptions: CssOptions;
12
12
  }): Promise<void>;
13
- export declare function buildStaticPages(entryPoints: string[], tempRootFilePath: string, buildOptions: {
13
+ export declare function buildStaticPages({ entryPoints, tempRootFilePath, outBase, outDir, assetsTagStr, showLog, }: {
14
+ entryPoints: string[];
15
+ tempRootFilePath: string;
14
16
  outBase: string;
15
17
  outDir: string;
16
- }, assetsTagStr: string): Promise<void>;
18
+ assetsTagStr: string;
19
+ showLog: boolean;
20
+ }): Promise<void>;
17
21
  export declare function buildRootEsmContent(tempRootFilePath: string): Promise<{
18
22
  component: RootJsxContent;
19
23
  staticData: GlobalStaticData;
20
24
  }>;
21
25
  export declare function buildGlobalStaticData(getGlobalStaticData: GetGlobalStaticData): Promise<GlobalStaticData>;
22
- export declare function buildStaticPage(entryPoint: string, outFile: string, rootStaticContent: RootStaticContent, assetsTagStr: string, outDir: string): Promise<void>;
26
+ export declare function buildStaticPage({ entryPoint, outFile, rootStaticContent, assetsTagStr, outDir, showLog, }: {
27
+ entryPoint: string;
28
+ outFile: string;
29
+ rootStaticContent: RootStaticContent;
30
+ assetsTagStr: string;
31
+ outDir: string;
32
+ showLog: boolean;
33
+ }): Promise<void>;
23
34
  export declare function buildStaticData(getStaticData: GetStaticData): Promise<StaticData>;
24
- export declare function buildHtmlPage(pageJsxContent: PageJsxContent, staticDataItem: StaticDataItem, routePath: string, rootStaticContent: RootStaticContent, assetsTagStr: string, frontmatter: any, outDir: string): Promise<void>;
35
+ export declare function buildHtmlPage({ pageJsxContent, staticDataItem, routePath, rootStaticContent, assetsTagStr, frontmatter, outDir, showLog, }: {
36
+ pageJsxContent: PageJsxContent;
37
+ staticDataItem: StaticDataItem;
38
+ routePath: string;
39
+ rootStaticContent: RootStaticContent;
40
+ assetsTagStr: string;
41
+ frontmatter: any;
42
+ outDir: string;
43
+ showLog: boolean;
44
+ }): Promise<void>;
25
45
  export declare function buildTempAssets(viteConfig: InlineConfig, buildOptions: {
26
46
  input: string;
27
47
  bundleOutName: string;
@@ -44,7 +64,7 @@ export declare function buildPartialStringIndex(partialModules: PartialModules,
44
64
  }): Promise<void>;
45
65
  export declare function buildPartialStringBundle(entryPoint: string, buildOptions: {
46
66
  outFile: string;
47
- alias: MinistaResolveAlias;
67
+ alias: AliasArray;
48
68
  mdxConfig: MdxOptions;
49
69
  svgrOptions: SvgrOptions;
50
70
  cssOptions: CssOptions;
@@ -62,4 +82,12 @@ export declare function buildPartialHydrateAssets(viteConfig: InlineConfig, buil
62
82
  assetDir: string;
63
83
  usePreact: boolean;
64
84
  }): Promise<void>;
85
+ export declare function buildSearchJson({ config, useCacheExists, entryPoints, entryBase, outFile, showLog, }: {
86
+ config: MinistaResolveConfig;
87
+ useCacheExists: boolean;
88
+ entryPoints: string[];
89
+ entryBase: string;
90
+ outFile: string;
91
+ showLog: boolean;
92
+ }): Promise<void>;
65
93
  export declare function buildCopyDir(targetDir: string, outDir: string, log?: "public" | "assets"): Promise<void>;
package/dist/build.js CHANGED
@@ -30,10 +30,11 @@ import {
30
30
  defineConfig as defineViteConfig,
31
31
  mergeConfig as mergeViteConfig
32
32
  } from "vite";
33
+ import { parse } from "node-html-parser";
34
+ import mojigiri from "mojigiri";
33
35
  import { systemConfig } from "./system.js";
34
36
  import { getFilePath } from "./path.js";
35
37
  import {
36
- getEsbuildAlias,
37
38
  resolvePlugin,
38
39
  svgrPlugin,
39
40
  rawPlugin,
@@ -41,7 +42,7 @@ import {
41
42
  } from "./esbuild.js";
42
43
  import { renderHtml } from "./render.js";
43
44
  import { slashEnd, reactStylesToString } from "./utils.js";
44
- import { CssModulePlugin } from "./css.js";
45
+ import { cssModulePlugin } from "./css.js";
45
46
  const __filename = url.fileURLToPath(import.meta.url);
46
47
  const __dirname = path.dirname(__filename);
47
48
  const ministaPkgUrl = path.resolve(__dirname + "/../package.json");
@@ -72,18 +73,11 @@ const esbuildLoaders = {
72
73
  ".woff": "file",
73
74
  ".woff2": "file"
74
75
  };
75
- const esbuildAlias = [
76
- {
77
- find: "react/jsx-runtime",
78
- replacement: "react/jsx-runtime.js"
79
- }
80
- ];
81
76
  const userPkgHasPreact = [
82
77
  ...Object.keys(userPkg.dependencies || {}),
83
78
  ...Object.keys(userPkg.devDependencies || {})
84
79
  ].includes("preact");
85
80
  async function buildTempPages(entryPoints, buildOptions) {
86
- const alias = getEsbuildAlias([esbuildAlias, buildOptions.alias]);
87
81
  await esBuild({
88
82
  entryPoints,
89
83
  outbase: buildOptions.outBase,
@@ -99,24 +93,38 @@ async function buildTempPages(entryPoints, buildOptions) {
99
93
  external: esbuildExternals,
100
94
  loader: esbuildLoaders,
101
95
  plugins: [
102
- resolvePlugin(alias),
103
- CssModulePlugin(buildOptions.cssOptions),
96
+ resolvePlugin({ "react/jsx-runtime": "react/jsx-runtime.js" }),
97
+ cssModulePlugin(buildOptions.cssOptions, buildOptions.alias),
104
98
  mdx(buildOptions.mdxConfig),
105
99
  svgrPlugin(buildOptions.svgrOptions),
106
- rawPlugin(),
107
- partialHydrationPlugin()
100
+ rawPlugin(buildOptions.alias),
101
+ partialHydrationPlugin(buildOptions.alias)
108
102
  ]
109
103
  }).catch(() => process.exit(1));
110
104
  }
111
- async function buildStaticPages(entryPoints, tempRootFilePath, buildOptions, assetsTagStr) {
105
+ async function buildStaticPages({
106
+ entryPoints,
107
+ tempRootFilePath,
108
+ outBase,
109
+ outDir,
110
+ assetsTagStr,
111
+ showLog
112
+ }) {
112
113
  const rootStaticContent = await buildRootEsmContent(tempRootFilePath);
113
- const winOutBase = buildOptions.outBase.replaceAll("/", "\\");
114
+ const winOutBase = outBase.replaceAll("/", "\\");
114
115
  await Promise.all(entryPoints.map(async (entryPoint) => {
115
116
  const extname = path.extname(entryPoint);
116
117
  const basename = path.basename(entryPoint, extname);
117
- const dirname = path.dirname(entryPoint).replace(buildOptions.outBase, buildOptions.outDir).replace(winOutBase, buildOptions.outDir);
118
+ const dirname = path.dirname(entryPoint).replace(outBase, outDir).replace(winOutBase, outDir);
118
119
  const filename = path.join(dirname, basename + ".html");
119
- await buildStaticPage(entryPoint, filename, rootStaticContent, assetsTagStr, buildOptions.outDir);
120
+ await buildStaticPage({
121
+ entryPoint,
122
+ outFile: filename,
123
+ rootStaticContent,
124
+ assetsTagStr,
125
+ outDir,
126
+ showLog
127
+ });
120
128
  }));
121
129
  }
122
130
  async function buildRootEsmContent(tempRootFilePath) {
@@ -138,7 +146,14 @@ async function buildGlobalStaticData(getGlobalStaticData) {
138
146
  const response = await getGlobalStaticData();
139
147
  return response;
140
148
  }
141
- async function buildStaticPage(entryPoint, outFile, rootStaticContent, assetsTagStr, outDir) {
149
+ async function buildStaticPage({
150
+ entryPoint,
151
+ outFile,
152
+ rootStaticContent,
153
+ assetsTagStr,
154
+ outDir,
155
+ showLog
156
+ }) {
142
157
  const targetFilePath = url.pathToFileURL(entryPoint).href;
143
158
  const pageEsmContent = await import(targetFilePath);
144
159
  const pageJsxContent = pageEsmContent.default;
@@ -147,11 +162,29 @@ async function buildStaticPage(entryPoint, outFile, rootStaticContent, assetsTag
147
162
  const staticData = pageEsmContent.getStaticData ? await buildStaticData(pageEsmContent.getStaticData) : void 0;
148
163
  if (!staticData) {
149
164
  const staticDataItem = defaultStaticDataItem;
150
- return await buildHtmlPage(pageJsxContent, staticDataItem, outFile, rootStaticContent, assetsTagStr, frontmatter, outDir);
165
+ return await buildHtmlPage({
166
+ pageJsxContent,
167
+ staticDataItem,
168
+ routePath: outFile,
169
+ rootStaticContent,
170
+ assetsTagStr,
171
+ frontmatter,
172
+ outDir,
173
+ showLog
174
+ });
151
175
  }
152
176
  if ("props" in staticData && "paths" in staticData === false) {
153
177
  const staticDataItem = __spreadValues(__spreadValues({}, defaultStaticDataItem), staticData);
154
- return await buildHtmlPage(pageJsxContent, staticDataItem, outFile, rootStaticContent, assetsTagStr, frontmatter, outDir);
178
+ return await buildHtmlPage({
179
+ pageJsxContent,
180
+ staticDataItem,
181
+ routePath: outFile,
182
+ rootStaticContent,
183
+ assetsTagStr,
184
+ frontmatter,
185
+ outDir,
186
+ showLog
187
+ });
155
188
  }
156
189
  if ("paths" in staticData) {
157
190
  const staticDataItem = __spreadValues(__spreadValues({}, defaultStaticDataItem), staticData);
@@ -160,7 +193,16 @@ async function buildStaticPage(entryPoint, outFile, rootStaticContent, assetsTag
160
193
  const reg = new RegExp("\\[" + key + "\\]", "g");
161
194
  fixedOutfile = fixedOutfile.replace(reg, `${value}`);
162
195
  }
163
- return await buildHtmlPage(pageJsxContent, staticDataItem, fixedOutfile, rootStaticContent, assetsTagStr, frontmatter, outDir);
196
+ return await buildHtmlPage({
197
+ pageJsxContent,
198
+ staticDataItem,
199
+ routePath: fixedOutfile,
200
+ rootStaticContent,
201
+ assetsTagStr,
202
+ frontmatter,
203
+ outDir,
204
+ showLog
205
+ });
164
206
  }
165
207
  if (Array.isArray(staticData) && staticData.length > 0) {
166
208
  const entryPoints = staticData;
@@ -171,7 +213,16 @@ async function buildStaticPage(entryPoint, outFile, rootStaticContent, assetsTag
171
213
  const reg = new RegExp("\\[" + key + "\\]", "g");
172
214
  fixedOutfile = fixedOutfile.replace(reg, `${value}`);
173
215
  }
174
- return await buildHtmlPage(pageJsxContent, staticDataItem, fixedOutfile, rootStaticContent, assetsTagStr, frontmatter, outDir);
216
+ return await buildHtmlPage({
217
+ pageJsxContent,
218
+ staticDataItem,
219
+ routePath: fixedOutfile,
220
+ rootStaticContent,
221
+ assetsTagStr,
222
+ frontmatter,
223
+ outDir,
224
+ showLog
225
+ });
175
226
  }));
176
227
  }
177
228
  }
@@ -179,7 +230,16 @@ async function buildStaticData(getStaticData) {
179
230
  const response = await getStaticData();
180
231
  return response;
181
232
  }
182
- async function buildHtmlPage(pageJsxContent, staticDataItem, routePath, rootStaticContent, assetsTagStr, frontmatter, outDir) {
233
+ async function buildHtmlPage({
234
+ pageJsxContent,
235
+ staticDataItem,
236
+ routePath,
237
+ rootStaticContent,
238
+ assetsTagStr,
239
+ frontmatter,
240
+ outDir,
241
+ showLog
242
+ }) {
183
243
  if (frontmatter == null ? void 0 : frontmatter.draft) {
184
244
  return;
185
245
  }
@@ -235,7 +295,7 @@ async function buildHtmlPage(pageJsxContent, staticDataItem, routePath, rootStat
235
295
  }
236
296
  const replacedHtml = html[0].replace(/<div class="minista-comment" hidden="">(.+?)<\/div>/g, "\n<!-- $1 -->");
237
297
  await fs.outputFile(routePath, replacedHtml).then(() => {
238
- console.log(`${pc.bold(pc.green("BUILD"))} ${pc.bold(routePath)}`);
298
+ showLog && console.log(`${pc.bold(pc.green("BUILD"))} ${pc.bold(routePath)}`);
239
299
  }).catch((err) => {
240
300
  console.error(err);
241
301
  });
@@ -426,7 +486,6 @@ export { ${tmpExportsStr} }`;
426
486
  });
427
487
  }
428
488
  async function buildPartialStringBundle(entryPoint, buildOptions) {
429
- const alias = getEsbuildAlias([esbuildAlias, buildOptions.alias]);
430
489
  await esBuild({
431
490
  entryPoints: [entryPoint],
432
491
  outfile: buildOptions.outFile,
@@ -439,11 +498,11 @@ async function buildPartialStringBundle(entryPoint, buildOptions) {
439
498
  external: esbuildExternals,
440
499
  loader: esbuildLoaders,
441
500
  plugins: [
442
- resolvePlugin(alias),
443
- CssModulePlugin(buildOptions.cssOptions),
501
+ resolvePlugin({ "react/jsx-runtime": "react/jsx-runtime.js" }),
502
+ cssModulePlugin(buildOptions.cssOptions, buildOptions.alias),
444
503
  mdx(buildOptions.mdxConfig),
445
504
  svgrPlugin(buildOptions.svgrOptions),
446
- rawPlugin()
505
+ rawPlugin(buildOptions.alias)
447
506
  ]
448
507
  }).catch(() => process.exit(1));
449
508
  }
@@ -534,7 +593,7 @@ async function buildPartialHydrateAssets(viteConfig, buildOptions) {
534
593
  resolve: {
535
594
  alias: activePreact ? resolveAliasPreact : {}
536
595
  },
537
- customLogger: viteConfig.customLogger
596
+ logLevel: "error"
538
597
  });
539
598
  const mergedConfig = mergeViteConfig({}, customConfig);
540
599
  const result = await viteBuild(mergedConfig);
@@ -554,6 +613,134 @@ async function buildPartialHydrateAssets(viteConfig, buildOptions) {
554
613
  });
555
614
  }
556
615
  }
616
+ async function buildSearchJson({
617
+ config,
618
+ useCacheExists,
619
+ entryPoints,
620
+ entryBase,
621
+ outFile,
622
+ showLog
623
+ }) {
624
+ if (useCacheExists) {
625
+ return;
626
+ }
627
+ const { trimTitle, targetSelector, hit } = config.search;
628
+ const tempWords = [];
629
+ const tempPages = [];
630
+ await Promise.all(entryPoints.map(async (filePath) => {
631
+ const html = await fs.readFile(filePath, { encoding: "utf-8" });
632
+ const parsedHtml = parse(html, {
633
+ blockTextElements: { script: false, style: false, pre: false }
634
+ });
635
+ const regTrimPath = new RegExp(`^${entryBase}|index|.html`, "g");
636
+ const path2 = filePath.replace(regTrimPath, "");
637
+ const regTrimTitle = new RegExp(trimTitle);
638
+ const pTitle = parsedHtml.querySelector("title");
639
+ const title = pTitle ? pTitle.rawText.replace(regTrimTitle, "") : "";
640
+ const titleArray = mojigiri(title);
641
+ const targetContent = parsedHtml.querySelector(targetSelector);
642
+ if (!targetContent) {
643
+ tempWords.push(title);
644
+ tempPages.push({
645
+ path: path2,
646
+ toc: [],
647
+ title: titleArray,
648
+ content: []
649
+ });
650
+ return;
651
+ }
652
+ const contents = [];
653
+ async function getContent(element) {
654
+ if (element.id) {
655
+ contents.push({ type: "id", value: [element.id] });
656
+ }
657
+ if (element._rawText) {
658
+ const text = element._rawText.replace(/\n/g, "").replace(/\s{2,}/g, " ").trim();
659
+ const words2 = mojigiri(text);
660
+ if (words2.length > 0) {
661
+ contents.push({ type: "words", value: words2 });
662
+ }
663
+ }
664
+ if (element.childNodes) {
665
+ await Promise.all(element.childNodes.map(async (childNode) => {
666
+ return await getContent(childNode);
667
+ }));
668
+ }
669
+ return;
670
+ }
671
+ await getContent(targetContent);
672
+ const toc = [];
673
+ const contentArray = [];
674
+ let contentCount = 0;
675
+ contents.forEach((content) => {
676
+ if (content.type === "id") {
677
+ toc.push([contentCount, content.value[0]]);
678
+ return;
679
+ } else if (content.type === "words") {
680
+ contentArray.push(content.value);
681
+ contentCount = contentCount + content.value.length;
682
+ return;
683
+ }
684
+ });
685
+ const body = targetContent.rawText.replace(/\n/g, "").replace(/\s{2,}/g, " ").trim();
686
+ tempWords.push(title);
687
+ tempWords.push(body);
688
+ tempPages.push({
689
+ path: path2,
690
+ toc,
691
+ title: titleArray,
692
+ content: contentArray.flat()
693
+ });
694
+ }));
695
+ const words = mojigiri(tempWords.join(" "));
696
+ const sortedWords = [...new Set(words)].sort();
697
+ const regHitsArray = [
698
+ hit.number && "[0-9]",
699
+ hit.english && "[a-zA-Z]",
700
+ hit.hiragana && "[\u3041-\u3093]",
701
+ hit.katakana && "[\u30A1-\u30F4]",
702
+ hit.kanji && "[\u2E80-\u2E99\u2E9B-\u2EF3\u2F00-\u2FD5\u3005\u3007\u3021-\u3029\u3038-\u303B\u3400-\u4DB5\u4E00-\u9FC3\uF900-\uFA2D\uFA30-\uFA6A\uFA70-\uFAD9]"
703
+ ].filter((reg) => reg);
704
+ const regHits = new RegExp(`(${regHitsArray.join("|")})`);
705
+ const tempHits = sortedWords.filter((word) => word.length >= hit.minLength && regHits.test(word) && word !== "...");
706
+ const hits = tempHits.map((word) => {
707
+ return sortedWords.indexOf(word);
708
+ });
709
+ const pages = [];
710
+ await Promise.all(tempPages.map(async (page) => {
711
+ const path2 = page.path;
712
+ const toc = page.toc;
713
+ const title = page.title.map((word) => {
714
+ return sortedWords.indexOf(word);
715
+ });
716
+ const content = page.content.map((word) => {
717
+ return sortedWords.indexOf(word);
718
+ });
719
+ pages.push({ path: path2, title, toc, content });
720
+ }));
721
+ const sortedPages = pages.sort((a, b) => {
722
+ const pathA = a.path.toUpperCase();
723
+ const pathB = b.path.toUpperCase();
724
+ if (pathA < pathB) {
725
+ return -1;
726
+ }
727
+ if (pathA > pathB) {
728
+ return 1;
729
+ }
730
+ return 0;
731
+ });
732
+ const template = {
733
+ words: sortedWords,
734
+ hits,
735
+ pages: sortedPages
736
+ };
737
+ await fs.outputJson(outFile, template).then(() => {
738
+ showLog && console.log(`${pc.bold(pc.green("BUILD"))} ${pc.bold(outFile)}`);
739
+ }).catch((err) => {
740
+ console.error(err);
741
+ });
742
+ return;
743
+ }
557
744
  async function buildCopyDir(targetDir, outDir, log) {
558
745
  const checkTargetDir = await fs.pathExists(targetDir);
559
746
  if (checkTargetDir) {
@@ -583,6 +770,7 @@ export {
583
770
  buildPartialStringIndex,
584
771
  buildPartialStringInitial,
585
772
  buildRootEsmContent,
773
+ buildSearchJson,
586
774
  buildStaticData,
587
775
  buildStaticPage,
588
776
  buildStaticPages,
package/dist/cli.js CHANGED
@@ -23,7 +23,7 @@ import { systemConfig } from "./system.js";
23
23
  import { getViteConfig } from "./vite.js";
24
24
  import { getMdxConfig } from "./mdx.js";
25
25
  import { emptyResolveDir } from "./empty.js";
26
- import { createDevServer } from "./server.js";
26
+ import { createDevServer, createDevServerAssets } from "./server.js";
27
27
  import { previewLocal } from "./preview.js";
28
28
  import {
29
29
  generateViteImporters,
@@ -36,6 +36,7 @@ import {
36
36
  generateAssets,
37
37
  generatePublic,
38
38
  generateDownload,
39
+ generateSearchJson,
39
40
  generateBeautify
40
41
  } from "./generate.js";
41
42
  const cli = cac("minista");
@@ -58,11 +59,18 @@ cli.command("[root]", "start dev server").alias("dev").option("--host [host]", `
58
59
  const mdxConfig = await getMdxConfig(config);
59
60
  const viteConfig = await getViteConfig(config, mdxConfig, cliOptions);
60
61
  await Promise.all([
62
+ emptyResolveDir(systemConfig.temp.root.outDir),
63
+ emptyResolveDir(systemConfig.temp.assets.outDir),
64
+ emptyResolveDir(systemConfig.temp.pages.outDir),
61
65
  emptyResolveDir(systemConfig.temp.viteImporter.outDir),
62
- emptyResolveDir(systemConfig.temp.icons.outDir)
66
+ emptyResolveDir(systemConfig.temp.icons.outDir),
67
+ emptyResolveDir(systemConfig.temp.partialHydration.outDir)
63
68
  ]);
64
69
  await generateViteImporters(config, viteConfig);
65
- await createDevServer(viteConfig);
70
+ await Promise.all([
71
+ createDevServer(viteConfig),
72
+ createDevServerAssets(config, mdxConfig)
73
+ ]);
66
74
  } catch (err) {
67
75
  console.log(err);
68
76
  process.exit(1);
@@ -94,11 +102,11 @@ cli.command("build [root]", "build for production").action(async () => {
94
102
  generatePartialHydration(config, mdxConfig, viteConfig)
95
103
  ]);
96
104
  await Promise.all([
97
- generateHtmlPages(config),
105
+ generateHtmlPages(config, config.pagesOutDir, true),
98
106
  generateAssets(config),
99
107
  generatePublic(config)
100
108
  ]);
101
- await Promise.all([generateDownload(config)]);
109
+ await Promise.all([generateDownload(config), generateSearchJson(config)]);
102
110
  await Promise.all([
103
111
  generateBeautify(config, "html"),
104
112
  generateBeautify(config, "css"),
package/dist/config.d.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  import type { AliasOptions as ViteAliasOptions } from "vite";
2
- import type { MinistaConfig, MinistaUserConfig, MinistaResolveConfig, MinistaResolveAliasInput, MinistaResolveAlias } from "./types.js";
2
+ import type { MinistaConfig, MinistaUserConfig, MinistaResolveConfig, 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 mergeAlias(configAlias: MinistaResolveAliasInput, viteConfigAlias: ViteAliasOptions): Promise<MinistaResolveAlias>;
5
+ export declare function mergeAlias(configAlias: MinistaResolveAliasInput, viteConfigAlias: ViteAliasOptions): Promise<AliasArray>;
6
6
  export declare function resolveConfig(config: MinistaConfig): Promise<MinistaResolveConfig>;
7
7
  export declare function getConfig(userConfig: MinistaUserConfig): Promise<MinistaResolveConfig>;
package/dist/config.js CHANGED
@@ -109,6 +109,24 @@ const defaultConfig = {
109
109
  rehypePlugins: []
110
110
  }
111
111
  },
112
+ search: {
113
+ useJson: false,
114
+ cache: false,
115
+ outDir: "assets",
116
+ outName: "search",
117
+ include: ["**/*"],
118
+ exclude: ["404"],
119
+ trimTitle: "",
120
+ targetSelector: "[data-search]",
121
+ hit: {
122
+ minLength: 3,
123
+ number: false,
124
+ english: true,
125
+ hiragana: false,
126
+ katakana: true,
127
+ kanji: true
128
+ }
129
+ },
112
130
  beautify: {
113
131
  useHtml: true,
114
132
  useAssets: false,
@@ -171,12 +189,15 @@ async function resolveConfig(config) {
171
189
  assetsOutHref: slashEnd(config.base) + noSlashEnd(config.assets.outDir),
172
190
  downloadOutDir: slashEnd(config.out) + noSlashEnd(config.assets.download.outDir),
173
191
  downloadOutHref: slashEnd(config.base) + noSlashEnd(config.assets.download.outDir),
192
+ searchJsonOutput: slashEnd(config.out) + slashEnd(config.search.outDir) + noSlashEnd(config.search.outName) + ".json",
174
193
  viteAssetsOutput: slashEnd(config.assets.outDir) + noSlashEnd(config.assets.outName) + ".[ext]",
175
194
  viteAssetsImagesOutput: slashEnd(config.assets.images.outDir) + noSlashEnd(config.assets.images.outName) + ".[ext]",
176
195
  viteAssetsFontsOutput: slashEnd(config.assets.fonts.outDir) + noSlashEnd(config.assets.fonts.outName) + ".[ext]",
177
196
  vitePluginSvgSpriteIconsSrcDir: noSlashEnd(config.assets.icons.srcDir),
178
197
  vitePluginSvgSpriteIconsOutput: slashEnd("/") + slashEnd(config.assets.icons.outDir) + noSlashEnd(config.assets.icons.outName) + ".svg",
179
- vitePluginSvgSpriteIconsTempOutput: slashEnd(systemConfig.temp.icons.outDir) + slashEnd(config.assets.icons.outDir) + noSlashEnd(config.assets.icons.outName) + ".svg"
198
+ vitePluginSvgSpriteIconsTempOutput: slashEnd(systemConfig.temp.icons.outDir) + slashEnd(config.assets.icons.outDir) + noSlashEnd(config.assets.icons.outName) + ".svg",
199
+ vitePluginSearchJsonOutput: slashEnd("/") + slashEnd(config.search.outDir) + noSlashEnd(config.search.outName) + ".json",
200
+ vitePluginSearchJsonTempOutput: slashEnd(systemConfig.temp.search.outDir) + slashEnd(config.search.outDir) + noSlashEnd(config.search.outName) + ".json"
180
201
  });
181
202
  return resolvedConfig;
182
203
  }
package/dist/css.d.ts CHANGED
@@ -1,3 +1,3 @@
1
1
  import type { Plugin } from "esbuild";
2
- import type { CssOptions } from "./types.js";
3
- export declare function CssModulePlugin(options: CssOptions): Plugin;
2
+ import type { AliasArray, CssOptions } from "./types.js";
3
+ export declare function cssModulePlugin(options: CssOptions, alias: AliasArray): Plugin;
package/dist/css.js CHANGED
@@ -19,9 +19,9 @@ var __spreadValues = (a, b) => {
19
19
  var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
20
20
  import React from "react";
21
21
  import fs from "fs-extra";
22
- import path from "path";
23
22
  import postcss from "postcss";
24
23
  import postcssModules from "postcss-modules";
24
+ import { getEsbuildResolvePath } from "./esbuild.js";
25
25
  var PreprocessLang = /* @__PURE__ */ ((PreprocessLang2) => {
26
26
  PreprocessLang2["less"] = "less";
27
27
  PreprocessLang2["sass"] = "sass";
@@ -110,7 +110,7 @@ async function buildJs(filepath, options) {
110
110
  const classNames = JSON.stringify(cssModulesJSON);
111
111
  return `export default ${classNames};`;
112
112
  }
113
- function CssModulePlugin(options) {
113
+ function cssModulePlugin(options, alias) {
114
114
  const filter = new RegExp(`\\.module${cssLangs}`);
115
115
  return {
116
116
  name: PLUGIN,
@@ -119,19 +119,19 @@ function CssModulePlugin(options) {
119
119
  build.onResolve({ filter, namespace: "file" }, async (args) => {
120
120
  if (!options.modules)
121
121
  return args;
122
- const sourceFullPath = path.resolve(args.resolveDir, args.path);
123
- if (results.has(sourceFullPath))
124
- return results.get(sourceFullPath);
125
- const content = await buildJs(sourceFullPath, options);
122
+ const resolvePath = getEsbuildResolvePath(args, alias);
123
+ if (results.has(resolvePath))
124
+ return results.get(resolvePath);
125
+ const content = await buildJs(resolvePath, options);
126
126
  const result = {
127
- path: args.path,
127
+ path: resolvePath,
128
128
  namespace: PLUGIN,
129
129
  pluginData: {
130
130
  content
131
131
  }
132
132
  };
133
133
  if (options.modules.cache)
134
- results.set(sourceFullPath, result);
134
+ results.set(resolvePath, result);
135
135
  return result;
136
136
  });
137
137
  build.onLoad({ filter, namespace: PLUGIN }, (args) => {
@@ -146,5 +146,5 @@ function CssModulePlugin(options) {
146
146
  };
147
147
  }
148
148
  export {
149
- CssModulePlugin
149
+ cssModulePlugin
150
150
  };
package/dist/esbuild.d.ts CHANGED
@@ -1,15 +1,11 @@
1
- import type { Plugin } from "esbuild";
1
+ import type { Plugin, OnResolveArgs } from "esbuild";
2
2
  import type { Config as SvgrOptions } from "@svgr/core";
3
- import type { MinistaResolveAlias } from "./types.js";
4
- export declare function getEsbuildAlias(aliasArray: MinistaResolveAlias[]): {
5
- [key: string]: string;
6
- };
3
+ import type { AliasObject, AliasArray } from "./types.js";
4
+ export declare function getEsbuildResolvePath(args: OnResolveArgs, alias: AliasArray): string;
7
5
  /*! Fork: esbuild-plugin-resolve | https://github.com/markwylde/esbuild-plugin-resolve */
8
- export declare function resolvePlugin(options: {
9
- [key: string]: string;
10
- }): Plugin;
6
+ export declare function resolvePlugin(alias: AliasObject): Plugin;
11
7
  /*! Fork: esbuild-plugin-svgr | https://github.com/kazijawad/esbuild-plugin-svgr */
12
8
  export declare function svgrPlugin(options: SvgrOptions): Plugin;
13
9
  /*! Fork: esbuild-plugin-resolve | https://github.com/hannoeru/esbuild-plugin-raw */
14
- export declare function rawPlugin(): Plugin;
15
- export declare function partialHydrationPlugin(): Plugin;
10
+ export declare function rawPlugin(alias: AliasArray): Plugin;
11
+ export declare function partialHydrationPlugin(alias: AliasArray): Plugin;