minista 2.4.5 → 2.6.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
@@ -138,7 +138,25 @@ export default defineConfig({
138
138
  outDir: "assets/images", // string
139
139
  },
140
140
  },
141
- vite: {}, // https://vitejs.dev/config/
141
+ vite: {}, // https://ja.vitejs.dev/config/
142
+ resolve: {
143
+ alias: [], // { [key: string]: string } | { find: string, replacement: string }[]
144
+ },
145
+ css: {
146
+ modules: {
147
+ cache: true,
148
+ scopeBehaviour: "local",
149
+ globalModulePaths: [],
150
+ generateScopedName: undefined,
151
+ hashPrefix: "",
152
+ localsConvention: "camelCaseOnly",
153
+ }, // https://ja.vitejs.dev/config/#css-modules
154
+ preprocessorOptions: {
155
+ scss: {},
156
+ less: {},
157
+ stylus: {},
158
+ }, // https://ja.vitejs.dev/config/#css-preprocessoroptions
159
+ },
142
160
  markdown: {
143
161
  syntaxHighlighter: "highlight", // "highlight" | "none"
144
162
  highlightOptions: {}, // https://github.com/rehypejs/rehype-highlight#options
@@ -155,7 +173,7 @@ export default defineConfig({
155
173
  max_preserve_newlines: 0,
156
174
  indent_inner_html: true,
157
175
  extra_liners: [],
158
- inline: ["span", "b", "br", "code", "del", "s", "small", "strong", "wbr"],
176
+ inline: ["span", "strong", "b", "small", "del", "s", "code", "br", "wbr"],
159
177
  }, // https://github.com/beautify-web/js-beautify#css--html
160
178
  cssOptions: {}, // https://github.com/beautify-web/js-beautify#css--html
161
179
  jsOptions: {}, // https://github.com/beautify-web/js-beautify#options
@@ -170,6 +188,7 @@ export default defineConfig({
170
188
 
171
189
  ## Media
172
190
 
191
+ - [SSG + Partial Hydration (部分的な React App) - minista v2.4](https://zenn.dev/qrac/articles/b9c65c1c0be901)
173
192
  - [Vite と esbuild を組み込み React 製 SSG を再構築 - minista v2](https://zenn.dev/qrac/articles/fbbbe7ccc3bdb1)
174
193
  - [React で書ける SSG 改善点と今後について - minista v1](https://zenn.dev/qrac/articles/a24de970148c7e)
175
194
  - [React(JSX)で書けるコーディング用 SSG - minista v0](https://zenn.dev/qrac/articles/7537521afcd1bf)
package/client.d.ts CHANGED
@@ -1,3 +1,65 @@
1
+ // CSS modules
2
+ type CSSModuleClasses = { readonly [key: string]: string }
3
+
4
+ declare module "*.module.css" {
5
+ const classes: CSSModuleClasses
6
+ export default classes
7
+ }
8
+ declare module "*.module.scss" {
9
+ const classes: CSSModuleClasses
10
+ export default classes
11
+ }
12
+ declare module "*.module.sass" {
13
+ const classes: CSSModuleClasses
14
+ export default classes
15
+ }
16
+ declare module "*.module.less" {
17
+ const classes: CSSModuleClasses
18
+ export default classes
19
+ }
20
+ declare module "*.module.styl" {
21
+ const classes: CSSModuleClasses
22
+ export default classes
23
+ }
24
+ declare module "*.module.stylus" {
25
+ const classes: CSSModuleClasses
26
+ export default classes
27
+ }
28
+ declare module "*.module.pcss" {
29
+ const classes: CSSModuleClasses
30
+ export default classes
31
+ }
32
+
33
+ // CSS
34
+ declare module "*.css" {
35
+ const css: string
36
+ export default css
37
+ }
38
+ declare module "*.scss" {
39
+ const css: string
40
+ export default css
41
+ }
42
+ declare module "*.sass" {
43
+ const css: string
44
+ export default css
45
+ }
46
+ declare module "*.less" {
47
+ const css: string
48
+ export default css
49
+ }
50
+ declare module "*.styl" {
51
+ const css: string
52
+ export default css
53
+ }
54
+ declare module "*.stylus" {
55
+ const css: string
56
+ export default css
57
+ }
58
+ declare module "*.pcss" {
59
+ const css: string
60
+ export default css
61
+ }
62
+
1
63
  declare module "*.mdx" {
2
64
  import { MDXProps } from "mdx/types"
3
65
  export default function MDXContent(props: MDXProps): JSX.Element
package/dist/build.d.ts CHANGED
@@ -1,12 +1,14 @@
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, PartialModules } from "./types.js";
4
+ import type { MinistaResolveConfig, MinistaResolveAlias, RootStaticContent, RootJsxContent, GlobalStaticData, GetGlobalStaticData, PageJsxContent, StaticData, StaticDataItem, GetStaticData, 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
9
  mdxConfig: MdxOptions;
9
10
  svgrOptions: SvgrOptions;
11
+ cssOptions: CssOptions;
10
12
  }): Promise<void>;
11
13
  export declare function buildStaticPages(entryPoints: string[], tempRootFilePath: string, buildOptions: {
12
14
  outBase: string;
@@ -42,8 +44,10 @@ export declare function buildPartialStringIndex(partialModules: PartialModules,
42
44
  }): Promise<void>;
43
45
  export declare function buildPartialStringBundle(entryPoint: string, buildOptions: {
44
46
  outFile: string;
47
+ alias: MinistaResolveAlias;
45
48
  mdxConfig: MdxOptions;
46
49
  svgrOptions: SvgrOptions;
50
+ cssOptions: CssOptions;
47
51
  }): Promise<void>;
48
52
  export declare function buildPartialStringInitial(entryPoint: string, partialModules: PartialModules, buildOptions: {
49
53
  outFile: string;
package/dist/build.js CHANGED
@@ -33,6 +33,7 @@ import {
33
33
  import { systemConfig } from "./system.js";
34
34
  import { getFilePath } from "./path.js";
35
35
  import {
36
+ getEsbuildAlias,
36
37
  resolvePlugin,
37
38
  svgrPlugin,
38
39
  rawPlugin,
@@ -40,6 +41,7 @@ import {
40
41
  } from "./esbuild.js";
41
42
  import { renderHtml } from "./render.js";
42
43
  import { slashEnd, reactStylesToString } from "./utils.js";
44
+ import { CssModulePlugin } from "./css.js";
43
45
  const __filename = url.fileURLToPath(import.meta.url);
44
46
  const __dirname = path.dirname(__filename);
45
47
  const ministaPkgUrl = path.resolve(__dirname + "/../package.json");
@@ -70,11 +72,18 @@ const esbuildLoaders = {
70
72
  ".woff": "file",
71
73
  ".woff2": "file"
72
74
  };
75
+ const esbuildAlias = [
76
+ {
77
+ find: "react/jsx-runtime",
78
+ replacement: "react/jsx-runtime.js"
79
+ }
80
+ ];
73
81
  const userPkgHasPreact = [
74
82
  ...Object.keys(userPkg.dependencies || {}),
75
83
  ...Object.keys(userPkg.devDependencies || {})
76
84
  ].includes("preact");
77
85
  async function buildTempPages(entryPoints, buildOptions) {
86
+ const alias = getEsbuildAlias([esbuildAlias, buildOptions.alias]);
78
87
  await esBuild({
79
88
  entryPoints,
80
89
  outbase: buildOptions.outBase,
@@ -90,10 +99,9 @@ async function buildTempPages(entryPoints, buildOptions) {
90
99
  external: esbuildExternals,
91
100
  loader: esbuildLoaders,
92
101
  plugins: [
102
+ resolvePlugin(alias),
103
+ CssModulePlugin(buildOptions.cssOptions),
93
104
  mdx(buildOptions.mdxConfig),
94
- resolvePlugin({
95
- "react/jsx-runtime": "react/jsx-runtime.js"
96
- }),
97
105
  svgrPlugin(buildOptions.svgrOptions),
98
106
  rawPlugin(),
99
107
  partialHydrationPlugin()
@@ -181,7 +189,7 @@ async function buildHtmlPage(pageJsxContent, staticDataItem, routePath, rootStat
181
189
  const staticProps = staticDataItem.props;
182
190
  const reg1 = new RegExp(`^${outDir}|index.html`, "g");
183
191
  const reg2 = new RegExp(`.html`, "g");
184
- const pathname = routePath.replace(reg1, "").replace(reg2, "");
192
+ const pathname = routePath.replace(reg1, "").replace(reg2, "").replaceAll("\\", "/");
185
193
  const location = { pathname };
186
194
  const RenderComponent = () => {
187
195
  if (RootComponent === Fragment) {
@@ -418,6 +426,7 @@ export { ${tmpExportsStr} }`;
418
426
  });
419
427
  }
420
428
  async function buildPartialStringBundle(entryPoint, buildOptions) {
429
+ const alias = getEsbuildAlias([esbuildAlias, buildOptions.alias]);
421
430
  await esBuild({
422
431
  entryPoints: [entryPoint],
423
432
  outfile: buildOptions.outFile,
@@ -430,10 +439,9 @@ async function buildPartialStringBundle(entryPoint, buildOptions) {
430
439
  external: esbuildExternals,
431
440
  loader: esbuildLoaders,
432
441
  plugins: [
442
+ resolvePlugin(alias),
443
+ CssModulePlugin(buildOptions.cssOptions),
433
444
  mdx(buildOptions.mdxConfig),
434
- resolvePlugin({
435
- "react/jsx-runtime": "react/jsx-runtime.js"
436
- }),
437
445
  svgrPlugin(buildOptions.svgrOptions),
438
446
  rawPlugin()
439
447
  ]
package/dist/config.d.ts CHANGED
@@ -1,5 +1,7 @@
1
- import type { MinistaConfig, MinistaUserConfig, MinistaResolveConfig } from "./types.js";
1
+ import type { AliasOptions as ViteAliasOptions } from "vite";
2
+ import type { MinistaConfig, MinistaUserConfig, MinistaResolveConfig, MinistaResolveAliasInput, MinistaResolveAlias } from "./types.js";
2
3
  export declare const defaultConfig: MinistaConfig;
3
4
  export declare function mergeConfig(userConfig: MinistaUserConfig): Promise<MinistaConfig>;
5
+ export declare function mergeAlias(configAlias: MinistaResolveAliasInput, viteConfigAlias: ViteAliasOptions): Promise<MinistaResolveAlias>;
4
6
  export declare function resolveConfig(config: MinistaConfig): Promise<MinistaResolveConfig>;
5
7
  export declare function getConfig(userConfig: MinistaUserConfig): Promise<MinistaResolveConfig>;
package/dist/config.js CHANGED
@@ -83,6 +83,24 @@ const defaultConfig = {
83
83
  }
84
84
  },
85
85
  vite: {},
86
+ resolve: {
87
+ alias: []
88
+ },
89
+ css: {
90
+ modules: {
91
+ cache: true,
92
+ scopeBehaviour: "local",
93
+ globalModulePaths: [],
94
+ generateScopedName: void 0,
95
+ hashPrefix: "",
96
+ localsConvention: "camelCaseOnly"
97
+ },
98
+ preprocessorOptions: {
99
+ scss: {},
100
+ less: {},
101
+ stylus: {}
102
+ }
103
+ },
86
104
  markdown: {
87
105
  syntaxHighlighter: "highlight",
88
106
  highlightOptions: {},
@@ -99,7 +117,7 @@ const defaultConfig = {
99
117
  max_preserve_newlines: 0,
100
118
  indent_inner_html: true,
101
119
  extra_liners: [],
102
- inline: ["span", "b", "br", "code", "del", "s", "small", "strong", "wbr"]
120
+ inline: ["span", "strong", "b", "small", "del", "s", "code", "br", "wbr"]
103
121
  },
104
122
  cssOptions: {},
105
123
  jsOptions: {}
@@ -112,8 +130,40 @@ async function mergeConfig(userConfig) {
112
130
  const mergedConfig = customDeepmerge(defaultConfig, userConfig);
113
131
  return mergedConfig;
114
132
  }
133
+ async function mergeAlias(configAlias, viteConfigAlias) {
134
+ const alias = [];
135
+ async function getAlias(input) {
136
+ if (!input) {
137
+ return;
138
+ } else if (Array.isArray(input) && input.length > 0) {
139
+ await Promise.all(input.map(async (item) => {
140
+ const pattern = {
141
+ find: item.find,
142
+ replacement: item.replacement
143
+ };
144
+ return alias.push(pattern);
145
+ }));
146
+ } else if (typeof input === "object") {
147
+ await Promise.all(Object.entries(input).map((item) => {
148
+ const pattern = {
149
+ find: item[0],
150
+ replacement: item[1]
151
+ };
152
+ return alias.push(pattern);
153
+ }));
154
+ }
155
+ }
156
+ await getAlias(configAlias);
157
+ await getAlias(viteConfigAlias);
158
+ return alias;
159
+ }
115
160
  async function resolveConfig(config) {
161
+ var _a;
162
+ const configAlias = config.resolve.alias;
163
+ const viteConfigAlias = ((_a = config.vite.resolve) == null ? void 0 : _a.alias) || {};
164
+ const alias = await mergeAlias(configAlias, viteConfigAlias);
116
165
  const resolvedConfig = __spreadProps(__spreadValues({}, config), {
166
+ alias,
117
167
  rootSrcDir: noSlashEnd(config.root.srcDir),
118
168
  pagesSrcDir: noSlashEnd(config.pages.srcDir),
119
169
  publicOutDir: noSlashEnd(config.out),
@@ -138,6 +188,7 @@ async function getConfig(userConfig) {
138
188
  export {
139
189
  defaultConfig,
140
190
  getConfig,
191
+ mergeAlias,
141
192
  mergeConfig,
142
193
  resolveConfig
143
194
  };
package/dist/css.d.ts ADDED
@@ -0,0 +1,3 @@
1
+ import type { Plugin } from "esbuild";
2
+ import type { CssOptions } from "./types.js";
3
+ export declare function CssModulePlugin(options: CssOptions): Plugin;
package/dist/css.js ADDED
@@ -0,0 +1,150 @@
1
+ var __defProp = Object.defineProperty;
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));
20
+ import React from "react";
21
+ import fs from "fs-extra";
22
+ import path from "path";
23
+ import postcss from "postcss";
24
+ import postcssModules from "postcss-modules";
25
+ var PreprocessLang = /* @__PURE__ */ ((PreprocessLang2) => {
26
+ PreprocessLang2["less"] = "less";
27
+ PreprocessLang2["sass"] = "sass";
28
+ PreprocessLang2["scss"] = "scss";
29
+ PreprocessLang2["styl"] = "styl";
30
+ PreprocessLang2["stylus"] = "stylus";
31
+ return PreprocessLang2;
32
+ })(PreprocessLang || {});
33
+ const PLUGIN = "esbuild-cssmodule-plugin";
34
+ const cssLangs = `\\.(css|less|sass|scss|styl|stylus)($|\\?)`;
35
+ const cssLangRE = new RegExp(cssLangs);
36
+ async function loadPreprocessor(lang) {
37
+ try {
38
+ const preprocessor = await import(lang);
39
+ return preprocessor.default;
40
+ } catch (e) {
41
+ if (e.code === "ERR_MODULE_NOT_FOUND") {
42
+ throw new Error(`Preprocessor dependency "${lang}" not found. Did you install it?`);
43
+ } else {
44
+ const error = new Error(`Preprocessor dependency "${lang}" failed to load:
45
+ ${e.message}`);
46
+ error.stack = `${e.stack}
47
+ ${error.stack}`;
48
+ throw error;
49
+ }
50
+ }
51
+ }
52
+ const less = async (filepath, options) => {
53
+ const less2 = await loadPreprocessor("less" /* less */);
54
+ const content = await fs.readFile(filepath, "utf8");
55
+ less2.render("", {});
56
+ const result = await less2.render(content, __spreadValues({}, options.preprocessorOptions.less));
57
+ return result.css;
58
+ };
59
+ const scss = async (scssFullPath, options) => {
60
+ const sass = await loadPreprocessor("sass" /* sass */);
61
+ const result = await sass.compileAsync(scssFullPath, __spreadValues({}, options.preprocessorOptions.scss));
62
+ return result.css;
63
+ };
64
+ const stylus = async (filepath, options) => {
65
+ const stylus2 = await loadPreprocessor("stylus" /* stylus */);
66
+ const content = await fs.readFile(filepath, "utf8");
67
+ const result = stylus2(content, __spreadValues({}, options.preprocessorOptions.stylus)).set("filename", filepath).render();
68
+ return result;
69
+ };
70
+ const preProcessors = {
71
+ ["less" /* less */]: less,
72
+ ["sass" /* sass */]: scss,
73
+ ["scss" /* scss */]: scss,
74
+ ["styl" /* styl */]: stylus,
75
+ ["stylus" /* stylus */]: stylus
76
+ };
77
+ async function buildCss(filepath, options) {
78
+ var _a;
79
+ const lang = (_a = filepath.match(cssLangRE)) == null ? void 0 : _a[1];
80
+ let css = void 0;
81
+ if (lang !== "css") {
82
+ const preProcessor = preProcessors[lang];
83
+ if (preProcessor) {
84
+ css = await preProcessor(filepath, options);
85
+ } else {
86
+ console.warn(`${PLUGIN}: Unsupported CSS language: ${lang}`);
87
+ return;
88
+ }
89
+ } else {
90
+ css = await fs.readFile(filepath, "utf8");
91
+ }
92
+ return css;
93
+ }
94
+ async function buildJs(filepath, options) {
95
+ const css = await buildCss(filepath, options);
96
+ if (!css)
97
+ return;
98
+ let cssModulesJSON = {};
99
+ await postcss([
100
+ postcssModules(__spreadProps(__spreadValues({}, options.modules), {
101
+ getJSON(_, json) {
102
+ cssModulesJSON = json;
103
+ return cssModulesJSON;
104
+ }
105
+ }))
106
+ ]).process(css, {
107
+ from: filepath,
108
+ map: false
109
+ });
110
+ const classNames = JSON.stringify(cssModulesJSON);
111
+ return `export default ${classNames};`;
112
+ }
113
+ function CssModulePlugin(options) {
114
+ const filter = new RegExp(`\\.module${cssLangs}`);
115
+ return {
116
+ name: PLUGIN,
117
+ setup(build) {
118
+ const results = /* @__PURE__ */ new Map();
119
+ build.onResolve({ filter, namespace: "file" }, async (args) => {
120
+ if (!options.modules)
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);
126
+ const result = {
127
+ path: args.path,
128
+ namespace: PLUGIN,
129
+ pluginData: {
130
+ content
131
+ }
132
+ };
133
+ if (options.modules.cache)
134
+ results.set(sourceFullPath, result);
135
+ return result;
136
+ });
137
+ build.onLoad({ filter, namespace: PLUGIN }, (args) => {
138
+ if (!args.pluginData.content)
139
+ return args;
140
+ return {
141
+ contents: args.pluginData.content,
142
+ loader: "js"
143
+ };
144
+ });
145
+ }
146
+ };
147
+ }
148
+ export {
149
+ CssModulePlugin
150
+ };
package/dist/esbuild.d.ts CHANGED
@@ -1,5 +1,9 @@
1
1
  import type { Plugin } 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
7
  /*! Fork: esbuild-plugin-resolve | https://github.com/markwylde/esbuild-plugin-resolve */
4
8
  export declare function resolvePlugin(options: {
5
9
  [key: string]: string;
package/dist/esbuild.js CHANGED
@@ -19,6 +19,13 @@ import fs from "fs-extra";
19
19
  import path from "path";
20
20
  import { v4 as uuidv4 } from "uuid";
21
21
  import { systemConfig } from "./system.js";
22
+ function getEsbuildAlias(aliasArray) {
23
+ const alias = [...aliasArray].flat();
24
+ const result = Object.assign({}, ...alias.map((item) => ({
25
+ [item.find]: item.replacement
26
+ })));
27
+ return result;
28
+ }
22
29
  /*! Fork: esbuild-plugin-resolve | https://github.com/markwylde/esbuild-plugin-resolve */
23
30
  function resolvePlugin(options) {
24
31
  function resolvePluginIntercept(build, moduleName, moduleTarget) {
@@ -120,6 +127,7 @@ function partialHydrationPlugin() {
120
127
  };
121
128
  }
122
129
  export {
130
+ getEsbuildAlias,
123
131
  partialHydrationPlugin,
124
132
  rawPlugin,
125
133
  resolvePlugin,
package/dist/generate.js CHANGED
@@ -46,8 +46,10 @@ async function generateTempRoot(config, mdxConfig) {
46
46
  await buildTempPages([srcRootFilePaths[0]], {
47
47
  outBase: config.rootSrcDir,
48
48
  outDir: systemConfig.temp.root.outDir,
49
+ alias: config.alias,
49
50
  mdxConfig,
50
- svgrOptions: config.assets.svgr.svgrOptions
51
+ svgrOptions: config.assets.svgr.svgrOptions,
52
+ cssOptions: config.css
51
53
  });
52
54
  }
53
55
  }
@@ -56,8 +58,10 @@ async function generateTempPages(config, mdxConfig) {
56
58
  await buildTempPages(srcPageFilePaths, {
57
59
  outBase: config.pagesSrcDir,
58
60
  outDir: systemConfig.temp.pages.outDir,
61
+ alias: config.alias,
59
62
  mdxConfig,
60
- svgrOptions: config.assets.svgr.svgrOptions
63
+ svgrOptions: config.assets.svgr.svgrOptions,
64
+ cssOptions: config.css
61
65
  });
62
66
  }
63
67
  async function generateTempAssets(config, viteConfig) {
@@ -90,7 +94,9 @@ async function generatePartialHydration(config, mdxConfig, viteConfig) {
90
94
  await buildPartialStringBundle(stringIndex, {
91
95
  outFile: stringBundle,
92
96
  mdxConfig,
93
- svgrOptions: config.assets.svgr.svgrOptions
97
+ alias: config.alias,
98
+ svgrOptions: config.assets.svgr.svgrOptions,
99
+ cssOptions: config.css
94
100
  });
95
101
  await optimizeCommentOutStyleImport([stringBundle]);
96
102
  await buildPartialStringInitial(stringBundle, partialModules, {
package/dist/path.js CHANGED
@@ -1,22 +1,22 @@
1
1
  import React from "react";
2
2
  import fs from "fs-extra";
3
+ import fg from "fast-glob";
3
4
  import path from "path";
4
- import glob from "tiny-glob";
5
5
  function getFilePath(targetDir, fileName, extension) {
6
6
  const filePath = `${targetDir}/${fileName}.${extension}`;
7
7
  const file = fs.existsSync(path.resolve(filePath)) ? path.resolve(filePath) : "";
8
8
  return file;
9
9
  }
10
10
  async function getFilePaths(targetDir, extensions) {
11
- const strExtension = typeof extensions === "string" ? extensions : extensions.join();
12
- const globPattern = `${targetDir}/**/*.{${strExtension}}`;
13
- const files = await glob(globPattern);
11
+ const strExtension = typeof extensions === "string" ? extensions : extensions.join("|");
12
+ const globPattern = `${targetDir}/**/*.+(${strExtension})`;
13
+ const files = await fg(globPattern, { extglob: true });
14
14
  return files;
15
15
  }
16
16
  async function getSameFilePaths(targetDir, fileName, extensions) {
17
- const strExtension = typeof extensions === "string" ? extensions : extensions.join();
18
- const globPattern = `${targetDir}/${fileName}.{${strExtension}}`;
19
- const files = await glob(globPattern);
17
+ const strExtension = typeof extensions === "string" ? extensions : extensions.join("|");
18
+ const globPattern = `${targetDir}/${fileName}.+(${strExtension})`;
19
+ const files = await fg(globPattern, { extglob: true });
20
20
  return files;
21
21
  }
22
22
  export {
package/dist/types.d.ts CHANGED
@@ -1,9 +1,12 @@
1
1
  import type { ExoticComponent } from "react";
2
2
  import type { UserConfig as ViteUserConfig, CorsOptions as ViteCorsOptions } from "vite";
3
3
  import type { Config as SvgrOptions } from "@svgr/core";
4
+ import type { SvgstoreAddOptions } from "@qrac/svgstore";
4
5
  import type { Options as HighlightOptions } from "rehype-highlight";
5
6
  import type { Options as MdxOptions } from "@mdx-js/esbuild";
6
7
  import type { HTMLBeautifyOptions, CSSBeautifyOptions, JSBeautifyOptions } from "js-beautify";
8
+ import type Sass from "sass";
9
+ import type Stylus from "stylus";
7
10
  export declare type MinistaConfig = {
8
11
  base: string;
9
12
  public: string;
@@ -56,7 +59,7 @@ export declare type MinistaConfig = {
56
59
  srcDir: string;
57
60
  outDir: string;
58
61
  outName: string;
59
- svgstoreOptions: MinistaSvgstoreOptions;
62
+ svgstoreOptions: SvgstoreAddOptions;
60
63
  };
61
64
  download: {
62
65
  useRemote: boolean;
@@ -66,6 +69,10 @@ export declare type MinistaConfig = {
66
69
  };
67
70
  };
68
71
  vite: ViteUserConfig;
72
+ resolve: {
73
+ alias: MinistaResolveAliasInput;
74
+ };
75
+ css: CssOptions;
69
76
  markdown: {
70
77
  syntaxHighlighter: "highlight" | "none";
71
78
  highlightOptions: HighlightOptions;
@@ -131,7 +138,7 @@ export declare type MinistaUserConfig = {
131
138
  srcDir?: string;
132
139
  outDir?: string;
133
140
  outName?: string;
134
- svgstoreOptions?: MinistaSvgstoreOptions;
141
+ svgstoreOptions?: SvgstoreAddOptions;
135
142
  };
136
143
  download?: {
137
144
  useRemote?: boolean;
@@ -141,6 +148,10 @@ export declare type MinistaUserConfig = {
141
148
  };
142
149
  };
143
150
  vite?: ViteUserConfig;
151
+ resolve?: {
152
+ alias?: MinistaResolveAliasInput;
153
+ };
154
+ css?: CssUserOptions;
144
155
  markdown?: {
145
156
  syntaxHighlighter?: "highlight" | "none";
146
157
  highlightOptions?: HighlightOptions;
@@ -154,19 +165,20 @@ export declare type MinistaUserConfig = {
154
165
  jsOptions?: JSBeautifyOptions;
155
166
  };
156
167
  };
157
- export declare type MinistaSvgstoreOptions = {
158
- cleanDefs?: Boolean | string[];
159
- cleanSymbols?: Boolean | string[];
160
- svgAttrs?: Boolean | {
161
- [key: string]: string;
162
- };
163
- symbolAttrs?: Boolean | {
164
- [key: string]: string;
165
- };
166
- copyAttrs?: Boolean | string[];
167
- renameDefs?: Boolean;
168
+ export declare type MinistaResolveConfig = MinistaConfig & MinistaResolveAliasConfig & MinistaResolvePathConfig;
169
+ export declare type MinistaResolveAliasInput = {
170
+ [key: string]: string;
171
+ } | {
172
+ find: string;
173
+ replacement: string;
174
+ }[];
175
+ export declare type MinistaResolveAlias = {
176
+ find: string;
177
+ replacement: string;
178
+ }[];
179
+ export declare type MinistaResolveAliasConfig = {
180
+ alias: MinistaResolveAlias;
168
181
  };
169
- export declare type MinistaResolveConfig = MinistaConfig & MinistaResolvePathConfig;
170
182
  export declare type MinistaResolvePathConfig = {
171
183
  rootSrcDir: string;
172
184
  pagesSrcDir: string;
@@ -271,3 +283,27 @@ export declare type PartialModules = {
271
283
  export declare type PartialString = {
272
284
  [key: string]: string;
273
285
  };
286
+ export declare type CssOptions = {
287
+ modules: CSSModulesOptions | false;
288
+ preprocessorOptions: {
289
+ scss: Sass.Options<"async">;
290
+ less: Less.Options;
291
+ stylus: Stylus.RenderOptions;
292
+ };
293
+ };
294
+ export declare type CssUserOptions = {
295
+ modules?: Partial<CSSModulesOptions> | false;
296
+ preprocessorOptions?: {
297
+ scss?: Sass.Options<"async">;
298
+ less?: Less.Options;
299
+ stylus?: Stylus.RenderOptions;
300
+ };
301
+ };
302
+ export declare type CSSModulesOptions = {
303
+ cache: boolean;
304
+ scopeBehaviour: "global" | "local";
305
+ globalModulePaths: RegExp[];
306
+ generateScopedName: undefined | string | ((name: string, filename: string, css: string) => string);
307
+ hashPrefix: string;
308
+ localsConvention: "camelCase" | "camelCaseOnly" | "dashes" | "dashesOnly";
309
+ };
package/dist/vite.d.ts CHANGED
@@ -1,10 +1,11 @@
1
1
  import type { UserConfig as ViteConfig, Plugin } from "vite";
2
2
  import type { Config as SvgrOptions } from "@svgr/core";
3
3
  import type { Options as MdxOptions } from "@mdx-js/esbuild";
4
- import type { MinistaResolveConfig, MinistaSvgstoreOptions, MinistaCliDevOptions, MinistaCliPreviewOptions } from "./types.js";
4
+ import type { SvgstoreAddOptions } from "@qrac/svgstore";
5
+ import type { MinistaResolveConfig, MinistaCliDevOptions, MinistaCliPreviewOptions } from "./types.js";
5
6
  export declare function getViteConfig(config: MinistaResolveConfig, mdxConfig: MdxOptions, cliOptions?: MinistaCliDevOptions | MinistaCliPreviewOptions): Promise<ViteConfig>;
6
7
  export declare function resolveEntry(entry: string | string[] | {}): {};
7
8
  export declare function vitePluginMinistaVirtualHtml(): Plugin;
8
9
  /*! Fork: vite-plugin-svgr | https://github.com/pd4d10/vite-plugin-svgr */
9
10
  export declare function vitePluginMinistaSvgr(svgrOptions: SvgrOptions): Plugin;
10
- export declare function vitePluginMinistaSvgSpriteIcons(srcDir: string, options: MinistaSvgstoreOptions | undefined, output: string, tempOutput: string): Plugin;
11
+ export declare function vitePluginMinistaSvgSpriteIcons(srcDir: string, options: SvgstoreAddOptions | undefined, output: string, tempOutput: string): Plugin;
package/dist/vite.js CHANGED
@@ -12,7 +12,7 @@ import {
12
12
  } from "vite";
13
13
  import react from "@vitejs/plugin-react";
14
14
  import mdx from "@mdx-js/rollup";
15
- import svgstore from "svgstore";
15
+ import svgstore from "@qrac/svgstore";
16
16
  import { systemConfig } from "./system.js";
17
17
  import { getFilePaths } from "./path.js";
18
18
  import { getFilename, getFilenameObject } from "./utils.js";
@@ -88,9 +88,15 @@ async function getViteConfig(config, mdxConfig, cliOptions) {
88
88
  "react-helmet"
89
89
  ]
90
90
  },
91
- customLogger: createLogger("info", { prefix: "[minista]" })
91
+ customLogger: createLogger("info", { prefix: "[minista]" }),
92
+ css: config.css
92
93
  });
93
94
  const mergedViteConfig = mergeViteConfig(defaultViteConfig, config.vite);
95
+ if (config.alias.length > 0) {
96
+ await Promise.all(config.alias.map(async (item) => {
97
+ return mergedViteConfig.resolve.alias.push(item);
98
+ }));
99
+ }
94
100
  const svgrPlugin = vitePluginMinistaSvgr(config.assets.svgr.svgrOptions);
95
101
  mergedViteConfig.plugins.push(svgrPlugin);
96
102
  if (config.assets.icons.useSprite) {
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.5",
4
+ "version": "2.6.0",
5
5
  "bin": {
6
6
  "minista": "./bin/minista.js"
7
7
  },
@@ -67,23 +67,41 @@
67
67
  "semi": false
68
68
  },
69
69
  "peerDependencies": {
70
+ "less": "*",
70
71
  "react": "^17.0.2",
71
- "react-dom": "^17.0.2"
72
+ "react-dom": "^17.0.2",
73
+ "sass": "*",
74
+ "stylus": "*"
75
+ },
76
+ "peerDependenciesMeta": {
77
+ "less": {
78
+ "optional": true
79
+ },
80
+ "sass": {
81
+ "optional": true
82
+ },
83
+ "stylus": {
84
+ "optional": true
85
+ }
72
86
  },
73
87
  "dependencies": {
74
88
  "@mdx-js/esbuild": "^2.1.1",
75
89
  "@mdx-js/rollup": "^2.1.1",
90
+ "@qrac/svgstore": "^3.0.3",
76
91
  "@svgr/core": "^6.2.1",
77
92
  "@vitejs/plugin-react": "^1.3.2",
78
93
  "cac": "^6.7.12",
79
94
  "deepmerge-ts": "^4.0.3",
80
- "esbuild": "^0.14.38",
95
+ "esbuild": "^0.14.42",
96
+ "fast-glob": "^3.2.11",
81
97
  "fs-extra": "^10.1.0",
82
98
  "js-beautify": "^1.14.3",
83
99
  "mime-types": "^2.1.35",
84
- "node-fetch": "^3.2.4",
100
+ "node-fetch": "^3.2.5",
85
101
  "node-html-parser": "^5.3.3",
86
102
  "picocolors": "^1.0.0",
103
+ "postcss": "^8.4.14",
104
+ "postcss-modules": "^4.3.1",
87
105
  "react-helmet": "^6.1.0",
88
106
  "react-router-dom": "^6.3.0",
89
107
  "rehype-highlight": "^5.0.2",
@@ -91,24 +109,27 @@
91
109
  "remark-gfm": "^3.0.1",
92
110
  "remark-mdx-frontmatter": "^1.1.1",
93
111
  "srcset": "^5.0.0",
94
- "svgstore": "^3.0.1",
95
- "tiny-glob": "^0.2.9",
96
112
  "uuid": "^8.3.2",
97
- "vite": "^2.9.8"
113
+ "vite": "^2.9.9"
98
114
  },
99
115
  "devDependencies": {
100
116
  "@types/fs-extra": "^9.0.13",
101
117
  "@types/js-beautify": "^1.13.3",
118
+ "@types/less": "^3.0.3",
102
119
  "@types/mime-types": "^2.1.1",
103
- "@types/node": "^17.0.31",
120
+ "@types/node": "^17.0.39",
104
121
  "@types/react": "^17.0.45",
105
122
  "@types/react-dom": "^17.0.16",
106
123
  "@types/react-helmet": "^6.1.5",
124
+ "@types/stylus": "^0.48.38",
107
125
  "@types/uuid": "^8.3.4",
126
+ "less": "^4.1.2",
108
127
  "react": "^17.0.2",
109
128
  "react-dom": "^17.0.2",
110
- "tsup": "^5.12.7",
111
- "typescript": "^4.6.4",
112
- "vitest": "^0.12.0"
129
+ "sass": "^1.52.2",
130
+ "stylus": "^0.58.1",
131
+ "tsup": "^6.0.1",
132
+ "typescript": "^4.7.3",
133
+ "vitest": "^0.13.1"
113
134
  }
114
135
  }