@bndynet/vue-site 1.4.0 → 1.5.0
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 +18 -3
- package/README.zh.md +17 -4
- package/dist/composables/useSiteConfig.d.ts +7 -0
- package/dist/index.d.ts +19 -1
- package/dist/index.es.js +724 -697
- package/dist/types.d.ts +4 -3
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -117,7 +117,7 @@ Add `"dev": "vue-site dev"` (or `vs dev`) in `package.json` scripts if you like.
|
|
|
117
117
|
| `auth` | Central authorization policy (`AuthConfig`) — see [Per-page authorization](#per-page-authorization-auth) |
|
|
118
118
|
| `router` | History mode (`RouterConfig`) — `hash` (default) or HTML5 `web`; see [Router history](#router-history-router) |
|
|
119
119
|
| `packageRepository` | Usually set by CLI from `package.json`; omit when using `createSiteApp` alone |
|
|
120
|
-
| `custom` | Public application-specific values, available from `useSiteConfig().config.custom
|
|
120
|
+
| `custom` | Public application-specific values, available from `useSiteConfig().config.custom` in components or `getSiteConfig().custom` elsewhere; see [Custom client configuration](#custom-client-configuration-custom) |
|
|
121
121
|
| `env` | Dev/build options — see below |
|
|
122
122
|
| `bootstrap` | Optional path from site root (e.g. `./bootstrap.ts`) — module loaded once before the Vue app |
|
|
123
123
|
| `configureApp` | Optional `(app) => void \| Promise<void>` after router install, before `mount` (see [Local packages in `configureApp`](#local-packages-in-configureapp)) |
|
|
@@ -125,7 +125,7 @@ Add `"dev": "vue-site dev"` (or `vs dev`) in `package.json` scripts if you like.
|
|
|
125
125
|
### Custom client configuration (`custom`)
|
|
126
126
|
|
|
127
127
|
Use `custom` for public, application-specific values that the framework should preserve without
|
|
128
|
-
interpreting
|
|
128
|
+
interpreting:
|
|
129
129
|
|
|
130
130
|
```typescript
|
|
131
131
|
// site.config.ts
|
|
@@ -144,6 +144,21 @@ const { config } = useSiteConfig()
|
|
|
144
144
|
const apiBaseUrl = config.custom?.apiBaseUrl
|
|
145
145
|
```
|
|
146
146
|
|
|
147
|
+
Ordinary modules such as `utils.ts` do not have Vue's injection context. Read the active config
|
|
148
|
+
with `getSiteConfig()` instead:
|
|
149
|
+
|
|
150
|
+
```typescript
|
|
151
|
+
// utils/api.ts
|
|
152
|
+
import { getSiteConfig } from '@bndynet/vue-site'
|
|
153
|
+
|
|
154
|
+
export function getApiBaseUrl() {
|
|
155
|
+
return getSiteConfig().custom?.apiBaseUrl
|
|
156
|
+
}
|
|
157
|
+
```
|
|
158
|
+
|
|
159
|
+
Call `getSiteConfig()` at runtime, after `createSiteApp()` has started. Do not evaluate it at the
|
|
160
|
+
top level of a module imported by `site.config.ts`; the active config has not been registered yet.
|
|
161
|
+
|
|
147
162
|
Use a different config file when the value changes between builds:
|
|
148
163
|
|
|
149
164
|
```typescript
|
|
@@ -639,7 +654,7 @@ app.mount('#app')
|
|
|
639
654
|
|
|
640
655
|
Use a top-level `await` in your entry (or an async IIFE): `createSiteApp` is async and **awaits** `configureApp` when it returns a `Promise`. If you set optional `bootstrap` in config, that module loads before the app is created; if you omit `bootstrap`, that step is skipped.
|
|
641
656
|
|
|
642
|
-
Exports: `createSiteApp`, `defineConfig`, `useTheme`, `useSiteConfig`, `useLocale`, `useLocalize`, `tk`, `resolveLocalized`, `resolveField`, `resolveMessage`, `mergeCatalog`, `flattenMessages`, `isMessageRef`, `localizedPage`, `builtinMessages`, `themeRefKey`, `localeRefKey`. Types: `SiteConfig`, `SiteEnvConfig`, `SiteViteConfig`, `SiteCustomConfig`, `SiteExternalLink`, `ShellConfig`, `ShellAction`, `ShellActionLoader`, `NavItem`, `StandalonePage`, `PageLayout`, `AuthRule`, `AuthContext`, `AuthConfig`, `RouterConfig`, `ThemeConfig`, `ThemeOption`, `ThemePaletteVars`, `ResolvedNavItem`, `I18nConfig`, `LocaleOption`, `LocaleCode`, `LocalizedString`, `IconRegistry`, `MessageRef`, `MessageTree`, `MessageCatalog`, `PageLoader`, `LocalizedPageOptions`.
|
|
657
|
+
Exports: `createSiteApp`, `defineConfig`, `useTheme`, `useSiteConfig`, `getSiteConfig`, `useLocale`, `useLocalize`, `tk`, `resolveLocalized`, `resolveField`, `resolveMessage`, `mergeCatalog`, `flattenMessages`, `isMessageRef`, `localizedPage`, `builtinMessages`, `themeRefKey`, `localeRefKey`. Types: `SiteConfig`, `SiteEnvConfig`, `SiteViteConfig`, `SiteCustomConfig`, `SiteExternalLink`, `ShellConfig`, `ShellAction`, `ShellActionLoader`, `NavItem`, `StandalonePage`, `PageLayout`, `AuthRule`, `AuthContext`, `AuthConfig`, `RouterConfig`, `ThemeConfig`, `ThemeOption`, `ThemePaletteVars`, `ResolvedNavItem`, `I18nConfig`, `LocaleOption`, `LocaleCode`, `LocalizedString`, `IconRegistry`, `MessageRef`, `MessageTree`, `MessageCatalog`, `PageLoader`, `LocalizedPageOptions`.
|
|
643
658
|
|
|
644
659
|
### Theme in Vue pages (`useTheme`)
|
|
645
660
|
|
package/README.zh.md
CHANGED
|
@@ -112,15 +112,14 @@ npx vue-site build --base /app/
|
|
|
112
112
|
| `auth` | 中心化的授权策略(`AuthConfig`)—— 参见[按页面授权](#按页面授权-auth) |
|
|
113
113
|
| `router` | 历史模式(`RouterConfig`)—— `hash`(默认)或 HTML5 `web`;参见[路由历史](#路由历史-router) |
|
|
114
114
|
| `packageRepository` | 通常由 CLI 从 `package.json` 设置;单独使用 `createSiteApp` 时可省略 |
|
|
115
|
-
| `custom` |
|
|
115
|
+
| `custom` | 公开的业务自定义配置;组件内通过 `useSiteConfig().config.custom` 读取,其他代码通过 `getSiteConfig().custom` 读取;参见[自定义客户端配置](#自定义客户端配置-custom) |
|
|
116
116
|
| `env` | 开发/构建选项 —— 见下文 |
|
|
117
117
|
| `bootstrap` | 可选的站点根目录相对路径(如 `./bootstrap.ts`)—— 在 Vue 应用之前加载一次的模块 |
|
|
118
118
|
| `configureApp` | 可选的 `(app) => void \| Promise<void>`,在路由安装之后、`mount` 之前执行(参见 [`configureApp` 中的本地包](#在-configureapp-中使用本地包)) |
|
|
119
119
|
|
|
120
120
|
### 自定义客户端配置(`custom`)
|
|
121
121
|
|
|
122
|
-
`custom`
|
|
123
|
-
`useSiteConfig()` 读取:
|
|
122
|
+
`custom` 用于存放框架无需解释、只需原样保留的公开业务配置:
|
|
124
123
|
|
|
125
124
|
```typescript
|
|
126
125
|
// site.config.ts
|
|
@@ -139,6 +138,20 @@ const { config } = useSiteConfig()
|
|
|
139
138
|
const apiBaseUrl = config.custom?.apiBaseUrl
|
|
140
139
|
```
|
|
141
140
|
|
|
141
|
+
`utils.ts` 等普通模块没有 Vue 注入上下文,应改用 `getSiteConfig()` 读取当前配置:
|
|
142
|
+
|
|
143
|
+
```typescript
|
|
144
|
+
// utils/api.ts
|
|
145
|
+
import { getSiteConfig } from '@bndynet/vue-site'
|
|
146
|
+
|
|
147
|
+
export function getApiBaseUrl() {
|
|
148
|
+
return getSiteConfig().custom?.apiBaseUrl
|
|
149
|
+
}
|
|
150
|
+
```
|
|
151
|
+
|
|
152
|
+
请在 `createSiteApp()` 已开始执行后的运行时代码中调用 `getSiteConfig()`。不要在被
|
|
153
|
+
`site.config.ts` 导入的模块顶层立即求值,因为此时当前配置尚未注册。
|
|
154
|
+
|
|
142
155
|
如果不同构建环境使用不同的值,可以选择不同的配置文件:
|
|
143
156
|
|
|
144
157
|
```typescript
|
|
@@ -577,7 +590,7 @@ app.mount('#app')
|
|
|
577
590
|
返回 `Promise` 时会 **await** 它。如果你在配置中设置了可选的 `bootstrap`,该模块会在应用创建前加载;
|
|
578
591
|
如果省略 `bootstrap`,则跳过该步骤。
|
|
579
592
|
|
|
580
|
-
导出:`createSiteApp`、`defineConfig`、`useTheme`、`useSiteConfig`、`useLocale`、`useLocalize`、`tk`、`resolveLocalized`、`resolveField`、`resolveMessage`、`mergeCatalog`、`flattenMessages`、`isMessageRef`、`localizedPage`、`builtinMessages`、`themeRefKey`、`localeRefKey`。类型:`SiteConfig`、`SiteEnvConfig`、`SiteViteConfig`、`SiteCustomConfig`、`SiteExternalLink`、`NavItem`、`StandalonePage`、`PageLayout`、`AuthRule`、`AuthContext`、`AuthConfig`、`RouterConfig`、`ThemeConfig`、`ThemeOption`、`ThemePaletteVars`、`ResolvedNavItem`、`I18nConfig`、`LocaleOption`、`LocaleCode`、`LocalizedString`、`MessageRef`、`MessageTree`、`MessageCatalog`、`PageLoader`、`LocalizedPageOptions`。
|
|
593
|
+
导出:`createSiteApp`、`defineConfig`、`useTheme`、`useSiteConfig`、`getSiteConfig`、`useLocale`、`useLocalize`、`tk`、`resolveLocalized`、`resolveField`、`resolveMessage`、`mergeCatalog`、`flattenMessages`、`isMessageRef`、`localizedPage`、`builtinMessages`、`themeRefKey`、`localeRefKey`。类型:`SiteConfig`、`SiteEnvConfig`、`SiteViteConfig`、`SiteCustomConfig`、`SiteExternalLink`、`NavItem`、`StandalonePage`、`PageLayout`、`AuthRule`、`AuthContext`、`AuthConfig`、`RouterConfig`、`ThemeConfig`、`ThemeOption`、`ThemePaletteVars`、`ResolvedNavItem`、`I18nConfig`、`LocaleOption`、`LocaleCode`、`LocalizedString`、`MessageRef`、`MessageTree`、`MessageCatalog`、`PageLoader`、`LocalizedPageOptions`。
|
|
581
594
|
|
|
582
595
|
### 在 Vue 页面中使用主题(`useTheme`)
|
|
583
596
|
|
|
@@ -10,5 +10,12 @@ export interface SiteContext {
|
|
|
10
10
|
}
|
|
11
11
|
/** Use `Symbol.for` so pages still inject context if Vite resolves the package twice. */
|
|
12
12
|
export declare const siteContextKey: InjectionKey<SiteContext>;
|
|
13
|
+
/** Register the configuration for access outside Vue's injection context. */
|
|
14
|
+
export declare function registerSiteConfig(config: SiteConfig): void;
|
|
13
15
|
export declare function provideSiteConfig(context: SiteContext): void;
|
|
16
|
+
/**
|
|
17
|
+
* Return the active site configuration outside Vue's setup / injection context.
|
|
18
|
+
* `createSiteApp()` must have started before this function is called.
|
|
19
|
+
*/
|
|
20
|
+
export declare function getSiteConfig(): SiteConfig;
|
|
14
21
|
export declare function useSiteConfig(): SiteContext;
|
package/dist/index.d.ts
CHANGED
|
@@ -6,8 +6,26 @@ export { useLocalize } from './composables/useLocalize';
|
|
|
6
6
|
export { resolveLocalized, resolveField, resolveMessage, mergeCatalog, flattenMessages, tk, isMessageRef, localizedPage } from './i18n-utils';
|
|
7
7
|
export type { LocalizedPageOptions, MessageCatalog } from './i18n-utils';
|
|
8
8
|
export { builtinMessages } from './i18n-messages';
|
|
9
|
-
export { useSiteConfig } from './composables/useSiteConfig';
|
|
9
|
+
export { getSiteConfig, useSiteConfig } from './composables/useSiteConfig';
|
|
10
10
|
export { builtinThemePalettes } from './theme/presets';
|
|
11
11
|
export { ElMessage, ElMessageBox, ElNotification, } from 'element-plus';
|
|
12
12
|
export type { SiteConfig, SiteEnvConfig, SiteViteConfig, SiteCustomConfig, SiteExternalLink, ShellConfig, ShellAction, ShellActionLoader, NavItem, StandalonePage, PageLayout, AuthRule, AuthContext, AuthConfig, RouterConfig, ThemeConfig, ThemeOption, ThemePaletteVars, ResolvedNavItem, LocaleCode, LocalizedString, IconRegistry, MessageRef, MessageTree, LocaleOption, I18nConfig, PageLoader, } from './types';
|
|
13
|
+
/**
|
|
14
|
+
* Type-safe identity for a single config object. Use the single-argument form for a standalone
|
|
15
|
+
* config file.
|
|
16
|
+
*
|
|
17
|
+
* When composing multiple config files (e.g. `site.config.prod.ts` importing a shared
|
|
18
|
+
* `site.config.common.ts`), use the two-argument form so `custom` is deep-merged: properties
|
|
19
|
+
* from the base `custom` are preserved unless explicitly overridden.
|
|
20
|
+
*
|
|
21
|
+
* @example
|
|
22
|
+
* // site.config.common.ts
|
|
23
|
+
* export default defineConfig({ custom: { apiBaseUrl: '/api', appName: 'MyApp' }, ... })
|
|
24
|
+
*
|
|
25
|
+
* // site.config.prod.ts
|
|
26
|
+
* import common from './site.config.common'
|
|
27
|
+
* export default defineConfig(common, { custom: { apiBaseUrl: 'https://prod.example.com/api' } })
|
|
28
|
+
* // Result: custom.apiBaseUrl is overridden, custom.appName is preserved.
|
|
29
|
+
*/
|
|
13
30
|
export declare function defineConfig(config: SiteConfig): SiteConfig;
|
|
31
|
+
export declare function defineConfig(base: SiteConfig, overrides: Partial<SiteConfig>): SiteConfig;
|