@olenbetong/appframe-vite 5.1.33 → 5.1.35

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 ADDED
@@ -0,0 +1,91 @@
1
+ # @olenbetong/appframe-vite
2
+
3
+ Tools to develop and build Vite applications that run inside Appframe articles.
4
+
5
+ - Provides a Vite plugin you add in `vite.config.*`.
6
+ - Proxies API and static routes to an Appframe server during `pnpm start`.
7
+ - Logs in automatically and refreshes the session on an interval.
8
+ - Serves real article HTML from Appframe in dev, but swaps production assets for your local entry.
9
+ - Caches i18n strings locally to speed up development loads.
10
+ - Shapes production builds to Appframe paths and filenames, with optional React externals.
11
+
12
+ ## Installation
13
+
14
+ ```sh
15
+ pnpm add -D @olenbetong/appframe-vite
16
+ ```
17
+
18
+ ## Usage (Vite)
19
+
20
+ ```ts
21
+ // vite.config.mjs or vite.config.ts
22
+ import appframe from "@olenbetong/appframe-vite";
23
+ import { defineConfig } from "vite";
24
+
25
+ export default defineConfig({
26
+ plugins: [appframe()],
27
+ });
28
+ ```
29
+
30
+ Then run your app:
31
+
32
+ ```sh
33
+ pnpm --filter <app> start
34
+ ```
35
+
36
+ Make sure your Appframe credentials are available as environment variables:
37
+
38
+ - `APPFRAME_LOGIN`: username
39
+ - `APPFRAME_PWD`: password
40
+
41
+ On first run, the plugin logs in, configures Vite’s proxy for Appframe routes, and serves the article HTML with your local entry injected.
42
+
43
+ ## Project configuration (package.json)
44
+
45
+ This package reads `package.json.appframe` to know what to proxy and how to build.
46
+
47
+ ```jsonc
48
+ {
49
+ "appframe": {
50
+ "article": {
51
+ "id": "my-article", // Required
52
+ "altNames": ["my-article-dev"] // Optional: alternate root paths
53
+ },
54
+ "deploy": { "hostname": "dev.obet.no" }, // Default server if proxy not set
55
+ "proxy": {
56
+ "hostname": "dev.obet.no", // Optional override for dev proxy
57
+ "routes": ["^/custom/.*"] // Optional: extra proxied routes
58
+ },
59
+ "build": {
60
+ "externals": true // Map React and ReactDOM to globals
61
+ }
62
+ }
63
+ }
64
+ ```
65
+
66
+ ## What it does (at a glance)
67
+
68
+ - Dev server
69
+ - Proxies Appframe routes (e.g. `/api`, `/file`, `/lib`, etc.) to the configured hostname.
70
+ - Performs an initial login and refreshes the session every 5 minutes to prevent 403 errors.
71
+ - Serves the real article HTML from Appframe, but removes production assets and injects your local entry (`/src/index.*`).
72
+ - Caches localized strings under `node_modules/.appframe/localizeCache.json` and injects them into the page to avoid many small HTTP 1.1 requests.
73
+ - Build
74
+ - Enables `manifest` and `sourcemap`.
75
+ - Writes filenames to Appframe paths, using the article ID, e.g.:
76
+ - `file/article/script/<ARTICLE_ID>/main.[hash].min.js`
77
+ - `file/article/style/<ARTICLE_ID>/style.[hash].min.css`
78
+ - Optionally treats `react` and `react-dom` as externals and maps them to `React` and `ReactDOM` globals.
79
+ - Adds a Rollup visualizer report at `dist/stats.html`.
80
+ - Resolve
81
+ - Adds the alias `~/` to `/src/` so imports like `~/components/Button` resolve to `src/components/Button`.
82
+
83
+ ## Exported helpers
84
+
85
+ Although most users only need the default plugin, the package also exports:
86
+
87
+ - `addAppframeBuildConfig(config)`: applies the Appframe build defaults (paths, externals, visualizer).
88
+ - `createDevMiddleware(server)`: serves transformed article HTML and injects cached i18n strings.
89
+
90
+ See `docs/reference/appframe-vite/` for a deeper dive into internals and configuration.
91
+
package/lib/build.js CHANGED
@@ -28,6 +28,7 @@ export async function addAppframeBuildConfig(config) {
28
28
  }
