@olenbetong/appframe-vite 5.1.34 → 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 +91 -0
- package/lib/devServer.js +1 -0
- package/lib/index.js +20 -4
- package/package.json +2 -2
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/devServer.js
CHANGED
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
|
|
83
|
-
proxy.on("proxyReq", (proxyReq
|
|
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-
|
|
128
|
+
// @ts-expect-error
|
|
113
129
|
if (req.body?.error) {
|
|
114
|
-
// @ts-
|
|
130
|
+
// @ts-expect-error
|
|
115
131
|
console.log("[Client error]", req.body?.error);
|
|
116
132
|
}
|
|
117
133
|
res.statusCode = 200;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@olenbetong/appframe-vite",
|
|
3
|
-
"version": "5.1.
|
|
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",
|
|
@@ -29,7 +29,7 @@
|
|
|
29
29
|
"jsdom": "^26.1.0",
|
|
30
30
|
"rollup-plugin-visualizer": "^5.14.0",
|
|
31
31
|
"vite-plugin-externals": "^0.6.2",
|
|
32
|
-
"@olenbetong/appframe-data": "1.1.
|
|
32
|
+
"@olenbetong/appframe-data": "1.1.1"
|
|
33
33
|
},
|
|
34
34
|
"devDependencies": {
|
|
35
35
|
"@types/jsdom": "^21.1.7",
|