@jctrans-materials/nuxt 1.0.2 → 1.0.4

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/package.json CHANGED
@@ -1,21 +1,22 @@
1
1
  {
2
2
  "name": "@jctrans-materials/nuxt",
3
3
  "type": "module",
4
- "version": "1.0.2",
4
+ "version": "1.0.4",
5
5
  "description": "Nuxt module for JCtrans UI components",
6
6
  "exports": {
7
7
  ".": "./src/module.ts"
8
8
  },
9
9
  "dependencies": {
10
- "nuxt": "^3.0.0",
11
10
  "@nuxt/kit": "^3.0.0",
11
+ "defu": "6.1.2",
12
+ "nuxt": "^3.0.0",
12
13
  "vue": "^3.5.26",
13
14
  "vue-router": "^4.6.4",
14
- "@jctrans-materials/comps-vue3": "1.0.2"
15
+ "@jctrans-materials/comps-vue3": "1.0.4"
15
16
  },
16
17
  "peerDependencies": {
17
18
  "nuxt": "^3.0.0",
18
- "@jctrans-materials/comps-vue3": "1.0.2"
19
+ "@jctrans-materials/comps-vue3": "1.0.4"
19
20
  },
20
21
  "devDependencies": {
21
22
  "@nuxt/module-builder": "latest"
package/src/module.ts CHANGED
@@ -4,54 +4,69 @@ import {
4
4
  addPlugin,
5
5
  createResolver,
6
6
  } from "nuxt/kit";
7
+ import { defu } from "defu";
8
+ import type { SharedConfig } from "@jctrans-materials/comps-vue3";
7
9
 
8
- // 定义模块配置项(如果以后需要传参,比如 jctrans: { prefix: 'JC' })
9
10
  export interface ModuleOptions {
10
- /**
11
- * 是否自动引入样式
12
- * @default true
13
- */
14
11
  addStyle?: boolean;
12
+ sharedConfig?: Partial<SharedConfig>;
15
13
  }
16
14
 
17
15
  export default defineNuxtModule<ModuleOptions>({
18
16
  meta: {
19
17
  name: "@jctrans-materials/nuxt",
20
- configKey: "jctrans", // 在 nuxt.config.ts 中使用的键名
18
+ configKey: "jctrans",
21
19
  compatibility: {
22
20
  nuxt: "^3.0.0",
23
21
  },
24
22
  },
23
+
25
24
  defaults: {
26
25
  addStyle: true,
26
+ sharedConfig: {},
27
27
  },
28
+
28
29
  setup(options, nuxt) {
29
30
  const { resolve } = createResolver(import.meta.url);
30
31
 
31
- // 1. 自动注入样式文件
32
- // 用户不再需要手动 import '@jctrans-materials/comps/style.css'
32
+ nuxt.options.runtimeConfig.public ||= {};
33
+ nuxt.options.runtimeConfig.public.jctrans = defu(
34
+ nuxt.options.runtimeConfig.public.jctrans,
35
+ {
36
+ sharedConfig: options.sharedConfig,
37
+ },
38
+ );
39
+
33
40
  if (options.addStyle) {
34
41
  nuxt.options.css.push("@jctrans-materials/comps-vue3/index.css");
35
42
  }
36
43
 
37
- // 2. 自动注册组件 (Auto-import)
38
- // 这样用户在页面里直接写 <Search /> 即可,无需 import
39
- const components = ["JcSearch", "ApplyDataDialog"];
40
-
41
- components.forEach((name) => {
42
- addComponent({
43
- name: name, // 组件在模板中的标签名
44
- export: name, // 从基础库中导出的具名对象名
45
- filePath: "@jctrans-materials/comps-vue3", // 来源库
46
- });
47
- });
44
+ ["JcSearch", "ApplyDataDialog", "MSearch", "GlobalModal"].forEach(
45
+ (name) => {
46
+ addComponent({
47
+ name,
48
+ export: name,
49
+ filePath: "@jctrans-materials/comps-vue3",
50
+ });
51
+ },
52
+ );
48
53
 
49
- // 3. 处理 SSR 转译
50
- // 确保 Nuxt 能够正确处理组件库里的 ESM 代码
51
- nuxt.options.build.transpile.push("@jctrans-materials/comps-vue3", "element-plus");
54
+ nuxt.options.build.transpile.push(
55
+ "@jctrans-materials/comps-vue3",
56
+ "element-plus",
57
+ );
52
58
 
53
- // 4. 注册运行时插件 (用于指令等)
54
- // 如果你的组件库在 install 里注册了全局指令,需要在这里指向一个插件文件
55
- addPlugin(resolve("./runtime/plugin"));
59
+ addPlugin({
60
+ src: resolve("./runtime/plugin"),
61
+ mode: "all",
62
+ });
56
63
  },
57
64
  });
65
+
66
+ declare module "@nuxt/schema" {
67
+ interface PublicRuntimeConfig {
68
+ jctrans?: {
69
+ sharedConfig?: Partial<SharedConfig>;
70
+ };
71
+ }
72
+ }
@@ -1,8 +1,13 @@
1
- import { defineNuxtPlugin } from "#app";
2
- import JCtransComps from "@jctrans-materials/comps-vue3";
1
+ import { defineNuxtPlugin, useRuntimeConfig } from '#app'
2
+ import { initSharedConfig } from '@jctrans-materials/comps-vue3'
3
3
 
4
- export default defineNuxtPlugin((nuxtApp) => {
5
- // 此时组件已经被 addComponent 自动注册了,
6
- // 我们这里主要执行基础库里的 install 函数,用于挂载指令或全局属性
7
- nuxtApp.vueApp.use(JCtransComps);
8
- });
4
+ export default defineNuxtPlugin(() => {
5
+ const runtimeConfig = useRuntimeConfig()
6
+
7
+ const sharedConfig =
8
+ runtimeConfig.public?.jctrans?.sharedConfig
9
+
10
+ if (sharedConfig) {
11
+ initSharedConfig(sharedConfig)
12
+ }
13
+ })