Skip to content

Commit

Permalink
fix: Fix sourceMap source file does not exist. #325
Browse files Browse the repository at this point in the history
  • Loading branch information
jaywcjlove committed Jan 1, 2022
1 parent 9df8183 commit 42e63fe
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions core/src/plugins/loadSourceMapWarnning.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import FS from 'fs-extra';
import path from 'path';
import { Configuration } from 'webpack';
import { LoaderConfOptions } from '../utils/loaderConf';

Expand All @@ -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;
},
Expand Down

0 comments on commit 42e63fe

Please sign in to comment.