nuxt-gin-tools 0.2.14 → 0.2.16

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 CHANGED
@@ -88,6 +88,22 @@ Go 监听规则来自 `.go-watch.json`(见下文)。
88
88
  - `killPortBeforeDevelop`: 开发前是否释放端口(默认 `true`)
89
89
  - `cleanupBeforeDevelop`: 开发前是否执行 cleanup(默认 `false`)
90
90
 
91
+ ### 3) 开发环境向前端暴露 `ginPort`
92
+
93
+ `createDefaultConfig` 会在 Nuxt `runtimeConfig.public` 中注入 `ginPort`:
94
+
95
+ - 开发环境:`useRuntimeConfig().public.ginPort` 为 `server.config.json` 的 `ginPort`
96
+ - 生产环境:`useRuntimeConfig().public.ginPort` 为 `null`
97
+ - 所有环境:`useRuntimeConfig().public.isDevelopment` 直接暴露当前是否开发环境
98
+
99
+ 前端示例:
100
+
101
+ ```ts
102
+ const config = useRuntimeConfig();
103
+ const ginPort = config.public.ginPort;
104
+ const isDevelopment = config.public.isDevelopment;
105
+ ```
106
+
91
107
  ### 2) `.go-watch.json`
92
108
 
93
109
  Go 监听配置文件,示例:
@@ -132,4 +148,3 @@ NUXT_GIN_WATCH_CONFIG=/path/to/.go-watch.json
132
148
 
133
149
  - Go 侧热更新已不再依赖 Air。
134
150
  - 当前方案为:`chokidar` 监听文件变化 + 重启 `go run main.go`。
135
-
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "nuxt-gin-tools",
3
- "version": "0.2.14",
3
+ "version": "0.2.16",
4
4
  "description": "This project is used as a dependency for [nuxt-gin-starter](https://github.com/RapboyGao/nuxt-gin-starter.git)",
5
5
  "bin": {
6
6
  "nuxt-gin": "index.js"
@@ -2,6 +2,10 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.createDefaultConfig = createDefaultConfig;
4
4
  const node_http_1 = require("node:http");
5
+ const node_path_1 = require("node:path");
6
+ function isDevEnvironment() {
7
+ return process.env.NODE_ENV !== "production";
8
+ }
5
9
  function normalizePathPrefix(value) {
6
10
  const withLeadingSlash = value.startsWith("/") ? value : `/${value}`;
7
11
  if (withLeadingSlash !== "/" && withLeadingSlash.endsWith("/")) {
@@ -82,10 +86,17 @@ function forwardWebSocketToGin(ginPort, req, clientSocket, clientHead) {
82
86
  * 创建默认的 Nuxt 配置。
83
87
  */
84
88
  function createDefaultConfig({ serverConfig, }) {
89
+ const development = isDevEnvironment();
85
90
  const baseUrl = normalizeBaseUrl(serverConfig.baseUrl);
91
+ const publicGinPort = development ? serverConfig.ginPort : null;
86
92
  return {
87
93
  buildDir: "vue/.nuxt",
88
94
  srcDir: "vue",
95
+ nitro: {
96
+ output: {
97
+ dir: (0, node_path_1.join)(process.cwd(), "vue", ".output"),
98
+ },
99
+ },
89
100
  ssr: false,
90
101
  experimental: {
91
102
  payloadExtraction: false,
@@ -96,6 +107,14 @@ function createDefaultConfig({ serverConfig, }) {
96
107
  },
97
108
  },
98
109
  app: { baseURL: serverConfig.baseUrl },
110
+ runtimeConfig: {
111
+ public: {
112
+ // Frontend can read this via useRuntimeConfig().public.ginPort in dev.
113
+ ginPort: publicGinPort,
114
+ // Frontend can use this to branch dev/prod logic directly.
115
+ isDevelopment: development,
116
+ },
117
+ },
99
118
  devServer: {
100
119
  port: serverConfig.nuxtPort,
101
120
  cors: {