nuxt-gin-tools 0.2.14 → 0.2.15
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 +16 -1
- package/package.json +1 -1
- package/src/nuxt-config.js +13 -0
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
package/src/nuxt-config.js
CHANGED
|
@@ -2,6 +2,9 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.createDefaultConfig = createDefaultConfig;
|
|
4
4
|
const node_http_1 = require("node:http");
|
|
5
|
+
function isDevEnvironment() {
|
|
6
|
+
return process.env.NODE_ENV !== "production";
|
|
7
|
+
}
|
|
5
8
|
function normalizePathPrefix(value) {
|
|
6
9
|
const withLeadingSlash = value.startsWith("/") ? value : `/${value}`;
|
|
7
10
|
if (withLeadingSlash !== "/" && withLeadingSlash.endsWith("/")) {
|
|
@@ -82,7 +85,9 @@ function forwardWebSocketToGin(ginPort, req, clientSocket, clientHead) {
|
|
|
82
85
|
* 创建默认的 Nuxt 配置。
|
|
83
86
|
*/
|
|
84
87
|
function createDefaultConfig({ serverConfig, }) {
|
|
88
|
+
const development = isDevEnvironment();
|
|
85
89
|
const baseUrl = normalizeBaseUrl(serverConfig.baseUrl);
|
|
90
|
+
const publicGinPort = development ? serverConfig.ginPort : null;
|
|
86
91
|
return {
|
|
87
92
|
buildDir: "vue/.nuxt",
|
|
88
93
|
srcDir: "vue",
|
|
@@ -96,6 +101,14 @@ function createDefaultConfig({ serverConfig, }) {
|
|
|
96
101
|
},
|
|
97
102
|
},
|
|
98
103
|
app: { baseURL: serverConfig.baseUrl },
|
|
104
|
+
runtimeConfig: {
|
|
105
|
+
public: {
|
|
106
|
+
// Frontend can read this via useRuntimeConfig().public.ginPort in dev.
|
|
107
|
+
ginPort: publicGinPort,
|
|
108
|
+
// Frontend can use this to branch dev/prod logic directly.
|
|
109
|
+
isDevelopment: development,
|
|
110
|
+
},
|
|
111
|
+
},
|
|
99
112
|
devServer: {
|
|
100
113
|
port: serverConfig.nuxtPort,
|
|
101
114
|
cors: {
|