/@fs/ 相关请求处理
export function serveRawFsMiddleware(): Connect.NextHandleFunction {const isWin = os.platform() === 'win32'const serveFromRoot = sirv('/', sirvOptions)return (req, res, next) => {let url = req.url!// In some cases (e.g. linked monorepos) files outside of root will// reference assets that are also out of served root. In such cases// the paths are rewritten to `/@fs/` prefixed paths and must be served by// searching based from fs root.// 如果 url 以 /@fs/ 为前缀,则视为静态资源获取,// 同时,如果是 windows 环境,而且 url 类似于 /@fs/D:asdfasdfasdf 这种带绝对路径的,直接抹除盘符号,强制视为以项目根文件夹为起始路径// 通过 sirv 这个库获取静态文件并返回if (url.startsWith(FS_PREFIX)) {url = url.slice(FS_PREFIX.length)if (isWin) url = url.replace(/^[A-Z]:/i, '')req.url = urlserveFromRoot(req, res, next)} else {next()}}}
