Skip to content

Commit

Permalink
fix(module-tools): catch rebaseUrl error which break the build (#4802)
Browse files Browse the repository at this point in the history
  • Loading branch information
10Derozan authored Oct 17, 2023
1 parent 822c75e commit 0488090
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 14 deletions.
6 changes: 6 additions & 0 deletions .changeset/giant-penguins-poke.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
'@modern-js/module-tools': patch
---

fix(module-tools): catch rebaseUrl error which break the build
fix(module-tools): 捕获会破坏整个构建的 rebaseUrl 错误
33 changes: 19 additions & 14 deletions packages/solutions/module-tools/src/builder/feature/style/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,20 +66,25 @@ export async function rebaseUrls(
if (!cssUrlRE.test(content)) {
return { file };
}
const rebased = await rewriteCssUrls(
content,
path.extname(file).slice(1),
url => {
if (url.startsWith('/')) {
return url;
}
return resolver(url, fileDir);
},
);
return {
file,
contents: rebased,
};
try {
// FIXME: use ast match instead of reg match
const rebased = await rewriteCssUrls(
content,
path.extname(file).slice(1),
url => {
if (url.startsWith('/')) {
return url;
}
return resolver(url, fileDir);
},
);
return {
file,
contents: rebased,
};
} catch (e) {
return { file };
}
}

export function rewriteCssUrls(
Expand Down

0 comments on commit 0488090

Please sign in to comment.