@quicktvui/web-cli 1.0.0-beta.24 → 1.0.0-beta.26
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 +40 -23
- package/package.json +1 -1
package/bin/qt-web-cli.js
CHANGED
|
@@ -164,37 +164,54 @@ async function main() {
|
|
|
164
164
|
|
|
165
165
|
// 检测 OpenSSL 版本
|
|
166
166
|
const needLegacyProvider = checkOpenSSLVersion(process.versions.openssl)
|
|
167
|
-
let nodeOptions = ''
|
|
168
167
|
if (needLegacyProvider) {
|
|
169
|
-
nodeOptions = '--openssl-legacy-provider'
|
|
170
168
|
signale.warn(`检测到 OpenSSL ${process.versions.openssl},已添加 --openssl-legacy-provider`)
|
|
169
|
+
process.env.NODE_OPTIONS = '--openssl-legacy-provider'
|
|
171
170
|
}
|
|
172
171
|
|
|
173
|
-
|
|
174
|
-
const webpackArgs = ['serve', `--config "${webpackConfigPath}"`, `--port ${args.port}`, '--color']
|
|
172
|
+
signale.pending(`启动开发服务器: http://localhost:${args.port}`)
|
|
175
173
|
|
|
176
|
-
|
|
177
|
-
|
|
174
|
+
// 使用 webpack Node API 启动开发服务器
|
|
175
|
+
startDevServer(webpackConfigPath, args.port, args.open)
|
|
176
|
+
}
|
|
178
177
|
|
|
179
|
-
|
|
178
|
+
/**
|
|
179
|
+
* 使用 webpack Node API 启动开发服务器
|
|
180
|
+
*/
|
|
181
|
+
function startDevServer(configPath, port, shouldOpen) {
|
|
182
|
+
const webpack = require('webpack')
|
|
183
|
+
const WebpackDevServer = require('webpack-dev-server')
|
|
184
|
+
const config = require(configPath)
|
|
185
|
+
|
|
186
|
+
// 确保 devServer 配置正确
|
|
187
|
+
config.devServer = config.devServer || {}
|
|
188
|
+
config.devServer.port = port
|
|
189
|
+
config.devServer.open = false // 我们自己控制浏览器打开
|
|
190
|
+
|
|
191
|
+
const compiler = webpack(config)
|
|
192
|
+
const server = new WebpackDevServer(config.devServer, compiler)
|
|
193
|
+
|
|
194
|
+
server.startCallback((err) => {
|
|
195
|
+
if (err) {
|
|
196
|
+
signale.error('启动开发服务器失败:', err.message)
|
|
197
|
+
process.exit(1)
|
|
198
|
+
}
|
|
199
|
+
signale.success(`开发服务器已启动: http://localhost:${port}`)
|
|
180
200
|
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
})
|
|
188
|
-
.catch((err) => {
|
|
189
|
-
signale.warn(`自动打开浏览器失败: ${err.message}`)
|
|
190
|
-
})
|
|
191
|
-
}
|
|
201
|
+
// 打开浏览器
|
|
202
|
+
if (shouldOpen) {
|
|
203
|
+
const url = `http://localhost:${port}`
|
|
204
|
+
openOrRefreshBrowser(url)
|
|
205
|
+
}
|
|
206
|
+
})
|
|
192
207
|
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
208
|
+
// 处理退出信号
|
|
209
|
+
process.on('SIGINT', () => {
|
|
210
|
+
server.stopCallback(() => {
|
|
211
|
+
signale.info('开发服务器已停止')
|
|
212
|
+
process.exit(0)
|
|
213
|
+
})
|
|
214
|
+
})
|
|
198
215
|
}
|
|
199
216
|
|
|
200
217
|
/**
|