vigor-moon 1.0.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 +9 -0
- package/bin/vigor.js +2 -0
- package/dist/chunk-2M2XJKGT.js +607 -0
- package/dist/chunk-3EAR5BNQ.js +610 -0
- package/dist/chunk-3ZCIQMBL.js +608 -0
- package/dist/chunk-6SPQ2G5U.js +611 -0
- package/dist/chunk-7V4TYSIZ.mjs +619 -0
- package/dist/chunk-AT54N5D7.js +611 -0
- package/dist/chunk-BBRRUMIN.js +616 -0
- package/dist/chunk-BE2AQAQS.mjs +608 -0
- package/dist/chunk-BS6X4ZCI.js +608 -0
- package/dist/chunk-CG4W75R5.mjs +622 -0
- package/dist/chunk-D2WJMNSR.js +618 -0
- package/dist/chunk-DTA4ZJEQ.mjs +606 -0
- package/dist/chunk-ECPJL6H6.js +618 -0
- package/dist/chunk-EU5K7BUZ.mjs +612 -0
- package/dist/chunk-FAELXJ3Z.mjs +605 -0
- package/dist/chunk-GBGTGHKN.js +621 -0
- package/dist/chunk-HW7CAZGA.js +611 -0
- package/dist/chunk-IDQ7PFDG.mjs +619 -0
- package/dist/chunk-IPVDS3I7.mjs +609 -0
- package/dist/chunk-JHZIOXVJ.js +605 -0
- package/dist/chunk-KRBN43PO.js +606 -0
- package/dist/chunk-KTIICQHT.mjs +622 -0
- package/dist/chunk-KZQIA6WA.js +604 -0
- package/dist/chunk-L4MZ52TR.mjs +609 -0
- package/dist/chunk-LEOZIK2T.mjs +607 -0
- package/dist/chunk-LS3TOABU.js +61 -0
- package/dist/chunk-MHZT64KI.mjs +605 -0
- package/dist/chunk-NTJI6VKJ.mjs +619 -0
- package/dist/chunk-NWZZITYZ.mjs +606 -0
- package/dist/chunk-OS3F7QDD.js +606 -0
- package/dist/chunk-PJPXX4UA.mjs +605 -0
- package/dist/chunk-PW73M55D.mjs +611 -0
- package/dist/chunk-R6L6GYA4.mjs +607 -0
- package/dist/chunk-RNUPZ4CR.mjs +612 -0
- package/dist/chunk-SEIXDGYJ.mjs +615 -0
- package/dist/chunk-SO47EKIV.mjs +69 -0
- package/dist/chunk-SYCZ35ZW.js +604 -0
- package/dist/chunk-THZGRR4I.js +611 -0
- package/dist/chunk-TJ5NMLCW.js +614 -0
- package/dist/chunk-TYBNSCBA.mjs +611 -0
- package/dist/chunk-UGBCHWPA.js +621 -0
- package/dist/chunk-VD42YO6T.mjs +622 -0
- package/dist/chunk-VMNTKZYD.js +604 -0
- package/dist/chunk-W6MHPTGR.js +605 -0
- package/dist/chunk-WBSL45KV.mjs +617 -0
- package/dist/chunk-X5IY67V6.js +621 -0
- package/dist/chunk-XFGBQ3QD.mjs +612 -0
- package/dist/chunk-ZBAZASII.js +618 -0
- package/dist/chunk-ZGLENLKC.js +610 -0
- package/dist/chunk-ZN4CSBNG.mjs +612 -0
- package/dist/cli.d.ts +2 -0
- package/dist/cli.js +296 -0
- package/dist/cli.mjs +296 -0
- package/dist/dev.d.ts +5 -0
- package/dist/dev.js +7 -0
- package/dist/dev.mjs +7 -0
- package/dist/index.d.ts +40 -0
- package/dist/index.js +6 -0
- package/dist/index.mjs +6 -0
- package/package.json +97 -0
- package/src/core/cli.ts +0 -0
- package/src/runtime/App.tsx +38 -0
- package/src/runtime/Content.tsx +27 -0
- package/src/runtime/client-entry.tsx +30 -0
- package/src/runtime/hooks.ts +8 -0
- package/src/runtime/index.ts +2 -0
- package/src/runtime/ssr-entry.tsx +24 -0
- package/src/theme-default/Layout/doc/doc.tsx +46 -0
- package/src/theme-default/Layout/doc/index.module.scss +154 -0
- package/src/theme-default/Layout/home/home.tsx +16 -0
- package/src/theme-default/Layout/index.tsx +38 -0
- package/src/theme-default/Layout/notFound/index.module.scss +7 -0
- package/src/theme-default/Layout/notFound/index.tsx +30 -0
- package/src/theme-default/component/Button/index.module.scss +36 -0
- package/src/theme-default/component/Button/index.tsx +42 -0
- package/src/theme-default/component/Link/index.module.scss +10 -0
- package/src/theme-default/component/Link/index.tsx +28 -0
- package/src/theme-default/component/feature/index.module.scss +10 -0
- package/src/theme-default/component/feature/index.tsx +28 -0
- package/src/theme-default/component/footer/index.module.scss +4 -0
- package/src/theme-default/component/footer/index.tsx +13 -0
- package/src/theme-default/component/hero/index.module.scss +5 -0
- package/src/theme-default/component/hero/index.tsx +48 -0
- package/src/theme-default/component/nav/index.module.scss +24 -0
- package/src/theme-default/component/nav/index.tsx +43 -0
- package/src/theme-default/component/nextPage/index.module.scss +43 -0
- package/src/theme-default/component/nextPage/index.tsx +64 -0
- package/src/theme-default/component/sidebar/index.module.scss +22 -0
- package/src/theme-default/component/sidebar/index.tsx +52 -0
- package/src/theme-default/component/switchTheme/index.module.scss +0 -0
- package/src/theme-default/component/switchTheme/index.tsx +9 -0
- package/src/theme-default/component/toc/activeScroll.ts +37 -0
- package/src/theme-default/component/toc/index.module.scss +7 -0
- package/src/theme-default/component/toc/index.tsx +60 -0
- package/src/theme-default/styles/base.css +92 -0
- package/src/theme-default/styles/vars.css +111 -0
- package/src/types/attributify-shims.d.ts +5 -0
- package/src/types/index.ts +129 -0
- package/src/types/types.d.ts +16 -0
package/dist/cli.js
ADDED
|
@@ -0,0 +1,296 @@
|
|
|
1
|
+
"use strict"; function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } } function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
var _chunkX5IY67V6js = require('./chunk-X5IY67V6.js');
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
var _chunkLS3TOABUjs = require('./chunk-LS3TOABU.js');
|
|
15
|
+
|
|
16
|
+
// package.json
|
|
17
|
+
var require_package = _chunkLS3TOABUjs.__commonJS.call(void 0, {
|
|
18
|
+
"package.json"(exports, module) {
|
|
19
|
+
module.exports = {
|
|
20
|
+
name: "vigor",
|
|
21
|
+
version: "1.1.0",
|
|
22
|
+
description: "SSG framework",
|
|
23
|
+
main: "dist/index.js",
|
|
24
|
+
module: "dist/index.mjs",
|
|
25
|
+
types: "dist/index.d.ts",
|
|
26
|
+
scripts: {
|
|
27
|
+
start: "tsup --watch",
|
|
28
|
+
build: "tsup",
|
|
29
|
+
"test:unit": "vitest run",
|
|
30
|
+
"test:watch": "vitest",
|
|
31
|
+
"test:e2e": "playwright test",
|
|
32
|
+
"prepare:e2e": "tsx scripts/e2e.ts",
|
|
33
|
+
release: "tsx scripts/release.ts",
|
|
34
|
+
changelog: "conventional-changelog -p angular -i CHANGELOG.md -s"
|
|
35
|
+
},
|
|
36
|
+
bin: {
|
|
37
|
+
vigor: "bin/vigor.js"
|
|
38
|
+
},
|
|
39
|
+
keywords: [
|
|
40
|
+
"SSG",
|
|
41
|
+
"docs"
|
|
42
|
+
],
|
|
43
|
+
author: "sungMoon",
|
|
44
|
+
license: "MIT",
|
|
45
|
+
files: [
|
|
46
|
+
"dist",
|
|
47
|
+
"bin",
|
|
48
|
+
"README.md",
|
|
49
|
+
"src/runtime",
|
|
50
|
+
"src/theme-default",
|
|
51
|
+
"src/types",
|
|
52
|
+
"src/core"
|
|
53
|
+
],
|
|
54
|
+
devDependencies: {
|
|
55
|
+
"@iconify-json/carbon": "^1.1.16",
|
|
56
|
+
"@playwright/test": "1.26.1",
|
|
57
|
+
"@types/compression": "^1.7.2",
|
|
58
|
+
"@types/fs-extra": "^11.0.1",
|
|
59
|
+
"@types/hast": "^2.3.4",
|
|
60
|
+
"@types/mdast": "^3.0.10",
|
|
61
|
+
"@types/node": "^18.13.0",
|
|
62
|
+
"@types/polka": "^0.5.4",
|
|
63
|
+
"@types/react-dom": "^18.0.11",
|
|
64
|
+
chalk: "^5.2.0",
|
|
65
|
+
"conventional-changelog-cli": "^2.2.2",
|
|
66
|
+
enquirer: "^2.3.6",
|
|
67
|
+
execa: "5.1.1",
|
|
68
|
+
minimist: "^1.2.8",
|
|
69
|
+
"rehype-stringify": "^9.0.3",
|
|
70
|
+
"remark-parse": "^10.0.1",
|
|
71
|
+
"remark-rehype": "^10.1.0",
|
|
72
|
+
rollup: "^3.14.0",
|
|
73
|
+
semver: "^7.5.0",
|
|
74
|
+
tsup: "^6.6.2",
|
|
75
|
+
tsx: "^3.12.3",
|
|
76
|
+
typescript: "^4.9.5",
|
|
77
|
+
unified: "^10.1.2",
|
|
78
|
+
"unist-util-visit": "^4.1.2",
|
|
79
|
+
vitest: "^0.28.4"
|
|
80
|
+
},
|
|
81
|
+
dependencies: {
|
|
82
|
+
"@loadable/component": "^5.15.3",
|
|
83
|
+
"@mdx-js/rollup": "2.1.3",
|
|
84
|
+
"@types/react": "^18.0.27",
|
|
85
|
+
"@vitejs/plugin-react": "^3.1.0",
|
|
86
|
+
acorn: "^8.8.2",
|
|
87
|
+
cac: "^6.7.14",
|
|
88
|
+
compression: "^1.7.4",
|
|
89
|
+
"fast-glob": "^3.2.12",
|
|
90
|
+
"fs-extra": "^11.1.0",
|
|
91
|
+
"github-slugger": "^2.0.0",
|
|
92
|
+
"hast-util-from-html": "^1.0.1",
|
|
93
|
+
koa: "^2.14.1",
|
|
94
|
+
"mdast-util-mdxjs-esm": "^1.3.1",
|
|
95
|
+
polka: "^0.5.2",
|
|
96
|
+
react: "^18.2.0",
|
|
97
|
+
"react-dom": "^18.2.0",
|
|
98
|
+
"react-helmet-async": "1.3.0",
|
|
99
|
+
"react-router-dom": "6.4.3",
|
|
100
|
+
"rehype-autolink-headings": "^6.1.1",
|
|
101
|
+
"rehype-slug": "^5.1.0",
|
|
102
|
+
"remark-frontmatter": "^4.0.1",
|
|
103
|
+
"remark-gfm": "^3.0.1",
|
|
104
|
+
"remark-mdx": "^2.3.0",
|
|
105
|
+
"remark-mdx-frontmatter": "^2.1.1",
|
|
106
|
+
"remark-stringify": "^10.0.2",
|
|
107
|
+
sass: "^1.60.0",
|
|
108
|
+
serve: "^14.2.0",
|
|
109
|
+
shiki: "^0.14.1",
|
|
110
|
+
sirv: "^2.0.2",
|
|
111
|
+
unocss: "^0.50.4",
|
|
112
|
+
vite: "^4.1.1"
|
|
113
|
+
}
|
|
114
|
+
};
|
|
115
|
+
}
|
|
116
|
+
});
|
|
117
|
+
|
|
118
|
+
// src/node/cli.ts
|
|
119
|
+
var _cac = require('cac');
|
|
120
|
+
|
|
121
|
+
// src/node/build.ts
|
|
122
|
+
var _vite = require('vite');
|
|
123
|
+
var _path = require('path'); var _path2 = _interopRequireDefault(_path);
|
|
124
|
+
var _fsextra = require('fs-extra'); var _fsextra2 = _interopRequireDefault(_fsextra);
|
|
125
|
+
var _pluginreact = require('@vitejs/plugin-react'); var _pluginreact2 = _interopRequireDefault(_pluginreact);
|
|
126
|
+
var _url = require('url');
|
|
127
|
+
var _vite3 = require('unocss/vite'); var _vite4 = _interopRequireDefault(_vite3);
|
|
128
|
+
var CLIENT_OUTPUT = "build";
|
|
129
|
+
async function bundle(root, config) {
|
|
130
|
+
const resolveViteConfig = async (isServer, isSSR = isServer) => ({
|
|
131
|
+
mode: "production",
|
|
132
|
+
root,
|
|
133
|
+
plugins: [
|
|
134
|
+
_vite4.default.call(void 0, _chunkX5IY67V6js.unocssOptions_default),
|
|
135
|
+
_chunkX5IY67V6js.pluginIndexHtml.call(void 0, ),
|
|
136
|
+
_pluginreact2.default.call(void 0, { jsxRuntime: "automatic", jsxImportSource: "react" }),
|
|
137
|
+
_chunkX5IY67V6js.pluginConfig.call(void 0, config),
|
|
138
|
+
// 此处的isSSR和isServer其实是一个东西,但是用的结构符,所以名称需要和之前设定的一样
|
|
139
|
+
// 所以添加了一个参数,直接让其和isServer相同
|
|
140
|
+
_chunkX5IY67V6js.pluginRoutes.call(void 0, { root: config.root, isSSR }),
|
|
141
|
+
await _chunkX5IY67V6js.pluginMdx.call(void 0, )
|
|
142
|
+
],
|
|
143
|
+
// 将react-router-dom直接打包进ssr的产物中,不用再单独引入第三方包了
|
|
144
|
+
ssr: {
|
|
145
|
+
noExternal: ["react-router-dom"]
|
|
146
|
+
},
|
|
147
|
+
build: {
|
|
148
|
+
minify: false,
|
|
149
|
+
ssr: isServer,
|
|
150
|
+
outDir: isServer ? _path2.default.join(root, ".temp") : _path2.default.join(root, CLIENT_OUTPUT),
|
|
151
|
+
rollupOptions: {
|
|
152
|
+
input: isServer ? _chunkX5IY67V6js.SERVER_ENTRY_PATH : _chunkX5IY67V6js.CLIENT_ENTRY_PATH,
|
|
153
|
+
output: {
|
|
154
|
+
format: isServer ? "cjs" : "esm"
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
});
|
|
159
|
+
try {
|
|
160
|
+
console.log("Building client and server bundles ...");
|
|
161
|
+
const [clientBundle, serverBundle] = await Promise.all([
|
|
162
|
+
// client build
|
|
163
|
+
_vite.build.call(void 0, await resolveViteConfig(false)),
|
|
164
|
+
// server build
|
|
165
|
+
_vite.build.call(void 0, await resolveViteConfig(true))
|
|
166
|
+
]);
|
|
167
|
+
const publicDir = _path.join.call(void 0, root, "public");
|
|
168
|
+
if (_fsextra2.default.pathExistsSync(publicDir)) {
|
|
169
|
+
await _fsextra2.default.copy(publicDir, _path.join.call(void 0, root, CLIENT_OUTPUT));
|
|
170
|
+
}
|
|
171
|
+
return [clientBundle, serverBundle];
|
|
172
|
+
} catch (error) {
|
|
173
|
+
console.log(error);
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
async function renderPage(render, root, clientBundle, routes) {
|
|
177
|
+
const clientChunk = clientBundle.output.find((chunk) => chunk.type === "chunk" && chunk.isEntry);
|
|
178
|
+
console.log("Rendering page in server side...");
|
|
179
|
+
const helmetContext = {
|
|
180
|
+
context: {}
|
|
181
|
+
};
|
|
182
|
+
await Promise.all(
|
|
183
|
+
[
|
|
184
|
+
...routes,
|
|
185
|
+
{
|
|
186
|
+
path: "/404"
|
|
187
|
+
}
|
|
188
|
+
].map(async (route) => {
|
|
189
|
+
const routePath = route.path;
|
|
190
|
+
const appHtml = render(routePath, helmetContext.context);
|
|
191
|
+
const styleAssets = clientBundle.output.filter(
|
|
192
|
+
(chunk) => chunk.type === "asset" && chunk.fileName.endsWith(".css")
|
|
193
|
+
);
|
|
194
|
+
const { helmet } = helmetContext.context;
|
|
195
|
+
const html = `
|
|
196
|
+
<!DOCTYPE html>
|
|
197
|
+
<html lang="en">
|
|
198
|
+
<head>
|
|
199
|
+
<meta charset="UTF-8">
|
|
200
|
+
<meta http-equiv="X-UA-Compatible" content="IE=edge">
|
|
201
|
+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
202
|
+
${_optionalChain([helmet, 'optionalAccess', _ => _.title, 'optionalAccess', _2 => _2.toString, 'call', _3 => _3()]) || ""}
|
|
203
|
+
${_optionalChain([helmet, 'optionalAccess', _4 => _4.meta, 'optionalAccess', _5 => _5.toString, 'call', _6 => _6()]) || ""}
|
|
204
|
+
${_optionalChain([helmet, 'optionalAccess', _7 => _7.link, 'optionalAccess', _8 => _8.toString, 'call', _9 => _9()]) || ""}
|
|
205
|
+
${_optionalChain([helmet, 'optionalAccess', _10 => _10.style, 'optionalAccess', _11 => _11.toString, 'call', _12 => _12()]) || ""}
|
|
206
|
+
<meta name="description" content="xxx">
|
|
207
|
+
${styleAssets.map((item) => `<link rel="stylesheet" href="/${item.fileName}">`).join("\n")}
|
|
208
|
+
</head>
|
|
209
|
+
<body>
|
|
210
|
+
<div id="root">${appHtml}</div>
|
|
211
|
+
<script src="/${_optionalChain([clientChunk, 'optionalAccess', _13 => _13.fileName])}" type="module"></script>
|
|
212
|
+
</body>
|
|
213
|
+
</html>
|
|
214
|
+
`.trim();
|
|
215
|
+
const fileName = routePath.endsWith("/") ? `${routePath}index.html` : `${routePath}.html`;
|
|
216
|
+
await _fsextra2.default.ensureDir(_path.join.call(void 0, root, "build", _path.dirname.call(void 0, fileName)));
|
|
217
|
+
await _fsextra2.default.writeFile(_path.join.call(void 0, root, "build", fileName), html);
|
|
218
|
+
})
|
|
219
|
+
);
|
|
220
|
+
}
|
|
221
|
+
async function build(root = process.cwd(), config) {
|
|
222
|
+
const [clientBundle] = await bundle(root, config);
|
|
223
|
+
const serverEntryPath = _path.join.call(void 0, root, ".temp", "ssr-entry.js");
|
|
224
|
+
const { render, routes } = await Promise.resolve().then(() => require(_url.pathToFileURL.call(void 0, serverEntryPath).toString()));
|
|
225
|
+
try {
|
|
226
|
+
await renderPage(render, root, clientBundle, routes);
|
|
227
|
+
} catch (e) {
|
|
228
|
+
console.log("Render is error\n", e);
|
|
229
|
+
}
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
// src/node/preview.ts
|
|
233
|
+
|
|
234
|
+
|
|
235
|
+
var _compression = require('compression'); var _compression2 = _interopRequireDefault(_compression);
|
|
236
|
+
var _sirv = require('sirv'); var _sirv2 = _interopRequireDefault(_sirv);
|
|
237
|
+
var _polka = require('polka'); var _polka2 = _interopRequireDefault(_polka);
|
|
238
|
+
var DEFAULT_SERVER_PORT = 9999;
|
|
239
|
+
async function preview(root, { port }) {
|
|
240
|
+
const config = await _chunkLS3TOABUjs.resolveConfig.call(void 0, root, "serve", "production");
|
|
241
|
+
const listenPort = _nullishCoalesce(port, () => ( DEFAULT_SERVER_PORT));
|
|
242
|
+
const outputDir = _path2.default.resolve(root, "build");
|
|
243
|
+
const notFoundPage = _fsextra2.default.readFileSync(_path2.default.resolve(outputDir, "404.html"), "utf8");
|
|
244
|
+
const compress = _compression2.default.call(void 0, );
|
|
245
|
+
const serve = _sirv2.default.call(void 0, outputDir, {
|
|
246
|
+
etag: true,
|
|
247
|
+
maxAge: 31536e3,
|
|
248
|
+
// 一年
|
|
249
|
+
immutable: true,
|
|
250
|
+
setHeaders(res, pathname) {
|
|
251
|
+
if (pathname.endsWith(".html")) {
|
|
252
|
+
res.setHeader("Cache-Control", "no-cache");
|
|
253
|
+
}
|
|
254
|
+
}
|
|
255
|
+
});
|
|
256
|
+
const onNoMatch = (req, res) => {
|
|
257
|
+
res.statusCode = 404;
|
|
258
|
+
res.end(notFoundPage);
|
|
259
|
+
};
|
|
260
|
+
_polka2.default.call(void 0, { onNoMatch }).use(compress, serve).listen(listenPort, (err) => {
|
|
261
|
+
if (err) {
|
|
262
|
+
throw err;
|
|
263
|
+
}
|
|
264
|
+
console.log(`Preview server is running at http://localhost:${listenPort}`);
|
|
265
|
+
});
|
|
266
|
+
}
|
|
267
|
+
|
|
268
|
+
// src/node/cli.ts
|
|
269
|
+
|
|
270
|
+
var version = require_package().version;
|
|
271
|
+
var cli = _cac.cac.call(void 0, "vigor").version(version).help();
|
|
272
|
+
cli.command("[root]", "start dev server").alias("dev").action(async (root) => {
|
|
273
|
+
root = root ? _path.resolve.call(void 0, root) : process.cwd();
|
|
274
|
+
const server = await _chunkX5IY67V6js.createDevServer.call(void 0, root);
|
|
275
|
+
await server.listen();
|
|
276
|
+
server.printUrls();
|
|
277
|
+
});
|
|
278
|
+
cli.command("build [root]", "build in production").action(async (root) => {
|
|
279
|
+
try {
|
|
280
|
+
root = _path.resolve.call(void 0, root);
|
|
281
|
+
const config = await _chunkLS3TOABUjs.resolveConfig.call(void 0, root, "build", "production");
|
|
282
|
+
await build(root, config);
|
|
283
|
+
} catch (error) {
|
|
284
|
+
console.log(error);
|
|
285
|
+
}
|
|
286
|
+
});
|
|
287
|
+
cli.command("preview [root]", "preview production build").option("--port <port>", "port to use for preview server").action(async (root, { port }) => {
|
|
288
|
+
try {
|
|
289
|
+
root = _path.resolve.call(void 0, root);
|
|
290
|
+
console.log(root);
|
|
291
|
+
await preview(root, { port });
|
|
292
|
+
} catch (e) {
|
|
293
|
+
console.log(e);
|
|
294
|
+
}
|
|
295
|
+
});
|
|
296
|
+
cli.parse();
|
package/dist/cli.mjs
ADDED
|
@@ -0,0 +1,296 @@
|
|
|
1
|
+
import {
|
|
2
|
+
CLIENT_ENTRY_PATH,
|
|
3
|
+
SERVER_ENTRY_PATH,
|
|
4
|
+
createDevServer,
|
|
5
|
+
pluginConfig,
|
|
6
|
+
pluginIndexHtml,
|
|
7
|
+
pluginMdx,
|
|
8
|
+
pluginRoutes,
|
|
9
|
+
unocssOptions_default
|
|
10
|
+
} from "./chunk-CG4W75R5.mjs";
|
|
11
|
+
import {
|
|
12
|
+
__commonJS,
|
|
13
|
+
resolveConfig
|
|
14
|
+
} from "./chunk-SO47EKIV.mjs";
|
|
15
|
+
|
|
16
|
+
// package.json
|
|
17
|
+
var require_package = __commonJS({
|
|
18
|
+
"package.json"(exports, module) {
|
|
19
|
+
module.exports = {
|
|
20
|
+
name: "vigor",
|
|
21
|
+
version: "1.1.0",
|
|
22
|
+
description: "SSG framework",
|
|
23
|
+
main: "dist/index.js",
|
|
24
|
+
module: "dist/index.mjs",
|
|
25
|
+
types: "dist/index.d.ts",
|
|
26
|
+
scripts: {
|
|
27
|
+
start: "tsup --watch",
|
|
28
|
+
build: "tsup",
|
|
29
|
+
"test:unit": "vitest run",
|
|
30
|
+
"test:watch": "vitest",
|
|
31
|
+
"test:e2e": "playwright test",
|
|
32
|
+
"prepare:e2e": "tsx scripts/e2e.ts",
|
|
33
|
+
release: "tsx scripts/release.ts",
|
|
34
|
+
changelog: "conventional-changelog -p angular -i CHANGELOG.md -s"
|
|
35
|
+
},
|
|
36
|
+
bin: {
|
|
37
|
+
vigor: "bin/vigor.js"
|
|
38
|
+
},
|
|
39
|
+
keywords: [
|
|
40
|
+
"SSG",
|
|
41
|
+
"docs"
|
|
42
|
+
],
|
|
43
|
+
author: "sungMoon",
|
|
44
|
+
license: "MIT",
|
|
45
|
+
files: [
|
|
46
|
+
"dist",
|
|
47
|
+
"bin",
|
|
48
|
+
"README.md",
|
|
49
|
+
"src/runtime",
|
|
50
|
+
"src/theme-default",
|
|
51
|
+
"src/types",
|
|
52
|
+
"src/core"
|
|
53
|
+
],
|
|
54
|
+
devDependencies: {
|
|
55
|
+
"@iconify-json/carbon": "^1.1.16",
|
|
56
|
+
"@playwright/test": "1.26.1",
|
|
57
|
+
"@types/compression": "^1.7.2",
|
|
58
|
+
"@types/fs-extra": "^11.0.1",
|
|
59
|
+
"@types/hast": "^2.3.4",
|
|
60
|
+
"@types/mdast": "^3.0.10",
|
|
61
|
+
"@types/node": "^18.13.0",
|
|
62
|
+
"@types/polka": "^0.5.4",
|
|
63
|
+
"@types/react-dom": "^18.0.11",
|
|
64
|
+
chalk: "^5.2.0",
|
|
65
|
+
"conventional-changelog-cli": "^2.2.2",
|
|
66
|
+
enquirer: "^2.3.6",
|
|
67
|
+
execa: "5.1.1",
|
|
68
|
+
minimist: "^1.2.8",
|
|
69
|
+
"rehype-stringify": "^9.0.3",
|
|
70
|
+
"remark-parse": "^10.0.1",
|
|
71
|
+
"remark-rehype": "^10.1.0",
|
|
72
|
+
rollup: "^3.14.0",
|
|
73
|
+
semver: "^7.5.0",
|
|
74
|
+
tsup: "^6.6.2",
|
|
75
|
+
tsx: "^3.12.3",
|
|
76
|
+
typescript: "^4.9.5",
|
|
77
|
+
unified: "^10.1.2",
|
|
78
|
+
"unist-util-visit": "^4.1.2",
|
|
79
|
+
vitest: "^0.28.4"
|
|
80
|
+
},
|
|
81
|
+
dependencies: {
|
|
82
|
+
"@loadable/component": "^5.15.3",
|
|
83
|
+
"@mdx-js/rollup": "2.1.3",
|
|
84
|
+
"@types/react": "^18.0.27",
|
|
85
|
+
"@vitejs/plugin-react": "^3.1.0",
|
|
86
|
+
acorn: "^8.8.2",
|
|
87
|
+
cac: "^6.7.14",
|
|
88
|
+
compression: "^1.7.4",
|
|
89
|
+
"fast-glob": "^3.2.12",
|
|
90
|
+
"fs-extra": "^11.1.0",
|
|
91
|
+
"github-slugger": "^2.0.0",
|
|
92
|
+
"hast-util-from-html": "^1.0.1",
|
|
93
|
+
koa: "^2.14.1",
|
|
94
|
+
"mdast-util-mdxjs-esm": "^1.3.1",
|
|
95
|
+
polka: "^0.5.2",
|
|
96
|
+
react: "^18.2.0",
|
|
97
|
+
"react-dom": "^18.2.0",
|
|
98
|
+
"react-helmet-async": "1.3.0",
|
|
99
|
+
"react-router-dom": "6.4.3",
|
|
100
|
+
"rehype-autolink-headings": "^6.1.1",
|
|
101
|
+
"rehype-slug": "^5.1.0",
|
|
102
|
+
"remark-frontmatter": "^4.0.1",
|
|
103
|
+
"remark-gfm": "^3.0.1",
|
|
104
|
+
"remark-mdx": "^2.3.0",
|
|
105
|
+
"remark-mdx-frontmatter": "^2.1.1",
|
|
106
|
+
"remark-stringify": "^10.0.2",
|
|
107
|
+
sass: "^1.60.0",
|
|
108
|
+
serve: "^14.2.0",
|
|
109
|
+
shiki: "^0.14.1",
|
|
110
|
+
sirv: "^2.0.2",
|
|
111
|
+
unocss: "^0.50.4",
|
|
112
|
+
vite: "^4.1.1"
|
|
113
|
+
}
|
|
114
|
+
};
|
|
115
|
+
}
|
|
116
|
+
});
|
|
117
|
+
|
|
118
|
+
// src/node/cli.ts
|
|
119
|
+
import { cac } from "cac";
|
|
120
|
+
|
|
121
|
+
// src/node/build.ts
|
|
122
|
+
import { build as viteBuild } from "vite";
|
|
123
|
+
import path, { join, dirname } from "path";
|
|
124
|
+
import fs from "fs-extra";
|
|
125
|
+
import pluginReact from "@vitejs/plugin-react";
|
|
126
|
+
import { pathToFileURL } from "url";
|
|
127
|
+
import pluginUnocss from "unocss/vite";
|
|
128
|
+
var CLIENT_OUTPUT = "build";
|
|
129
|
+
async function bundle(root, config) {
|
|
130
|
+
const resolveViteConfig = async (isServer, isSSR = isServer) => ({
|
|
131
|
+
mode: "production",
|
|
132
|
+
root,
|
|
133
|
+
plugins: [
|
|
134
|
+
pluginUnocss(unocssOptions_default),
|
|
135
|
+
pluginIndexHtml(),
|
|
136
|
+
pluginReact({ jsxRuntime: "automatic", jsxImportSource: "react" }),
|
|
137
|
+
pluginConfig(config),
|
|
138
|
+
// 此处的isSSR和isServer其实是一个东西,但是用的结构符,所以名称需要和之前设定的一样
|
|
139
|
+
// 所以添加了一个参数,直接让其和isServer相同
|
|
140
|
+
pluginRoutes({ root: config.root, isSSR }),
|
|
141
|
+
await pluginMdx()
|
|
142
|
+
],
|
|
143
|
+
// 将react-router-dom直接打包进ssr的产物中,不用再单独引入第三方包了
|
|
144
|
+
ssr: {
|
|
145
|
+
noExternal: ["react-router-dom"]
|
|
146
|
+
},
|
|
147
|
+
build: {
|
|
148
|
+
minify: false,
|
|
149
|
+
ssr: isServer,
|
|
150
|
+
outDir: isServer ? path.join(root, ".temp") : path.join(root, CLIENT_OUTPUT),
|
|
151
|
+
rollupOptions: {
|
|
152
|
+
input: isServer ? SERVER_ENTRY_PATH : CLIENT_ENTRY_PATH,
|
|
153
|
+
output: {
|
|
154
|
+
format: isServer ? "cjs" : "esm"
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
});
|
|
159
|
+
try {
|
|
160
|
+
console.log("Building client and server bundles ...");
|
|
161
|
+
const [clientBundle, serverBundle] = await Promise.all([
|
|
162
|
+
// client build
|
|
163
|
+
viteBuild(await resolveViteConfig(false)),
|
|
164
|
+
// server build
|
|
165
|
+
viteBuild(await resolveViteConfig(true))
|
|
166
|
+
]);
|
|
167
|
+
const publicDir = join(root, "public");
|
|
168
|
+
if (fs.pathExistsSync(publicDir)) {
|
|
169
|
+
await fs.copy(publicDir, join(root, CLIENT_OUTPUT));
|
|
170
|
+
}
|
|
171
|
+
return [clientBundle, serverBundle];
|
|
172
|
+
} catch (error) {
|
|
173
|
+
console.log(error);
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
async function renderPage(render, root, clientBundle, routes) {
|
|
177
|
+
const clientChunk = clientBundle.output.find((chunk) => chunk.type === "chunk" && chunk.isEntry);
|
|
178
|
+
console.log("Rendering page in server side...");
|
|
179
|
+
const helmetContext = {
|
|
180
|
+
context: {}
|
|
181
|
+
};
|
|
182
|
+
await Promise.all(
|
|
183
|
+
[
|
|
184
|
+
...routes,
|
|
185
|
+
{
|
|
186
|
+
path: "/404"
|
|
187
|
+
}
|
|
188
|
+
].map(async (route) => {
|
|
189
|
+
const routePath = route.path;
|
|
190
|
+
const appHtml = render(routePath, helmetContext.context);
|
|
191
|
+
const styleAssets = clientBundle.output.filter(
|
|
192
|
+
(chunk) => chunk.type === "asset" && chunk.fileName.endsWith(".css")
|
|
193
|
+
);
|
|
194
|
+
const { helmet } = helmetContext.context;
|
|
195
|
+
const html = `
|
|
196
|
+
<!DOCTYPE html>
|
|
197
|
+
<html lang="en">
|
|
198
|
+
<head>
|
|
199
|
+
<meta charset="UTF-8">
|
|
200
|
+
<meta http-equiv="X-UA-Compatible" content="IE=edge">
|
|
201
|
+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
202
|
+
${helmet?.title?.toString() || ""}
|
|
203
|
+
${helmet?.meta?.toString() || ""}
|
|
204
|
+
${helmet?.link?.toString() || ""}
|
|
205
|
+
${helmet?.style?.toString() || ""}
|
|
206
|
+
<meta name="description" content="xxx">
|
|
207
|
+
${styleAssets.map((item) => `<link rel="stylesheet" href="/${item.fileName}">`).join("\n")}
|
|
208
|
+
</head>
|
|
209
|
+
<body>
|
|
210
|
+
<div id="root">${appHtml}</div>
|
|
211
|
+
<script src="/${clientChunk?.fileName}" type="module"></script>
|
|
212
|
+
</body>
|
|
213
|
+
</html>
|
|
214
|
+
`.trim();
|
|
215
|
+
const fileName = routePath.endsWith("/") ? `${routePath}index.html` : `${routePath}.html`;
|
|
216
|
+
await fs.ensureDir(join(root, "build", dirname(fileName)));
|
|
217
|
+
await fs.writeFile(join(root, "build", fileName), html);
|
|
218
|
+
})
|
|
219
|
+
);
|
|
220
|
+
}
|
|
221
|
+
async function build(root = process.cwd(), config) {
|
|
222
|
+
const [clientBundle] = await bundle(root, config);
|
|
223
|
+
const serverEntryPath = join(root, ".temp", "ssr-entry.js");
|
|
224
|
+
const { render, routes } = await import(pathToFileURL(serverEntryPath).toString());
|
|
225
|
+
try {
|
|
226
|
+
await renderPage(render, root, clientBundle, routes);
|
|
227
|
+
} catch (e) {
|
|
228
|
+
console.log("Render is error\n", e);
|
|
229
|
+
}
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
// src/node/preview.ts
|
|
233
|
+
import path2 from "path";
|
|
234
|
+
import fs2 from "fs-extra";
|
|
235
|
+
import compression from "compression";
|
|
236
|
+
import sirv from "sirv";
|
|
237
|
+
import polka from "polka";
|
|
238
|
+
var DEFAULT_SERVER_PORT = 9999;
|
|
239
|
+
async function preview(root, { port }) {
|
|
240
|
+
const config = await resolveConfig(root, "serve", "production");
|
|
241
|
+
const listenPort = port ?? DEFAULT_SERVER_PORT;
|
|
242
|
+
const outputDir = path2.resolve(root, "build");
|
|
243
|
+
const notFoundPage = fs2.readFileSync(path2.resolve(outputDir, "404.html"), "utf8");
|
|
244
|
+
const compress = compression();
|
|
245
|
+
const serve = sirv(outputDir, {
|
|
246
|
+
etag: true,
|
|
247
|
+
maxAge: 31536e3,
|
|
248
|
+
// 一年
|
|
249
|
+
immutable: true,
|
|
250
|
+
setHeaders(res, pathname) {
|
|
251
|
+
if (pathname.endsWith(".html")) {
|
|
252
|
+
res.setHeader("Cache-Control", "no-cache");
|
|
253
|
+
}
|
|
254
|
+
}
|
|
255
|
+
});
|
|
256
|
+
const onNoMatch = (req, res) => {
|
|
257
|
+
res.statusCode = 404;
|
|
258
|
+
res.end(notFoundPage);
|
|
259
|
+
};
|
|
260
|
+
polka({ onNoMatch }).use(compress, serve).listen(listenPort, (err) => {
|
|
261
|
+
if (err) {
|
|
262
|
+
throw err;
|
|
263
|
+
}
|
|
264
|
+
console.log(`Preview server is running at http://localhost:${listenPort}`);
|
|
265
|
+
});
|
|
266
|
+
}
|
|
267
|
+
|
|
268
|
+
// src/node/cli.ts
|
|
269
|
+
import { resolve } from "path";
|
|
270
|
+
var version = require_package().version;
|
|
271
|
+
var cli = cac("vigor").version(version).help();
|
|
272
|
+
cli.command("[root]", "start dev server").alias("dev").action(async (root) => {
|
|
273
|
+
root = root ? resolve(root) : process.cwd();
|
|
274
|
+
const server = await createDevServer(root);
|
|
275
|
+
await server.listen();
|
|
276
|
+
server.printUrls();
|
|
277
|
+
});
|
|
278
|
+
cli.command("build [root]", "build in production").action(async (root) => {
|
|
279
|
+
try {
|
|
280
|
+
root = resolve(root);
|
|
281
|
+
const config = await resolveConfig(root, "build", "production");
|
|
282
|
+
await build(root, config);
|
|
283
|
+
} catch (error) {
|
|
284
|
+
console.log(error);
|
|
285
|
+
}
|
|
286
|
+
});
|
|
287
|
+
cli.command("preview [root]", "preview production build").option("--port <port>", "port to use for preview server").action(async (root, { port }) => {
|
|
288
|
+
try {
|
|
289
|
+
root = resolve(root);
|
|
290
|
+
console.log(root);
|
|
291
|
+
await preview(root, { port });
|
|
292
|
+
} catch (e) {
|
|
293
|
+
console.log(e);
|
|
294
|
+
}
|
|
295
|
+
});
|
|
296
|
+
cli.parse();
|
package/dist/dev.d.ts
ADDED
package/dist/dev.js
ADDED
package/dist/dev.mjs
ADDED
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { UserConfig as UserConfig$1 } from 'vitest/config';
|
|
2
|
+
|
|
3
|
+
interface NavItemsConfig {
|
|
4
|
+
text: string;
|
|
5
|
+
link: string;
|
|
6
|
+
}
|
|
7
|
+
type SidebarItem = {
|
|
8
|
+
text: string;
|
|
9
|
+
link: string;
|
|
10
|
+
} | {
|
|
11
|
+
text: string;
|
|
12
|
+
link?: string;
|
|
13
|
+
items: SidebarItem[];
|
|
14
|
+
};
|
|
15
|
+
interface SidebarGroup {
|
|
16
|
+
text?: string;
|
|
17
|
+
items: SidebarItem[];
|
|
18
|
+
}
|
|
19
|
+
interface SidebarConfig {
|
|
20
|
+
[path: string]: SidebarGroup[];
|
|
21
|
+
}
|
|
22
|
+
interface FooterConfig {
|
|
23
|
+
message?: string;
|
|
24
|
+
copyright?: string;
|
|
25
|
+
}
|
|
26
|
+
interface ThemeConfig {
|
|
27
|
+
nav?: NavItemsConfig[];
|
|
28
|
+
sidebar?: SidebarConfig;
|
|
29
|
+
footer?: FooterConfig;
|
|
30
|
+
}
|
|
31
|
+
interface UserConfig {
|
|
32
|
+
title?: string;
|
|
33
|
+
description?: string;
|
|
34
|
+
themeConfig?: ThemeConfig;
|
|
35
|
+
vite?: UserConfig$1;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
declare function defineConfig(config: UserConfig): UserConfig;
|
|
39
|
+
|
|
40
|
+
export { defineConfig };
|
package/dist/index.js
ADDED