@realnation/content-config 0.2.0 → 0.2.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 +2 -1
- package/package.json +10 -4
- package/src/vite-plugin.mjs +10 -1
package/README.md
CHANGED
|
@@ -12,7 +12,8 @@ AI 与团队建活动 skill 的读法:先从模块目录接口 `GET /partner/p
|
|
|
12
12
|
|
|
13
13
|
## 模块里怎么接
|
|
14
14
|
|
|
15
|
-
1. 装包:`npm install -D @realnation/content-config
|
|
15
|
+
1. 装包:`npm install -D @realnation/content-config`。esbuild 与 vite 是可选的同伴依赖(0.2.1 起):模块仓装了 vite 就带着 esbuild,
|
|
16
|
+
不用另装;只用 `./validate` 的项目(如建活动 skill)两样都不用装。
|
|
16
17
|
2. `vite.config.ts` 里加插件:
|
|
17
18
|
|
|
18
19
|
```ts
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@realnation/content-config",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.1",
|
|
4
4
|
"description": "qiksense 模块内容配置的机器可读说明:构建时导出 content-config.json,并用字段说明校验默认请求体",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"exports": {
|
|
@@ -20,12 +20,18 @@
|
|
|
20
20
|
"scripts": {
|
|
21
21
|
"test": "node --test \"test/*.test.mjs\""
|
|
22
22
|
},
|
|
23
|
-
"dependencies": {
|
|
24
|
-
"esbuild": ">=0.19"
|
|
25
|
-
},
|
|
26
23
|
"peerDependencies": {
|
|
24
|
+
"esbuild": ">=0.19",
|
|
27
25
|
"vite": ">=5"
|
|
28
26
|
},
|
|
27
|
+
"peerDependenciesMeta": {
|
|
28
|
+
"esbuild": {
|
|
29
|
+
"optional": true
|
|
30
|
+
},
|
|
31
|
+
"vite": {
|
|
32
|
+
"optional": true
|
|
33
|
+
}
|
|
34
|
+
},
|
|
29
35
|
"engines": {
|
|
30
36
|
"node": ">=18"
|
|
31
37
|
},
|
package/src/vite-plugin.mjs
CHANGED
|
@@ -2,7 +2,6 @@
|
|
|
2
2
|
// 不通过就让构建失败;通过就在 remoteEntry.js 同一目录生成 content-config.json,随配置端产物发布。
|
|
3
3
|
// 模块每次构建都跑(本机 npm run build、deploy.mjs 发 UAT 与正式),所以说明永远跟着当时的代码。
|
|
4
4
|
|
|
5
|
-
import { build } from 'esbuild'
|
|
6
5
|
import { mkdirSync, rmSync, writeFileSync } from 'node:fs'
|
|
7
6
|
import { join, resolve } from 'node:path'
|
|
8
7
|
import { pathToFileURL } from 'node:url'
|
|
@@ -13,9 +12,19 @@ export { checkLabels, collectLabels } from './labels.mjs'
|
|
|
13
12
|
|
|
14
13
|
export const FORMAT = 1
|
|
15
14
|
|
|
15
|
+
// esbuild 是可选的同伴依赖(0.2.1 起):模块仓装了 vite 就有它;只用 ./validate 的场合(如建活动 skill)用不到,不必装
|
|
16
|
+
async function loadEsbuild() {
|
|
17
|
+
try {
|
|
18
|
+
return await import('esbuild')
|
|
19
|
+
} catch {
|
|
20
|
+
throw new Error('content-config:构建时要用 esbuild 加载 src/content-config.ts(vite 自带)。这个项目里找不到它,请 npm install -D esbuild')
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
|
|
16
24
|
// 用 esbuild 把 content-config.ts 连同它引用的模块代码打成一个 ESM 文件再加载:TS、相对引用与 @/ 别名都能处理;
|
|
17
25
|
// node_modules 里的包不打进去,加载时照常从模块仓解析(所以临时文件放在模块仓的 node_modules 下)
|
|
18
26
|
export async function loadSpec(root, entry) {
|
|
27
|
+
const { build } = await loadEsbuild()
|
|
19
28
|
const dir = join(root, 'node_modules', '.content-config')
|
|
20
29
|
mkdirSync(dir, { recursive: true })
|
|
21
30
|
const out = join(dir, `spec-${process.pid}-${Date.now()}.mjs`)
|