Skip to content

Commit 21bfabb

Browse files
committed
improve regex for matching react modules
1 parent 945d181 commit 21bfabb

File tree

1 file changed

+12
-9
lines changed
  • packages/app/src/sandbox/eval/presets/create-react-app/utils

1 file changed

+12
-9
lines changed

packages/app/src/sandbox/eval/presets/create-react-app/utils/reactPreset.ts

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -69,18 +69,15 @@ export const reactPreset = babelConfig => {
6969
[{ transpiler: babelTranspiler, options: {} }]
7070
);
7171

72-
const isJavaScript = (p: string) => {
73-
return /\.(m|c)?(t|j)sx?$/.test(p) && !p.endsWith('.d.ts');
74-
};
75-
7672
if (isRefresh) {
7773
debug('Refresh is enabled, registering additional transpiler');
7874
// Add react refresh babel plugin for non-node_modules
7975

8076
preset.registerTranspiler(
8177
module =>
82-
!module.path.startsWith('/node_modules') &&
83-
isJavaScript(module.path),
78+
/^(?!\/node_modules\/).*\.(((m|c)?jsx?)|tsx)$/.test(
79+
module.path
80+
),
8481
[
8582
{
8683
transpiler: babelTranspiler,
@@ -102,9 +99,15 @@ export const reactPreset = babelConfig => {
10299
debug('Refresh is disabled');
103100
}
104101

105-
preset.registerTranspiler(module => isJavaScript(module.path), [
106-
{ transpiler: babelTranspiler, options: babelConfig },
107-
]);
102+
preset.registerTranspiler(
103+
module => {
104+
return (
105+
/\.(m|c)?(t|j)sx?$/.test(module.path) &&
106+
!module.path.endsWith('.d.ts')
107+
);
108+
},
109+
[{ transpiler: babelTranspiler, options: babelConfig }]
110+
);
108111

109112
// svgr is required for the react-svg-transpiler
110113
preset.addTranspiler(svgrTranspiler);

0 commit comments

Comments
 (0)