From 42e63fe0f93b1589dd4d93dda79a818b8d18ebc4 Mon Sep 17 00:00:00 2001 From: jaywcjlove <398188662@qq.com> Date: Sun, 2 Jan 2022 00:05:20 +0800 Subject: [PATCH] fix: Fix sourceMap source file does not exist. #325 --- core/src/plugins/loadSourceMapWarnning.ts | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/core/src/plugins/loadSourceMapWarnning.ts b/core/src/plugins/loadSourceMapWarnning.ts index 491c25ec..1e9b729b 100644 --- a/core/src/plugins/loadSourceMapWarnning.ts +++ b/core/src/plugins/loadSourceMapWarnning.ts @@ -1,4 +1,5 @@ import FS from 'fs-extra'; +import path from 'path'; import { Configuration } from 'webpack'; import { LoaderConfOptions } from '../utils/loaderConf'; @@ -17,8 +18,17 @@ export function loadSourceMapWarnning( // ;(conf.module.rules[0] as any).exclude = /((@babel(?:\/|\\{1,2})runtime)|codesandbox-import-utils)/; (conf.module.rules[0] as any).options = { filterSourceMappingUrl: (url: string, resourcePath: string) => { - if (/\.(js|mjs|jsx|ts|tsx|css)$/.test(resourcePath) && !FS.existsSync(resourcePath)) { - return 'skip'; + const sourceMapPath = path.join(path.dirname(resourcePath), url); + if (FS.existsSync(sourceMapPath)) { + const { sources = [] } = FS.readJsonSync(sourceMapPath); + if (Array.isArray(sources) && sources.length > 0) { + const isexists = sources + .map((item: string) => FS.existsSync(path.resolve(path.dirname(resourcePath), item))) + .find((item) => item === false); + if (isexists === false) { + return 'skip'; + } + } } return true; },