@quicktvui/web-cli 1.0.0-beta.36 → 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 CHANGED
@@ -183,33 +183,26 @@ 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)
193
192
 
194
- // 监听编译完成事件,在首次编译完成后打开浏览器
195
- let isOpened = false
196
- compiler.hooks.done.tap('open-browser', (stats) => {
197
- if (!isOpened && shouldOpen) {
198
- isOpened = true
199
- const url = `http://localhost:${port}`
200
- openOrRefreshBrowser(url)
201
- }
202
- })
203
-
204
193
  server.startCallback((err) => {
205
194
  if (err) {
206
195
  signale.error('启动开发服务器失败:', err.message)
207
196
  process.exit(1)
208
197
  }
209
198
  signale.success(`开发服务器已启动: http://localhost:${port}`)
199
+
200
+ if (shouldOpen) {
201
+ const url = `http://localhost:${port}`
202
+ openBrowser(url)
203
+ }
210
204
  })
211
205
 
212
- // 处理退出信号
213
206
  process.on('SIGINT', () => {
214
207
  server.stopCallback(() => {
215
208
  signale.info('开发服务器已停止')
@@ -255,41 +248,24 @@ function waitForServer(url, timeout = 30000) {
255
248
  }
256
249
 
257
250
  /**
258
- * 打开或刷新浏览器(支持 macOS)
251
+ * 打开浏览器
259
252
  */
260
- function openOrRefreshBrowser(url) {
253
+ function openBrowser(url) {
261
254
  const platform = process.platform
262
-
263
- if (platform === 'darwin') {
264
- // macOS: 使用 AppleScript 检查并刷新已存在的标签页
265
- const appleScript = `
266
- tell application "Safari"
267
- activate
268
- set found to false
269
- repeat with w in windows
270
- repeat with t in tabs of w
271
- if URL of t starts with "http://localhost:" then
272
- set URL of t to "${url}"
273
- set found to true
274
- exit repeat
275
- end if
276
- end repeat
277
- if found then exit repeat
278
- end repeat
279
- if not found then
280
- open location "${url}"
281
- end if
282
- end tell
283
- `
284
-
285
- exec(`osascript -e '${appleScript.replace(/\n/g, ' ')}'`, { silent: true })
286
- signale.success('已打开/刷新浏览器')
287
- } else {
288
- // 其他平台:直接打开 URL
289
- const openCmd = platform === 'win32' ? 'start' : 'xdg-open'
290
- 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) {
291
264
  signale.success('已打开浏览器')
265
+ return
292
266
  }
267
+
268
+ signale.warn(`自动打开浏览器失败,请手动访问: ${url}`)
293
269
  }
294
270
 
295
271
  function findProjectRoot(startDir = process.cwd()) {
@@ -1,6 +1,6 @@
1
1
  // @quicktvui/web-cli - web entry
2
2
  // 通过 @quicktvui/web-renderer 导入所有依赖
3
- // 主入口由 webpack 在本文件之前加载,App 已注册
3
+ // 动态加载主入口,确保初始化顺序正确
4
4
 
5
5
  console.log('[Web Renderer] === Starting initialization ===')
6
6
 
@@ -49,15 +49,17 @@ styleEl.textContent = `
49
49
  document.head.appendChild(styleEl)
50
50
  console.log('[Web Renderer] Global CSS reset injected')
51
51
 
52
- // 启动引擎(主入口已在前加载并注册 App)
53
- console.log('[Web Renderer] Starting engine...')
54
- startWebEngine(engine, APP_NAME)
55
- console.log('[Web Renderer] === Initialization complete ===')
56
-
57
- // HMR 支持
58
-
59
- if (module.hot) {
60
-
61
- module.hot.accept()
62
-
63
- }
52
+ // 动态加载主入口,等待加载完成后再启动引擎
53
+ console.log('[Web Renderer] Importing main module...')
54
+ import(__QUICKTVUI_MAIN_ENTRY__)
55
+ .then(() => {
56
+ console.log('[Web Renderer] Main module loaded')
57
+ console.log('[Web Renderer] Starting engine...')
58
+ startWebEngine(engine, APP_NAME)
59
+ setTimeout(() => {
60
+ console.log('[Web Renderer] === Initialization complete ===')
61
+ }, 1000)
62
+ })
63
+ .catch((err) => {
64
+ console.error('[Web Renderer] Failed to load main module:', err)
65
+ })
@@ -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 = {}
@@ -104,18 +105,23 @@ const cssLoader = detectCSSLoader()
104
105
  const cliDir = path.resolve(__dirname, '..')
105
106
  const resolveLoader = (loaderName) => require.resolve(loaderName, { paths: [cliDir] })
106
107
 
107
- // 入口文件:主入口作为静态入口以便 HMR 追踪
108
+ // 入口文件:只加载 entry-package.js,主入口通过动态 import 加载
108
109
  const entryPackageFile = path.resolve(__dirname, 'entry-package.js')
109
- // 手动注入 webpack-dev-server 客户端(全局安装时需要)
110
- const webpackDevServerPath = require.resolve('webpack-dev-server/client', { paths: [cliDir] })
110
+ const entryFiles = ['regenerator-runtime/runtime', entryPackageFile]
111
111
 
112
112
  module.exports = {
113
113
  mode: 'development',
114
- bail: false,
114
+ bail: true,
115
115
 
116
116
  devServer: {
117
117
  port,
118
- hot: true,
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
+ },
119
125
  proxy: [
120
126
  {
121
127
  context: ['/proxy'],
@@ -149,35 +155,26 @@ module.exports = {
149
155
  },
150
156
 
151
157
  watchOptions: {
152
- aggregateTimeout: 300,
153
- poll: 1000, // 移动硬盘必须使用轮询
158
+ aggregateTimeout: 1500,
159
+ poll: watchPoll,
154
160
  ignored: /node_modules/,
155
161
  },
156
162
 
157
163
  devtool: 'source-map',
158
164
 
159
- // 入口配置:主入口在 entry-package 之前加载以确保 App 先注册
160
- // webpack 会按顺序执行入口文件
165
+ // 多入口配置:先加载初始化代码,再加载主入口
161
166
  entry: {
162
- index: [
163
- `${webpackDevServerPath}?http://localhost:${port}`,
164
- 'webpack/hot/dev-server',
165
- 'regenerator-runtime/runtime',
166
- mainEntry, // 先加载主入口,注册 App
167
- entryPackageFile, // 再加载初始化代码,启动引擎
168
- ],
167
+ index: entryFiles,
169
168
  },
170
169
 
171
170
  output: {
172
171
  filename: 'index.bundle.js',
173
172
  path: path.resolve(projectRoot, './dist/web/'),
174
- publicPath: '/',
175
173
  strictModuleExceptionHandling: true,
176
174
  globalObject: '(0, eval)("this")',
177
175
  },
178
176
 
179
177
  plugins: [
180
- new (require('webpack').HotModuleReplacementPlugin)(),
181
178
  new (require('vue-loader').VueLoaderPlugin)(),
182
179
  new (require('html-webpack-plugin'))({
183
180
  inject: true,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@quicktvui/web-cli",
3
- "version": "1.0.0-beta.36",
3
+ "version": "1.0.0-beta.38",
4
4
  "description": "CLI tool for QuickTVUI web development - zero configuration",
5
5
  "author": "QuickTVUI Team",
6
6
  "license": "Apache-2.0",