Skip to content

Commit bba99b1

Browse files
Adamlyu-hubSingle-Dancer
authored andcommitted
fix: 更正ServerOptions类型使用
1 parent 4750e9d commit bba99b1

File tree

2 files changed

+13
-6
lines changed

2 files changed

+13
-6
lines changed

packages/taro-vite-runner/src/h5/config.ts

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import { getHtmlScript } from '../utils/html'
1212

1313
import type { PostcssOption } from '@tarojs/taro/types/compile'
1414
import type { ViteH5CompilerContext } from '@tarojs/taro/types/compile/viteCompilerContext'
15-
import type { PluginOption, ServerOptions } from 'vite'
15+
import type { PluginOption } from 'vite'
1616

1717

1818
export default function (viteCompilerContext: ViteH5CompilerContext): PluginOption {
@@ -93,9 +93,9 @@ export default function (viteCompilerContext: ViteH5CompilerContext): PluginOpti
9393
esnextModules: taroConfig.esnextModules || []
9494
})
9595
const [, pxtransformOption] = __postcssOption.find(([name]) => name === 'postcss-pxtransform') || []
96-
const serverOption: ServerOptions = (taroConfig.devServer || {}) as ServerOptions
97-
let headers: Record<string, string | string[]> = {}
98-
if (isObject<Record<string, string | string[]>>(serverOption.headers)) {
96+
const serverOption = taroConfig.devServer || {}
97+
let headers = {}
98+
if (isObject<Record<string, any>>(serverOption.headers)) {
9999
headers = serverOption.headers
100100
}
101101

@@ -164,6 +164,11 @@ export default function (viteCompilerContext: ViteH5CompilerContext): PluginOpti
164164
allowedHosts = [serverOption.allowedHosts]
165165
}
166166

167+
let sourcemapIgnoreList: false | ((sourcePath: string, sourcemapPath: string) => boolean) = (sourcePath) => sourcePath.includes('node_modules')
168+
if (typeof serverOption.sourcemapIgnoreList === 'boolean' || typeof serverOption.sourcemapIgnoreList === 'function') {
169+
sourcemapIgnoreList = serverOption.sourcemapIgnoreList
170+
}
171+
167172
return {
168173
name: 'taro:vite-h5-config',
169174
enforce: 'pre',
@@ -238,7 +243,7 @@ export default function (viteCompilerContext: ViteH5CompilerContext): PluginOpti
238243
allowedHosts,
239244
middlewareMode,
240245
strictPort,
241-
246+
sourcemapIgnoreList,
242247
origin,
243248
cors,
244249
},

packages/taro/types/compile/config/h5.d.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import type { IOption, IPostcssOption, IUrlLoaderOption } from './util'
66
import type { OutputOptions as RollupOutputOptions } from 'rollup'
77
import type { Compiler, CompilerTypes, CompilerWebpackTypes } from '../compiler'
88
import type { OutputExt } from './project'
9+
import type { ServerOptions as ViteServerOptions } from 'vite'
910

1011
export interface IH5RouterConfig {
1112
/** 配置路由模式 */
@@ -51,7 +52,8 @@ export interface IH5Config <T extends CompilerTypes = CompilerWebpackTypes> {
5152
router?: IH5RouterConfig
5253

5354
/** 预览服务的配置,可以更改端口等参数。具体配置参考 [webpack-dev-server](https://webpack.js.org/configuration/dev-server) */
54-
devServer?: webpackDevServer.Configuration
55+
// 修改后:同时支持 Webpack 和 Vite
56+
devServer?: T extends 'vite' ? ViteServerOptions : webpackDevServer.Configuration
5557

5658
/** 用于控制是否生成 js、css 对应的 sourceMap (默认值:watch 模式下为 true,否则为 false) */
5759
enableSourceMap?: boolean

0 commit comments

Comments
 (0)