@quicktvui/web-cli 1.0.0-beta.37 → 1.0.0-beta.38
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/bin/qt-web-cli.js +16 -36
- package/lib/webpack.config.js +9 -2
- package/package.json +1 -1
package/bin/qt-web-cli.js
CHANGED
|
@@ -183,10 +183,9 @@ function startDevServer(configPath, port, shouldOpen) {
|
|
|
183
183
|
const WebpackDevServer = require('webpack-dev-server')
|
|
184
184
|
const config = require(configPath)
|
|
185
185
|
|
|
186
|
-
// 确保 devServer 配置正确
|
|
187
186
|
config.devServer = config.devServer || {}
|
|
188
187
|
config.devServer.port = port
|
|
189
|
-
config.devServer.open = false
|
|
188
|
+
config.devServer.open = false
|
|
190
189
|
|
|
191
190
|
const compiler = webpack(config)
|
|
192
191
|
const server = new WebpackDevServer(config.devServer, compiler)
|
|
@@ -198,14 +197,12 @@ function startDevServer(configPath, port, shouldOpen) {
|
|
|
198
197
|
}
|
|
199
198
|
signale.success(`开发服务器已启动: http://localhost:${port}`)
|
|
200
199
|
|
|
201
|
-
// 打开浏览器
|
|
202
200
|
if (shouldOpen) {
|
|
203
201
|
const url = `http://localhost:${port}`
|
|
204
|
-
|
|
202
|
+
openBrowser(url)
|
|
205
203
|
}
|
|
206
204
|
})
|
|
207
205
|
|
|
208
|
-
// 处理退出信号
|
|
209
206
|
process.on('SIGINT', () => {
|
|
210
207
|
server.stopCallback(() => {
|
|
211
208
|
signale.info('开发服务器已停止')
|
|
@@ -251,41 +248,24 @@ function waitForServer(url, timeout = 30000) {
|
|
|
251
248
|
}
|
|
252
249
|
|
|
253
250
|
/**
|
|
254
|
-
*
|
|
251
|
+
* 打开浏览器
|
|
255
252
|
*/
|
|
256
|
-
function
|
|
253
|
+
function openBrowser(url) {
|
|
257
254
|
const platform = process.platform
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
if URL of t starts with "http://localhost:" then
|
|
268
|
-
set URL of t to "${url}"
|
|
269
|
-
set found to true
|
|
270
|
-
exit repeat
|
|
271
|
-
end if
|
|
272
|
-
end repeat
|
|
273
|
-
if found then exit repeat
|
|
274
|
-
end repeat
|
|
275
|
-
if not found then
|
|
276
|
-
open location "${url}"
|
|
277
|
-
end if
|
|
278
|
-
end tell
|
|
279
|
-
`
|
|
280
|
-
|
|
281
|
-
exec(`osascript -e '${appleScript.replace(/\n/g, ' ')}'`, { silent: true })
|
|
282
|
-
signale.success('已打开/刷新浏览器')
|
|
283
|
-
} else {
|
|
284
|
-
// 其他平台:直接打开 URL
|
|
285
|
-
const openCmd = platform === 'win32' ? 'start' : 'xdg-open'
|
|
286
|
-
exec(`${openCmd} "${url}"`, { silent: true })
|
|
255
|
+
const command =
|
|
256
|
+
platform === 'darwin'
|
|
257
|
+
? `open "${url}"`
|
|
258
|
+
: platform === 'win32'
|
|
259
|
+
? `cmd /c start "" "${url}"`
|
|
260
|
+
: `xdg-open "${url}"`
|
|
261
|
+
const result = exec(command, { silent: true })
|
|
262
|
+
|
|
263
|
+
if (result.code === 0) {
|
|
287
264
|
signale.success('已打开浏览器')
|
|
265
|
+
return
|
|
288
266
|
}
|
|
267
|
+
|
|
268
|
+
signale.warn(`自动打开浏览器失败,请手动访问: ${url}`)
|
|
289
269
|
}
|
|
290
270
|
|
|
291
271
|
function findProjectRoot(startDir = process.cwd()) {
|
package/lib/webpack.config.js
CHANGED
|
@@ -10,6 +10,7 @@ const fs = require('fs')
|
|
|
10
10
|
const projectRoot = process.env.QUICKTVUI_PROJECT_ROOT || process.cwd()
|
|
11
11
|
const mainEntry = process.env.QUICKTVUI_MAIN_ENTRY || path.resolve(projectRoot, 'src/main.ts')
|
|
12
12
|
const port = parseInt(process.env.QUICKTVUI_PORT || '39001', 10)
|
|
13
|
+
const watchPoll = parseInt(process.env.QUICKTVUI_WATCH_POLL || '1000', 10)
|
|
13
14
|
|
|
14
15
|
// 尝试加载项目的 package.json
|
|
15
16
|
let pkg = {}
|
|
@@ -114,7 +115,13 @@ module.exports = {
|
|
|
114
115
|
|
|
115
116
|
devServer: {
|
|
116
117
|
port,
|
|
117
|
-
hot:
|
|
118
|
+
hot: false,
|
|
119
|
+
liveReload: true,
|
|
120
|
+
headers: {
|
|
121
|
+
'Cache-Control': 'no-store, no-cache, must-revalidate, proxy-revalidate',
|
|
122
|
+
Pragma: 'no-cache',
|
|
123
|
+
Expires: '0',
|
|
124
|
+
},
|
|
118
125
|
proxy: [
|
|
119
126
|
{
|
|
120
127
|
context: ['/proxy'],
|
|
@@ -149,7 +156,7 @@ module.exports = {
|
|
|
149
156
|
|
|
150
157
|
watchOptions: {
|
|
151
158
|
aggregateTimeout: 1500,
|
|
152
|
-
poll:
|
|
159
|
+
poll: watchPoll,
|
|
153
160
|
ignored: /node_modules/,
|
|
154
161
|
},
|
|
155
162
|
|