[Fresh] Add skipEnvCheck option to Babel plugin (#16688)

This commit is contained in:
Dan Abramov
2019-09-06 20:30:16 +01:00
committed by GitHub
parent 2f15881859
commit b260bef398
3 changed files with 5 additions and 5 deletions

View File

@@ -7,16 +7,16 @@
'use strict';
export default function(babel) {
export default function(babel, opts) {
if (typeof babel.getEnv === 'function') {
// Only available in Babel 7.
const env = babel.getEnv();
if (env !== 'development' && typeof expect !== 'function') {
if (env !== 'development' && !opts.skipEnvCheck) {
throw new Error(
'React Refresh Babel transform should only be enabled in development environment. ' +
'Instead, the environment is: "' +
env +
'".',
'". If you want to override this check, pass {skipEnvCheck: true} as plugin options.',
);
}
}

View File

@@ -19,7 +19,7 @@ function transform(input, options = {}) {
plugins: [
'@babel/syntax-jsx',
'@babel/syntax-dynamic-import',
freshPlugin,
[freshPlugin, {skipEnvCheck: true}],
...(options.plugins || []),
],
}).code,

View File

@@ -60,7 +60,7 @@ describe('ReactFreshIntegration', () => {
babelrc: false,
presets: ['@babel/react'],
plugins: [
freshPlugin,
[freshPlugin, {skipEnvCheck: true}],
'@babel/plugin-transform-modules-commonjs',
compileDestructuring && '@babel/plugin-transform-destructuring',
].filter(Boolean),