@quicktvui/web-cli 1.0.0 → 1.0.1

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.
Files changed (2) hide show
  1. package/bin/qt-web-cli.js +19 -11
  2. package/package.json +2 -1
package/bin/qt-web-cli.js CHANGED
@@ -171,14 +171,6 @@ async function main() {
171
171
 
172
172
  const mainEntryPath = path.resolve(projectRoot, mainEntry)
173
173
 
174
- // 获取 webpack 配置
175
- let webpackConfigPath
176
- if (args.config) {
177
- webpackConfigPath = path.resolve(projectRoot, args.config)
178
- } else {
179
- webpackConfigPath = path.resolve(__dirname, '../lib/webpack.config.js')
180
- }
181
-
182
174
  // 设置环境变量
183
175
  process.env.NODE_ENV = 'development'
184
176
  process.env.QUICKTVUI_PROJECT_ROOT = projectRoot
@@ -196,16 +188,32 @@ async function main() {
196
188
  signale.pending(`启动开发服务器: http://localhost:${args.port}`)
197
189
 
198
190
  // 使用 webpack Node API 启动开发服务器
199
- startDevServer(webpackConfigPath, args.port, args.open)
191
+ const defaultConfigPath = path.resolve(__dirname, '../lib/webpack.config.js')
192
+ const userConfigPath = args.config ? path.resolve(projectRoot, args.config) : null
193
+ startDevServer(defaultConfigPath, args.port, args.open, userConfigPath)
200
194
  }
201
195
 
202
196
  /**
203
197
  * 使用 webpack Node API 启动开发服务器
204
198
  */
205
- function startDevServer(configPath, port, shouldOpen) {
199
+ function startDevServer(configPath, port, shouldOpen, userConfigPath) {
206
200
  const webpack = require('webpack')
207
201
  const WebpackDevServer = require('webpack-dev-server')
208
- const config = require(configPath)
202
+ const { merge } = require('webpack-merge')
203
+
204
+ // 加载内置配置
205
+ let config = require(configPath)
206
+
207
+ // 如果用户指定了自定义配置,进行合并
208
+ if (userConfigPath) {
209
+ if (!fs.existsSync(userConfigPath)) {
210
+ signale.error(`自定义配置文件不存在: ${userConfigPath}`)
211
+ process.exit(1)
212
+ }
213
+ signale.info(`加载用户配置: ${userConfigPath}`)
214
+ const userConfig = require(userConfigPath)
215
+ config = merge(config, userConfig)
216
+ }
209
217
 
210
218
  config.devServer = config.devServer || {}
211
219
  config.devServer.port = port
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@quicktvui/web-cli",
3
- "version": "1.0.0",
3
+ "version": "1.0.1",
4
4
  "description": "CLI tool for QuickTVUI web development - zero configuration",
5
5
  "author": "QuickTVUI Team",
6
6
  "license": "Apache-2.0",
@@ -24,6 +24,7 @@
24
24
  "minimist": "^1.2.8",
25
25
  "shelljs": "^0.10.0",
26
26
  "signale": "^1.4.0",
27
+ "webpack-merge": "^6.0.0",
27
28
  "@quicktvui/web-renderer": "^1.0.9",
28
29
  "scope-loader": "^1.0.3",
29
30
  "chokidar": "^3.5.3",