Skip to content

Commit b260bef

Browse files
authored
[Fresh] Add skipEnvCheck option to Babel plugin (#16688)
1 parent 2f15881 commit b260bef

File tree

3 files changed

+5
-5
lines changed

3 files changed

+5
-5
lines changed

packages/react-refresh/src/ReactFreshBabelPlugin.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,16 +7,16 @@
77

88
'use strict';
99

10-
export default function(babel) {
10+
export default function(babel, opts) {
1111
if (typeof babel.getEnv === 'function') {
1212
// Only available in Babel 7.
1313
const env = babel.getEnv();
14-
if (env !== 'development' && typeof expect !== 'function') {
14+
if (env !== 'development' && !opts.skipEnvCheck) {
1515
throw new Error(
1616
'React Refresh Babel transform should only be enabled in development environment. ' +
1717
'Instead, the environment is: "' +
1818
env +
19-
'".',
19+
'". If you want to override this check, pass {skipEnvCheck: true} as plugin options.',
2020
);
2121
}
2222
}

packages/react-refresh/src/__tests__/ReactFreshBabelPlugin-test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ function transform(input, options = {}) {
1919
plugins: [
2020
'@babel/syntax-jsx',
2121
'@babel/syntax-dynamic-import',
22-
freshPlugin,
22+
[freshPlugin, {skipEnvCheck: true}],
2323
...(options.plugins || []),
2424
],
2525
}).code,

packages/react-refresh/src/__tests__/ReactFreshIntegration-test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ describe('ReactFreshIntegration', () => {
6060
babelrc: false,
6161
presets: ['@babel/react'],
6262
plugins: [
63-
freshPlugin,
63+
[freshPlugin, {skipEnvCheck: true}],
6464
'@babel/plugin-transform-modules-commonjs',
6565
compileDestructuring && '@babel/plugin-transform-destructuring',
6666
].filter(Boolean),

0 commit comments

Comments
 (0)