@quicktvui/web-cli 1.0.0-beta.25 → 1.0.0-beta.27

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
@@ -164,40 +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
- // 构建 webpack 命令 - 使用 web-cli 自带的 webpack-cli
174
- const webpackCliPath = require.resolve('webpack-cli/bin/cli.js', {
175
- paths: [path.resolve(__dirname, '..')],
176
- })
177
- const webpackArgs = [webpackCliPath, 'serve', `--config "${webpackConfigPath}"`, `--port ${args.port}`, '--color']
172
+ signale.pending(`启动开发服务器: http://localhost:${args.port}`)
178
173
 
179
- const envPrefix = nodeOptions ? `NODE_OPTIONS="${nodeOptions}" ` : ''
180
- const webpackCmd = `${envPrefix}node ${webpackArgs.join(' ')}`
174
+ // 使用 webpack Node API 启动开发服务器
175
+ startDevServer(webpackConfigPath, args.port, args.open)
176
+ }
181
177
 
182
- signale.pending(`执行: webpack serve --port ${args.port}`)
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}`)
183
200
 
184
- // 如果需要打开浏览器,等待服务器就绪后打开
185
- if (args.open) {
186
- const url = `http://localhost:${args.port}`
187
- waitForServer(url, 30000)
188
- .then(() => {
189
- openOrRefreshBrowser(url)
190
- })
191
- .catch((err) => {
192
- signale.warn(`自动打开浏览器失败: ${err.message}`)
193
- })
194
- }
201
+ // 打开浏览器
202
+ if (shouldOpen) {
203
+ const url = `http://localhost:${port}`
204
+ openOrRefreshBrowser(url)
205
+ }
206
+ })
195
207
 
196
- const result = exec(webpackCmd, { stdio: 'inherit' })
197
- if (result.code !== 0) {
198
- signale.error('启动开发服务器失败')
199
- process.exit(1)
200
- }
208
+ // 处理退出信号
209
+ process.on('SIGINT', () => {
210
+ server.stopCallback(() => {
211
+ signale.info('开发服务器已停止')
212
+ process.exit(0)
213
+ })
214
+ })
201
215
  }
202
216
 
203
217
  /**
@@ -100,6 +100,10 @@ function detectCSSLoader() {
100
100
 
101
101
  const cssLoader = detectCSSLoader()
102
102
 
103
+ // 获取 web-cli 目录下的 loader 路径
104
+ const cliDir = path.resolve(__dirname, '..')
105
+ const resolveLoader = (loaderName) => require.resolve(loaderName, { paths: [cliDir] })
106
+
103
107
  // 入口文件:只加载 entry-package.js,主入口通过动态 import 加载
104
108
  const entryPackageFile = path.resolve(__dirname, 'entry-package.js')
105
109
  const entryFiles = ['regenerator-runtime/runtime', entryPackageFile]
@@ -196,7 +200,7 @@ module.exports = {
196
200
  loader: 'vue-loader',
197
201
  options: { compilerOptions: { whitespace: 'condense' } },
198
202
  },
199
- 'scope-loader',
203
+ require.resolve('scope-loader', { paths: [path.resolve(__dirname, '..')] }),
200
204
  ],
201
205
  },
202
206
  // TypeScript 文件
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@quicktvui/web-cli",
3
- "version": "1.0.0-beta.25",
3
+ "version": "1.0.0-beta.27",
4
4
  "description": "CLI tool for QuickTVUI web development - zero configuration",
5
5
  "author": "QuickTVUI Team",
6
6
  "license": "Apache-2.0",