Open thatsmydoing opened 1 year ago
The issue we've found here is when the regexp passed to require.context
uses a lookbehind expression like /(?<!.spec).(js|tsx)$/
, swc transforms it to RegExp("(?<!.spec).(js|tsx)$")
. Playground
webpack only processes require.context
if the provided regex is a literal and otherwise skips it. So in our case, removing the lookbehind made swc keep it as a literal and it worked for us. Another option is to set the target to ES2022
(if the project allows) where swc will keep it as a literal too.
Though it would be nice if swc-loader
could be smart about this and not transform require.context
arguments but I'm not sure how feasible that is.
From https://github.com/swc-project/swc-loader/issues/64#issue-1335268930 by @callmeteus