@revojs/client 0.1.58
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/dist/module/index.d.ts +15 -0
- package/dist/module/index.js +109 -0
- package/dist/package.js +45 -0
- package/dist/types/index.d.ts +5 -0
- package/package.json +36 -0
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { type HtmlTagDescriptor } from "vite";
|
|
2
|
+
export type HtmlTags = "head" | "body";
|
|
3
|
+
export interface HtmlTag {
|
|
4
|
+
tagName: string;
|
|
5
|
+
attributes: Record<string, string>;
|
|
6
|
+
children: Array<string | HtmlTag>;
|
|
7
|
+
}
|
|
8
|
+
export interface ClientConfig {
|
|
9
|
+
html: Record<HtmlTags, HtmlTag>;
|
|
10
|
+
}
|
|
11
|
+
export declare function toHtmlTagDescriptor(htmlTag: HtmlTag, injectTo: HtmlTagDescriptor["injectTo"]): HtmlTagDescriptor;
|
|
12
|
+
declare const _default: import("revojs/module").Module<"client", ClientConfig, []>;
|
|
13
|
+
export default _default;
|
|
14
|
+
export declare const CLIENT = "client";
|
|
15
|
+
export declare const CLIENT_SUFFIX = "?client";
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
import package_default from "../package.js";
|
|
2
|
+
import { readFileSync } from "fs";
|
|
3
|
+
import { basename } from "path";
|
|
4
|
+
import { cwd } from "process";
|
|
5
|
+
import { addTypes, addVirtual, defineModule, useModule } from "revojs/module";
|
|
6
|
+
import "vite";
|
|
7
|
+
//#region src/module/index.ts
|
|
8
|
+
function toHtmlTagDescriptor(htmlTag, injectTo) {
|
|
9
|
+
let children;
|
|
10
|
+
for (const entry of htmlTag.children) if (entry instanceof Object) {
|
|
11
|
+
children ??= [];
|
|
12
|
+
if (Array.isArray(children)) children.push(toHtmlTagDescriptor(entry, injectTo));
|
|
13
|
+
} else {
|
|
14
|
+
children ??= "";
|
|
15
|
+
if (!Array.isArray(children)) children += entry;
|
|
16
|
+
}
|
|
17
|
+
return {
|
|
18
|
+
tag: htmlTag.tagName,
|
|
19
|
+
attrs: htmlTag.attributes,
|
|
20
|
+
children,
|
|
21
|
+
injectTo
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
var module_default = defineModule({
|
|
25
|
+
name: "client",
|
|
26
|
+
config: () => ({ html: {
|
|
27
|
+
head: {
|
|
28
|
+
tagName: "head",
|
|
29
|
+
attributes: {},
|
|
30
|
+
children: []
|
|
31
|
+
},
|
|
32
|
+
body: {
|
|
33
|
+
tagName: "body",
|
|
34
|
+
attributes: {},
|
|
35
|
+
children: []
|
|
36
|
+
}
|
|
37
|
+
} }),
|
|
38
|
+
setup(config) {
|
|
39
|
+
const { fromModule } = useModule(import.meta.url);
|
|
40
|
+
let viteDevServer;
|
|
41
|
+
let clientOutput;
|
|
42
|
+
addTypes(config, "client", () => `import '${fromModule("../types/index.d.ts")}'`);
|
|
43
|
+
return { vite: {
|
|
44
|
+
environments: { [CLIENT]: {
|
|
45
|
+
consumer: "client",
|
|
46
|
+
build: {
|
|
47
|
+
rolldownOptions: {
|
|
48
|
+
input: "./index.html",
|
|
49
|
+
output: {
|
|
50
|
+
entryFileNames: "assets/[hash].js",
|
|
51
|
+
chunkFileNames: "assets/[hash].js",
|
|
52
|
+
assetFileNames: "assets/[hash][extname]"
|
|
53
|
+
}
|
|
54
|
+
},
|
|
55
|
+
outDir: "./dist/client"
|
|
56
|
+
}
|
|
57
|
+
} },
|
|
58
|
+
plugins: [{
|
|
59
|
+
name: package_default.name,
|
|
60
|
+
configResolved(viteConfig) {
|
|
61
|
+
const { fromModule } = useModule(cwd());
|
|
62
|
+
addVirtual(config, "client", () => {
|
|
63
|
+
const input = viteConfig.environments[CLIENT]?.build?.rolldownOptions?.input;
|
|
64
|
+
if (typeof input === "string") return `import client from "${fromModule(input)}?client"; export default client`;
|
|
65
|
+
});
|
|
66
|
+
},
|
|
67
|
+
configureServer(devServer) {
|
|
68
|
+
viteDevServer = devServer;
|
|
69
|
+
},
|
|
70
|
+
transformIndexHtml: {
|
|
71
|
+
order: "pre",
|
|
72
|
+
handler() {
|
|
73
|
+
const entries = new Array();
|
|
74
|
+
const head = toHtmlTagDescriptor(config.client.html.head, "head");
|
|
75
|
+
if (Array.isArray(head.children)) entries.push(...head.children);
|
|
76
|
+
const body = toHtmlTagDescriptor(config.client.html.body, "body");
|
|
77
|
+
if (Array.isArray(body.children)) entries.push(...body.children);
|
|
78
|
+
return entries;
|
|
79
|
+
}
|
|
80
|
+
},
|
|
81
|
+
writeBundle(_, bundle) {
|
|
82
|
+
if (this.environment.name === "client") clientOutput = bundle;
|
|
83
|
+
},
|
|
84
|
+
load(key) {
|
|
85
|
+
if (key.endsWith("?client")) {
|
|
86
|
+
const path = key.substring(0, key.length - CLIENT_SUFFIX.length);
|
|
87
|
+
if (clientOutput) for (const name in clientOutput) {
|
|
88
|
+
const file = clientOutput[name];
|
|
89
|
+
if (file.type === "asset" && file.fileName === basename(path)) return file.source.toString();
|
|
90
|
+
}
|
|
91
|
+
return readFileSync(path, "utf8");
|
|
92
|
+
}
|
|
93
|
+
return null;
|
|
94
|
+
},
|
|
95
|
+
async transform(code, key) {
|
|
96
|
+
if (key.endsWith("?client")) {
|
|
97
|
+
code = viteDevServer ? await viteDevServer.transformIndexHtml(key, code) : code;
|
|
98
|
+
return { code: `export default \`${code}\`` };
|
|
99
|
+
}
|
|
100
|
+
return null;
|
|
101
|
+
}
|
|
102
|
+
}]
|
|
103
|
+
} };
|
|
104
|
+
}
|
|
105
|
+
});
|
|
106
|
+
var CLIENT = "client";
|
|
107
|
+
var CLIENT_SUFFIX = "?client";
|
|
108
|
+
//#endregion
|
|
109
|
+
export { CLIENT, CLIENT_SUFFIX, module_default as default, toHtmlTagDescriptor };
|
package/dist/package.js
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
//#region package.json
|
|
2
|
+
var name = "@revojs/client";
|
|
3
|
+
var version = "0.1.58";
|
|
4
|
+
var repository = {
|
|
5
|
+
"type": "git",
|
|
6
|
+
"url": "git+https://github.com/tellua/revojs.git"
|
|
7
|
+
};
|
|
8
|
+
var files = ["dist"];
|
|
9
|
+
var type = "module";
|
|
10
|
+
var main = "./dist/index.js";
|
|
11
|
+
var module = "./dist/index.js";
|
|
12
|
+
var types = "./dist/index.d.ts";
|
|
13
|
+
var exports = {
|
|
14
|
+
".": {
|
|
15
|
+
"types": "./dist/index.d.ts",
|
|
16
|
+
"import": "./dist/index.js"
|
|
17
|
+
},
|
|
18
|
+
"./module": {
|
|
19
|
+
"types": "./dist/module/index.d.ts",
|
|
20
|
+
"import": "./dist/module/index.js"
|
|
21
|
+
}
|
|
22
|
+
};
|
|
23
|
+
var scripts = {
|
|
24
|
+
"build": "vite build",
|
|
25
|
+
"watch": "vite build --watch"
|
|
26
|
+
};
|
|
27
|
+
var dependencies = { "revojs": "*" };
|
|
28
|
+
var devDependencies = { "@revojs/tsconfig": "*" };
|
|
29
|
+
var package_default = {
|
|
30
|
+
name,
|
|
31
|
+
version,
|
|
32
|
+
license: "MIT",
|
|
33
|
+
repository,
|
|
34
|
+
files,
|
|
35
|
+
type,
|
|
36
|
+
main,
|
|
37
|
+
module,
|
|
38
|
+
types,
|
|
39
|
+
exports,
|
|
40
|
+
scripts,
|
|
41
|
+
dependencies,
|
|
42
|
+
devDependencies
|
|
43
|
+
};
|
|
44
|
+
//#endregion
|
|
45
|
+
export { package_default as default, dependencies, devDependencies, exports, files, main, module, name, repository, scripts, type, types, version };
|
package/package.json
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@revojs/client",
|
|
3
|
+
"version": "0.1.58",
|
|
4
|
+
"license": "MIT",
|
|
5
|
+
"repository": {
|
|
6
|
+
"type": "git",
|
|
7
|
+
"url": "git+https://github.com/tellua/revojs.git"
|
|
8
|
+
},
|
|
9
|
+
"files": [
|
|
10
|
+
"dist"
|
|
11
|
+
],
|
|
12
|
+
"type": "module",
|
|
13
|
+
"main": "./dist/index.js",
|
|
14
|
+
"module": "./dist/index.js",
|
|
15
|
+
"types": "./dist/index.d.ts",
|
|
16
|
+
"exports": {
|
|
17
|
+
".": {
|
|
18
|
+
"types": "./dist/index.d.ts",
|
|
19
|
+
"import": "./dist/index.js"
|
|
20
|
+
},
|
|
21
|
+
"./module": {
|
|
22
|
+
"types": "./dist/module/index.d.ts",
|
|
23
|
+
"import": "./dist/module/index.js"
|
|
24
|
+
}
|
|
25
|
+
},
|
|
26
|
+
"scripts": {
|
|
27
|
+
"build": "vite build",
|
|
28
|
+
"watch": "vite build --watch"
|
|
29
|
+
},
|
|
30
|
+
"dependencies": {
|
|
31
|
+
"revojs": "*"
|
|
32
|
+
},
|
|
33
|
+
"devDependencies": {
|
|
34
|
+
"@revojs/tsconfig": "*"
|
|
35
|
+
}
|
|
36
|
+
}
|