@metajoy-preview/unplugin 0.0.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/README.md ADDED
@@ -0,0 +1,128 @@
1
+ # @metajoy/unplugin
2
+
3
+ Metajoy 的跨构建工具插件集合,统一提供配 api 管理等能力。
4
+
5
+ ## 1 概览
6
+
7
+ 当前已支持:
8
+
9
+ - 多构建工具适配器:Vite、Webpack、Rollup、esbuild、Rspack、Astro、Nuxt、Farm
10
+ - 自动加载 `metajoy.config.ts`
11
+ - 自动加载 `.env` 与 `.env.{NODE_ENV}`
12
+ - 1 个插件模块:`api`(来源于 `src/plugins/api.ts`)
13
+
14
+ ## 2 安装使用
15
+
16
+ ```bash
17
+ npm install @metajoy/unplugin
18
+ # 或
19
+ pnpm add @metajoy/unplugin
20
+ ```
21
+
22
+ ### Vite
23
+
24
+ ```ts
25
+ import { defineConfig } from "vite";
26
+ import vue from "@vitejs/plugin-vue";
27
+ import metajoy from "@metajoy/unplugin/vite";
28
+
29
+ export default defineConfig({
30
+ plugins: [vue(), metajoy()],
31
+ });
32
+ ```
33
+
34
+ ### Webpack
35
+
36
+ ```js
37
+ const MetajoyPlugin = require("@metajoy/unplugin/webpack").default;
38
+
39
+ module.exports = {
40
+ plugins: [new MetajoyPlugin()],
41
+ };
42
+ ```
43
+
44
+ ### Nuxt
45
+
46
+ ```ts
47
+ export default defineNuxtConfig({
48
+ modules: ["@metajoy/unplugin/nuxt"],
49
+ });
50
+ ```
51
+
52
+ ## 3 插件配置
53
+
54
+ 所有插件均按照如下优先级加载配置:
55
+
56
+ 1. 插件参数
57
+ 2. `metajoy.config.ts`
58
+ 3. 环境变量
59
+
60
+ ## 4 适配器矩阵
61
+
62
+ | 构建工具 | 导入路径 |
63
+ | -------- | ------------------------- |
64
+ | Vite | @metajoy/unplugin/vite |
65
+ | Webpack | @metajoy/unplugin/webpack |
66
+ | Rollup | @metajoy/unplugin/rollup |
67
+ | esbuild | @metajoy/unplugin/esbuild |
68
+ | Rspack | @metajoy/unplugin/rspack |
69
+ | Astro | @metajoy/unplugin/astro |
70
+ | Nuxt | @metajoy/unplugin/nuxt |
71
+ | Farm | @metajoy/unplugin/farm |
72
+
73
+ ## 5 插件行为
74
+
75
+ - 自动加载配置(通常支持热重载)
76
+
77
+ ## 6 插件模块
78
+
79
+ ### `api`
80
+
81
+ #### 参数
82
+
83
+ - `api`:`boolean | object`
84
+ - `api.baseUrl`:默认 API 基础地址
85
+ - `api.overrides`:按 tag 覆盖目标地址
86
+ - `api.proxy`:是否启用开发代理
87
+
88
+ #### 配置
89
+
90
+ `metajoy.config.ts` 示例:
91
+
92
+ ```ts
93
+ import { defineConfig } from "@metajoy/unplugin/config";
94
+
95
+ export default defineConfig({
96
+ api: {
97
+ baseUrl: "http://localhost:8080",
98
+ docPath: "/swagger/doc.json",
99
+ overrides: {
100
+ auth: "http://192.168.0.145:8081",
101
+ test: "http://192.168.0.148:8001",
102
+ },
103
+ },
104
+ });
105
+ ```
106
+
107
+ #### 示例
108
+
109
+ 获取 baseUrl:
110
+
111
+ ```typescript
112
+ import { getBaseUrl } from "virtual:@metajoy/unplugin/api";
113
+
114
+ console.log(getBaseUrl("auth"));
115
+ console.log(getBaseUrl("test", { proxy: true }));
116
+ ```
117
+
118
+ ## 09 路线图
119
+
120
+ 暂无
121
+
122
+ ## 10 开发
123
+
124
+ ```bash
125
+ vp install
126
+ vp test
127
+ vp pack
128
+ ```
@@ -0,0 +1,6 @@
1
+ import { Options } from "./option.mjs";
2
+
3
+ //#region src/astro.d.ts
4
+ declare const _default: (options: Options) => any;
5
+ //#endregion
6
+ export { _default as default };
package/dist/astro.mjs ADDED
@@ -0,0 +1,11 @@
1
+ import { t as metajoyUnplugin } from "./src-2HigwrEC.mjs";
2
+ //#region src/astro.ts
3
+ var astro_default = (options) => ({
4
+ name: "metajoy-unplugin-astro",
5
+ hooks: { "astro:config:setup": async (astro) => {
6
+ astro.config.vite.plugins ||= [];
7
+ astro.config.vite.plugins.push(metajoyUnplugin.vite(options));
8
+ } }
9
+ });
10
+ //#endregion
11
+ export { astro_default as default };
@@ -0,0 +1,35 @@
1
+ //#region src/client.d.ts
2
+ type Primitive = null | undefined | string | number | boolean | symbol | bigint;
3
+ type LiteralUnion<LiteralType, BaseType extends Primitive> = LiteralType | (BaseType & Record<never, never>);
4
+ declare module "virtual:@metajoy/unplugin/api" {
5
+ type Tags = never;
6
+ /**
7
+ * 获取 API 基础 URL
8
+ * @param tag 目标标签
9
+ * @param options 选项
10
+ */
11
+ function getBaseUrl<T extends LiteralUnion<Tags, string>>(
12
+ /**
13
+ * 目标标签
14
+ * - 如果提供了标签,则返回对应标签的 API 基础 URL
15
+ * - 如果提供了标签但未找到对应的 API 基础 URL,则返回 "default" 标签的 API 基础 URL(如果存在)
16
+ * - 如果未提供标签但存在 "default" 标签的 API 基础 URL,则返回 "default" 标签的 API 基础 URL
17
+ * - 否则返回 undefined。
18
+ * @default "default"
19
+ */
20
+
21
+ tag?: T,
22
+ /**
23
+ * 选项
24
+ */
25
+
26
+ options?: {
27
+ /**
28
+ * 是否使用代理
29
+ * - 如果代理启用并且在开发环境中,则会返回代理 URL
30
+ * - 否则返回实际的 API 基础 URL。
31
+ * @default false
32
+ */
33
+ proxy?: boolean;
34
+ }): T extends Tags ? string : "default" extends Tags ? string : void;
35
+ }
@@ -0,0 +1 @@
1
+ export {};