[Fresh] Add skipEnvCheck option to Babel plugin (#16688)
Dan Abramov committed
Sep 6, 2019 at 20:30 UTC
b260bef398c4da465a41f6b95bc0cf64deafdfd7
3 files changed
+5
-5
packages/react-refresh/src/ReactFreshBabelPlugin.js
+3
-3
@@ -7,16 +7,16 @@
7
8
'use strict';
9
10
-export default function(babel) {
10
+export default function(babel, opts) {
11
if (typeof babel.getEnv === 'function') {
12
// Only available in Babel 7.
13
const env = babel.getEnv();
14
- if (env !== 'development' && typeof expect !== 'function') {
14
+ if (env !== 'development' && !opts.skipEnvCheck) {
15
throw new Error(
16
'React Refresh Babel transform should only be enabled in development environment. ' +
17
'Instead, the environment is: "' +
18
env +
19
- '".',
19
+ '". If you want to override this check, pass {skipEnvCheck: true} as plugin options.',
20
);
21
}
22
}
packages/react-refresh/src/__tests__/ReactFreshBabelPlugin-test.js
+1
-1
@@ -19,7 +19,7 @@ function transform(input, options = {}) {
19
plugins: [
20
'@babel/syntax-jsx',
21
'@babel/syntax-dynamic-import',
22
- freshPlugin,
22
+ [freshPlugin, {skipEnvCheck: true}],
23
...(options.plugins || []),
24
],
25
}).code,
packages/react-refresh/src/__tests__/ReactFreshIntegration-test.js
+1
-1
@@ -60,7 +60,7 @@ describe('ReactFreshIntegration', () => {
60
babelrc: false,
61
presets: ['@babel/react'],
62
plugins: [
63
- freshPlugin,
63
+ [freshPlugin, {skipEnvCheck: true}],
64
'@babel/plugin-transform-modules-commonjs',
65
compileDestructuring && '@babel/plugin-transform-destructuring',
66
].filter(Boolean),