vike-lite 1.1.4 → 1.2.1

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/LICENSE ADDED
@@ -0,0 +1,9 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2024-present node-ecosystem
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
6
+
7
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
8
+
9
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
package/README.md CHANGED
@@ -1,9 +1,10 @@
1
1
  # vike-lite
2
2
 
3
- ### ⬇️ Clone
4
- ```sh
5
- git clone https://github.com/node-ecosystem/vike-lite.git
6
- ```
3
+ Light version of [Vike](https://vike.dev)
4
+
5
+ ### Features
6
+ ❯ **Zero dependencies:**<br> _light_ with less dependencies and essential checks
7
+ ❯ **Functionalities:**<br> [See documentation](doc/FUNCTIONALITIES)
7
8
 
8
9
  ### ⚙️ Install
9
10
  | Package Manager | Command
@@ -22,7 +23,11 @@ import vikeLite from 'vike-lite/vite'
22
23
 
23
24
  export default {
24
25
  plugins: [
25
- vikeLite()
26
+ vikeLite({
27
+ pagesDir = 'pages', // default
28
+ serverEntry = 'server/index', // default
29
+ apiPrefix = '/api' // default
30
+ })
26
31
  ]
27
32
  } satisfies UserConfig
28
33
  ```
@@ -46,7 +51,7 @@ if (process.env.NODE_ENV === 'production') {
46
51
 
47
52
  app.route('/api', apiRoutes)
48
53
 
49
- // Catch-all remaining requests using custom rendering
54
+ // Catch-all remaining requests (pages) using custom rendering
50
55
  app.get('*', async (c, next) => {
51
56
  const response = await renderPage(c.req.raw)
52
57
  return response ?? next()
@@ -59,3 +64,13 @@ app.onError((error, c) => {
59
64
 
60
65
  export default app
61
66
  ```
67
+
68
+ ### 🫶 Contribution
69
+ Clone
70
+ ```sh
71
+ git clone https://github.com/node-ecosystem/vike-lite.git
72
+ ```
73
+
74
+ ---
75
+
76
+ This project is licensed under the [MIT License](LICENSE).
@@ -1,2 +1,2 @@
1
- import { t as matchRoute } from "../matchRoute-BF9hAXiF.mjs";
1
+ import { t as matchRoute } from "../matchRoute-BNUQpQu-.mjs";
2
2
  export { matchRoute };
@@ -12,7 +12,7 @@ function matchRoute(urlPathname, routes) {
12
12
  let compiled = regexCache.get(route.path);
13
13
  if (!compiled) {
14
14
  const paramNames = [];
15
- const regexPath = route.path.replace(/:([^/]+)/g, (_, name) => {
15
+ const regexPath = route.path.replaceAll(/:([^/]+)/g, (_, name) => {
16
16
  paramNames.push(name);
17
17
  return "([^/]+)";
18
18
  });
package/dist/server.mjs CHANGED
@@ -1,4 +1,4 @@
1
- import { t as matchRoute } from "./matchRoute-BF9hAXiF.mjs";
1
+ import { t as matchRoute } from "./matchRoute-BNUQpQu-.mjs";
2
2
  import { n as store } from "./store-CfUB1COP.mjs";
3
3
  //#region src/utils/serializeContext.ts
4
4
  const ESCAPE_LOOKUP = {
@@ -51,9 +51,9 @@ function getAssets(route) {
51
51
  const virtualEntryClientKey = getVirtualEntryClientKey();
52
52
  collectAssets(virtualEntryClientKey);
53
53
  const { page, layout, head } = route;
54
- collectAssets(page.replace("@/", ""));
55
- if (head) collectAssets(head.replace("@/", ""));
56
- if (layout) collectAssets(layout.replace("@/", ""));
54
+ collectAssets(page);
55
+ if (head) collectAssets(head);
56
+ if (layout) collectAssets(layout);
57
57
  return {
58
58
  cssLinks: [...cssFiles].map((href) => `<link rel="stylesheet" href="/${href}">`).join(""),
59
59
  jsPreloads: [...jsFiles].map((href) => `<link rel="modulepreload" href="/${href}">`).join(""),
package/dist/vite.mjs CHANGED
@@ -3,13 +3,14 @@ import path from "node:path";
3
3
  import { Readable } from "node:stream";
4
4
  import { pipeline } from "node:stream/promises";
5
5
  //#region src/vite-plugin.ts
6
- function generateRoutes(pagesAbsPath) {
6
+ function generateRoutes(viteRoot, pagesDir) {
7
+ const pagesAbsPath = path.resolve(viteRoot, pagesDir);
7
8
  if (!fs.existsSync(pagesAbsPath)) return { routes: [] };
8
9
  const routes = [];
9
10
  let errorRoute;
10
11
  function walk(dir, routePath, parentLayout, parentHead) {
11
12
  const files = fs.readdirSync(dir);
12
- const importPath = "@/pages" + (dir === pagesAbsPath ? "" : "/" + path.relative(pagesAbsPath, dir).replaceAll("\\", "/"));
13
+ const importPath = path.relative(viteRoot, dir).replaceAll("\\", "/");
13
14
  const currentLayout = files.includes("+Layout.tsx") ? `${importPath}/+Layout.tsx` : parentLayout;
14
15
  const currentHead = files.includes("+Head.tsx") ? `${importPath}/+Head.tsx` : parentHead;
15
16
  if (files.includes("+Page.tsx")) {
@@ -95,14 +96,16 @@ function routerPlugin({ pagesDir = "pages", serverEntry = "server/index", apiPre
95
96
  name: "vike-lite",
96
97
  config(config) {
97
98
  outDir = config.build?.outDir ?? "dist";
98
- const emptyOutDir = config.build?.emptyOutDir;
99
+ const { emptyOutDir, minify = true, cssMinify = true, sourcemap } = config.build || {};
99
100
  return {
100
101
  appType: "custom",
101
102
  environments: {
102
103
  client: { build: {
103
104
  outDir: path.join(outDir, "client"),
104
105
  emptyOutDir: emptyOutDir ?? true,
105
- cssMinify: true,
106
+ minify,
107
+ cssMinify,
108
+ sourcemap,
106
109
  manifest: true,
107
110
  rolldownOptions: {
108
111
  input: virtualEntryClientId,
@@ -121,6 +124,8 @@ function routerPlugin({ pagesDir = "pages", serverEntry = "server/index", apiPre
121
124
  target: "esnext",
122
125
  outDir: path.join(outDir, "server"),
123
126
  emptyOutDir: emptyOutDir ?? true,
127
+ minify,
128
+ sourcemap,
124
129
  rolldownOptions: {
125
130
  input: virtualEntryServerId,
126
131
  output: {
@@ -148,16 +153,16 @@ function routerPlugin({ pagesDir = "pages", serverEntry = "server/index", apiPre
148
153
  },
149
154
  async load(id, options) {
150
155
  if (id === resolvedVirtualModuleId) {
151
- const { routes, errorRoute } = generateRoutes(path.resolve(viteConfigRoot, pagesDir));
156
+ const { routes, errorRoute } = generateRoutes(viteConfigRoot, pagesDir);
152
157
  const isSSR = options.ssr;
153
158
  let code = `import { onRenderHtml } from '${virtualAdapterId}';\nexport const config = { onRenderHtml };\nexport const routes = [\n`;
154
159
  for (const r of routes) {
155
- code += `{path:'${r.path}',page:'${r.page}',Page:()=>import('${r.page}'),`;
156
- if (r.head) code += `head:'${r.head}',Head:()=>import('${r.head}'),`;
157
- if (r.layout) code += `layout:'${r.layout}',Layout:()=>import('${r.layout}'),`;
160
+ code += `{path:'${r.path}',page:'${r.page}',Page:()=>import('/${r.page}'),`;
161
+ if (r.head) code += `head:'${r.head}',Head:()=>import('/${r.head}'),`;
162
+ if (r.layout) code += `layout:'${r.layout}',Layout:()=>import('/${r.layout}'),`;
158
163
  code += `hasData:${r.hasData},hasTitle:${r.hasTitle},`;
159
164
  if (isSSR) {
160
- if (r.hasData) code += `data:()=>import('${r.page.replace("+Page.tsx", "+data.ts")}'),`;
165
+ if (r.hasData) code += `data:()=>import('/${r.page.replace("+Page.tsx", "+data.ts")}'),`;
161
166
  if (r.hasTitle) code += `title:()=>import('${r.page.replace("+Page.tsx", "+title.ts")}'),`;
162
167
  }
163
168
  code += "},";
@@ -165,9 +170,9 @@ function routerPlugin({ pagesDir = "pages", serverEntry = "server/index", apiPre
165
170
  code += "];\n";
166
171
  if (errorRoute) {
167
172
  const e = errorRoute;
168
- code += `export const errorRoute={path:'${e.path}',page:'${e.page}',Page:()=>import('${e.page}'),`;
169
- if (e.layout) code += `layout:'${e.layout}',Layout:()=>import('${e.layout}'),`;
170
- if (e.head) code += `head:'${e.head}',Head:()=>import('${e.head}'),`;
173
+ code += `export const errorRoute={path:'${e.path}',page:'${e.page}',Page:()=>import('/${e.page}'),`;
174
+ if (e.layout) code += `layout:'${e.layout}',Layout:()=>import('/${e.layout}'),`;
175
+ if (e.head) code += `head:'${e.head}',Head:()=>import('/${e.head}'),`;
171
176
  code += "};\n";
172
177
  } else code += "export const errorRoute=null;\n";
173
178
  return code;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "vike-lite",
3
- "version": "1.1.4",
3
+ "version": "1.2.1",
4
4
  "license": "MIT",
5
5
  "type": "module",
6
6
  "module": "./dist/index.mjs",