@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 +20 -44
- package/lib/entry-package.js +15 -13
- package/lib/webpack.config.js +15 -18
- package/package.json +1 -1
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
|
-
*
|
|
251
|
+
* 打开浏览器
|
|
259
252
|
*/
|
|
260
|
-
function
|
|
253
|
+
function openBrowser(url) {
|
|
261
254
|
const platform = process.platform
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
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()) {
|
package/lib/entry-package.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
// @quicktvui/web-cli - web entry
|
|
2
2
|
// 通过 @quicktvui/web-renderer 导入所有依赖
|
|
3
|
-
//
|
|
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
|
-
//
|
|
53
|
-
console.log('[Web Renderer]
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
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
|
+
})
|
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 = {}
|
|
@@ -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
|
-
//
|
|
108
|
+
// 入口文件:只加载 entry-package.js,主入口通过动态 import 加载
|
|
108
109
|
const entryPackageFile = path.resolve(__dirname, 'entry-package.js')
|
|
109
|
-
|
|
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:
|
|
114
|
+
bail: true,
|
|
115
115
|
|
|
116
116
|
devServer: {
|
|
117
117
|
port,
|
|
118
|
-
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
|
+
},
|
|
119
125
|
proxy: [
|
|
120
126
|
{
|
|
121
127
|
context: ['/proxy'],
|
|
@@ -149,35 +155,26 @@ module.exports = {
|
|
|
149
155
|
},
|
|
150
156
|
|
|
151
157
|
watchOptions: {
|
|
152
|
-
aggregateTimeout:
|
|
153
|
-
poll:
|
|
158
|
+
aggregateTimeout: 1500,
|
|
159
|
+
poll: watchPoll,
|
|
154
160
|
ignored: /node_modules/,
|
|
155
161
|
},
|
|
156
162
|
|
|
157
163
|
devtool: 'source-map',
|
|
158
164
|
|
|
159
|
-
//
|
|
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,
|