29
29
  config.build.rollupOptions = {
30
30
  input: entry,
31
+ // Cast visualizer plugin to any to avoid Rollup type version clashes
31
32
  plugins: [visualizer({ filename: "./dist/stats.html", gzipSize: true })],
32
33
  output: {
33
34
  globals: appframe.build.externals !== false
package/lib/devServer.js CHANGED
@@ -36,6 +36,7 @@ export function getProxyRoutes() {
36
36
  "^/lib/.*",
37
37
  "^/login",
38
38
  "^/logout",
39
+ "^/media/.*",
39
40
  ];
40
41
  if (appframe.proxy?.routes) {
41
42
  proxyRoutes.push(...appframe.proxy.routes);
@@ -128,7 +129,7 @@ async function getArticleHtml() {
128
129
  let { hostname, username, password } = await getLoginInfo();
129
130
  let article = appframe.article?.id;
130
131
  let client = new Client(hostname);
131
- let re = await client.login(username, password);
132
+ await client.login(username, password);
132
133
  let response = await client.fetch(`/${article}`, {
133
134
  timeout: 30_000,
134
135
  method: "GET",
@@ -3,4 +3,4 @@
3
3
  * function that reads a JSON file from disk and returns the parsed
4
4
  * content.
5
5
  */
6
- export declare function importJson(url: any, useCwd?: boolean): Promise<any>;
6
+ export declare function importJson(url: string, useCwd?: boolean): Promise<any>;
package/lib/index.js CHANGED
@@ -5,6 +5,22 @@ import { createDevMiddleware, getLoginInfo, getProxyRoutes } from "./devServer.j
5
5
  import { importJson } from "./importJson.js";
6
6
  import { localizeMiddleware } from "./localization.js";
7
7
  import { getLastSession, login } from "./proxy.js";
8
+ // type AppframeDevConfig = {
9
+ // article: {
10
+ // id: string;
11
+ // hostname: string;
12
+ // };
13
+ // deploy: {
14
+ // hostname: string;
15
+ // };
16
+ // build: {
17
+ // externals: true;
18
+ // };
19
+ // proxy?: {
20
+ // hostname?: string;
21
+ // routes?: string[];
22
+ // };
23
+ // };
8
24
  let interval;
9
25
  let server;
10
26
  let lastHostname;
@@ -79,8 +95,8 @@ export default function appframe() {
79
95
  proxy[route] = {
80
96
  target: `https://${hostname}`,
81
97
  changeOrigin: true,
82
- configure(proxy, options) {
83
- proxy.on("proxyReq", (proxyReq, req, res, options) => {
98
+ configure(proxy) {
99
+ proxy.on("proxyReq", (proxyReq) => {
84
100
  let authCookies = getLastSession(hostname)?.authCookies;
85
101
  if (authCookies) {
86
102
  let cookies = [];
@@ -109,9 +125,9 @@ export default function appframe() {
109
125
  _server.middlewares.use(`/api/user/localize/new/${appframe.article.id}`, localizeMiddleware);
110
126
  _server.middlewares.use("/data/Logger/LogError", jsonParser);
111
127
  _server.middlewares.use("/data/Logger/LogError", (req, res) => {
112
- // @ts-ignore
128
+ // @ts-expect-error
113
129
  if (req.body?.error) {
114
- // @ts-ignore
130
+ // @ts-expect-error
115
131
  console.log("[Client error]", req.body?.error);
116
132
  }
117
133
  res.statusCode = 200;
package/lib/proxy.d.ts CHANGED
@@ -3,6 +3,6 @@ type LoginCacheEntry = {
3
3
  timestamp: number;
4
4
  authCookies: CookieObject;
5
5
  };
6
- export declare function getLastSession(hostname: any): LoginCacheEntry | undefined;
6
+ export declare function getLastSession(hostname: string): LoginCacheEntry | undefined;
7
7
  export declare function login(hostname: string, username: string, password: string): Promise<CookieObject>;
8
8
  export {};
package/package.json CHANGED
@@ -1,12 +1,16 @@
1
1
  {
2
2
  "name": "@olenbetong/appframe-vite",
3
- "version": "5.1.33",
3
+ "version": "5.1.35",
4
4
  "description": "Tools to use and deploy Vite applications to Appframe",
5
5
  "main": "./lib/index.js",
6
6
  "type": "module",
7
7
  "types": "./lib/index.d.ts",
8
8
  "exports": {
9
- "default": "./lib/index.js"
9
+ "default": "./lib/index.js",
10
+ "./proxy": {
11
+ "import": "./lib/proxy.js",
12
+ "types": "./lib/proxy.d.ts"
13
+ }
10
14
  },
11
15
  "files": [
12
16
  "lib"
@@ -25,7 +29,7 @@
25
29
  "jsdom": "^26.1.0",
26
30
  "rollup-plugin-visualizer": "^5.14.0",
27
31
  "vite-plugin-externals": "^0.6.2",
28
- "@olenbetong/appframe-data": "1.0.14"
32
+ "@olenbetong/appframe-data": "1.1.1"
29
33
  },
30
34
  "devDependencies": {
31
35
  "@types/jsdom": "^21.1.7",
@@ -42,5 +46,8 @@
42
46
  "tcp-port-used": "^1.0.2"
43
47
  },
44
48
  "gitHead": "ef3839cfde6097aa12488f72913680b3ce22706e",
45
- "scripts": {}
49
+ "scripts": {
50
+ "build": "pnpm run build:tsc",
51
+ "build:tsc": "rm -rf ./lib tsconfig.build.tsbuildinfo && tsc -p tsconfig.build.json"
52
+ }
46
53
  }