minista 2.4.6 → 2.5.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,7 @@ 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
142
  markdown: {
143
143
  syntaxHighlighter: "highlight", // "highlight" | "none"
144
144
  highlightOptions: {}, // https://github.com/rehypejs/rehype-highlight#options
@@ -160,6 +160,21 @@ export default defineConfig({
160
160
  cssOptions: {}, // https://github.com/beautify-web/js-beautify#css--html
161
161
  jsOptions: {}, // https://github.com/beautify-web/js-beautify#options
162
162
  },
163
+ css: {
164
+ modules: {
165
+ generateScopedName: undefined,
166
+ globalModulePaths: [],
167
+ hashPrefix: "",
168
+ localsConvention: "camelCaseOnly",
169
+ scopeBehaviour: "local",
170
+ cache: true,
171
+ }, // https://ja.vitejs.dev/config/#css-modules
172
+ preprocessorOptions: {
173
+ scss: {},
174
+ less: {},
175
+ stylus: {},
176
+ }, // https://ja.vitejs.dev/config/#css-preprocessoroptions
177
+ },
163
178
  })
164
179
  ```
165
180
 
@@ -170,6 +185,7 @@ export default defineConfig({
170
185
 
171
186
  ## Media
172
187
 
188
+ - [SSG + Partial Hydration (部分的な React App) - minista v2.4](https://zenn.dev/qrac/articles/b9c65c1c0be901)
173
189
  - [Vite と esbuild を組み込み React 製 SSG を再構築 - minista v2](https://zenn.dev/qrac/articles/fbbbe7ccc3bdb1)
174
190
  - [React で書ける SSG 改善点と今後について - minista v1](https://zenn.dev/qrac/articles/a24de970148c7e)
175
191
  - [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,13 @@
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, 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
8
  mdxConfig: MdxOptions;
9
9
  svgrOptions: SvgrOptions;
10
+ cssOptions: CssOptions;
10
11
  }): Promise<void>;
11
12
  export declare function buildStaticPages(entryPoints: string[], tempRootFilePath: string, buildOptions: {
12
13
  outBase: string;
@@ -44,6 +45,7 @@ export declare function buildPartialStringBundle(entryPoint: string, buildOption
44
45
  outFile: string;
45
46
  mdxConfig: MdxOptions;
46
47
  svgrOptions: SvgrOptions;
48
+ cssOptions: CssOptions;
47
49
  }): Promise<void>;
48
50
  export declare function buildPartialStringInitial(entryPoint: string, partialModules: PartialModules, buildOptions: {
49
51
  outFile: string;
package/dist/build.js CHANGED
@@ -40,6 +40,7 @@ import {
40
40
  } from "./esbuild.js";
41
41
  import { renderHtml } from "./render.js";
42
42
  import { slashEnd, reactStylesToString } from "./utils.js";
43
+ import { CssModulePlugin } from "./css.js";
43
44
  const __filename = url.fileURLToPath(import.meta.url);
44
45
  const __dirname = path.dirname(__filename);
45
46
  const ministaPkgUrl = path.resolve(__dirname + "/../package.json");
@@ -90,6 +91,7 @@ async function buildTempPages(entryPoints, buildOptions) {
90
91
  external: esbuildExternals,
91
92
  loader: esbuildLoaders,
92
93
  plugins: [
94
+ CssModulePlugin(buildOptions.cssOptions),
93
95
  mdx(buildOptions.mdxConfig),
94
96
  resolvePlugin({
95
97
  "react/jsx-runtime": "react/jsx-runtime.js"
@@ -430,6 +432,7 @@ async function buildPartialStringBundle(entryPoint, buildOptions) {
430
432
  external: esbuildExternals,
431
433
  loader: esbuildLoaders,
432
434
  plugins: [
435
+ CssModulePlugin(buildOptions.cssOptions),
433
436
  mdx(buildOptions.mdxConfig),
434
437
  resolvePlugin({
435
438
  "react/jsx-runtime": "react/jsx-runtime.js"
package/dist/config.js CHANGED
@@ -103,6 +103,21 @@ const defaultConfig = {
103
103
  },
104
104
  cssOptions: {},
105
105
  jsOptions: {}
106
+ },
107
+ css: {
108
+ modules: {
109
+ generateScopedName: void 0,
110
+ globalModulePaths: [],
111
+ hashPrefix: "",
112
+ localsConvention: "camelCaseOnly",
113
+ scopeBehaviour: "local",
114
+ cache: true
115
+ },
116
+ preprocessorOptions: {
117
+ scss: {},
118
+ less: {},
119
+ stylus: {}
120
+ }
106
121
  }
107
122
  };
108
123
  async function mergeConfig(userConfig) {
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 path from "path";
22
+ import fs from "fs-extra";
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/generate.js CHANGED
@@ -47,7 +47,8 @@ async function generateTempRoot(config, mdxConfig) {
47
47
  outBase: config.rootSrcDir,
48
48
  outDir: systemConfig.temp.root.outDir,
49
49
  mdxConfig,
50
- svgrOptions: config.assets.svgr.svgrOptions
50
+ svgrOptions: config.assets.svgr.svgrOptions,
51
+ cssOptions: config.css
51
52
  });
52
53
  }
53
54
  }
@@ -57,7 +58,8 @@ async function generateTempPages(config, mdxConfig) {
57
58
  outBase: config.pagesSrcDir,
58
59
  outDir: systemConfig.temp.pages.outDir,
59
60
  mdxConfig,
60
- svgrOptions: config.assets.svgr.svgrOptions
61
+ svgrOptions: config.assets.svgr.svgrOptions,
62
+ cssOptions: config.css
61
63
  });
62
64
  }
63
65
  async function generateTempAssets(config, viteConfig) {
@@ -90,7 +92,8 @@ async function generatePartialHydration(config, mdxConfig, viteConfig) {
90
92
  await buildPartialStringBundle(stringIndex, {
91
93
  outFile: stringBundle,
92
94
  mdxConfig,
93
- svgrOptions: config.assets.svgr.svgrOptions
95
+ svgrOptions: config.assets.svgr.svgrOptions,
96
+ cssOptions: config.css
94
97
  });
95
98
  await optimizeCommentOutStyleImport([stringBundle]);
96
99
  await buildPartialStringInitial(stringBundle, partialModules, {
package/dist/types.d.ts CHANGED
@@ -4,6 +4,8 @@ import type { Config as SvgrOptions } from "@svgr/core";
4
4
  import type { Options as HighlightOptions } from "rehype-highlight";
5
5
  import type { Options as MdxOptions } from "@mdx-js/esbuild";
6
6
  import type { HTMLBeautifyOptions, CSSBeautifyOptions, JSBeautifyOptions } from "js-beautify";
7
+ import type Sass from "sass";
8
+ import type Stylus from "stylus";
7
9
  export declare type MinistaConfig = {
8
10
  base: string;
9
11
  public: string;
@@ -78,6 +80,7 @@ export declare type MinistaConfig = {
78
80
  cssOptions: CSSBeautifyOptions;
79
81
  jsOptions: JSBeautifyOptions;
80
82
  };
83
+ css: CssOptions;
81
84
  };
82
85
  export declare type MinistaUserConfig = {
83
86
  base?: string;
@@ -153,6 +156,7 @@ export declare type MinistaUserConfig = {
153
156
  cssOptions?: CSSBeautifyOptions;
154
157
  jsOptions?: JSBeautifyOptions;
155
158
  };
159
+ css?: CssUserOptions;
156
160
  };
157
161
  export declare type MinistaSvgstoreOptions = {
158
162
  cleanDefs?: Boolean | string[];
@@ -271,3 +275,27 @@ export declare type PartialModules = {
271
275
  export declare type PartialString = {
272
276
  [key: string]: string;
273
277
  };
278
+ export declare type CSSModulesOptions = {
279
+ cache: boolean;
280
+ scopeBehaviour: "global" | "local";
281
+ globalModulePaths: RegExp[];
282
+ generateScopedName: undefined | string | ((name: string, filename: string, css: string) => string);
283
+ hashPrefix: string;
284
+ localsConvention: "camelCase" | "camelCaseOnly" | "dashes" | "dashesOnly";
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
+ };
package/dist/vite.js CHANGED
@@ -88,7 +88,8 @@ 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);
94
95
  const svgrPlugin = vitePluginMinistaSvgr(config.assets.svgr.svgrOptions);
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.6",
4
+ "version": "2.5.0",
5
5
  "bin": {
6
6
  "minista": "./bin/minista.js"
7
7
  },
@@ -67,8 +67,22 @@
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",
@@ -77,13 +91,15 @@
77
91
  "@vitejs/plugin-react": "^1.3.2",
78
92
  "cac": "^6.7.12",
79
93
  "deepmerge-ts": "^4.0.3",
80
- "esbuild": "^0.14.38",
94
+ "esbuild": "^0.14.39",
81
95
  "fs-extra": "^10.1.0",
82
96
  "js-beautify": "^1.14.3",
83
97
  "mime-types": "^2.1.35",
84
98
  "node-fetch": "^3.2.4",
85
99
  "node-html-parser": "^5.3.3",
86
100
  "picocolors": "^1.0.0",
101
+ "postcss": "^8.4.13",
102
+ "postcss-modules": "^4.3.1",
87
103
  "react-helmet": "^6.1.0",
88
104
  "react-router-dom": "^6.3.0",
89
105
  "rehype-highlight": "^5.0.2",
@@ -94,21 +110,26 @@
94
110
  "svgstore": "^3.0.1",
95
111
  "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.34",
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",
129
+ "sass": "^1.51.0",
130
+ "stylus": "^0.57.0",
131
+ "tsup": "^5.12.8",
111
132
  "typescript": "^4.6.4",
112
- "vitest": "^0.12.0"
133
+ "vitest": "^0.12.6"
113
134
  }
114
135
  }