How to use metro-babel-register - 7 common examples

To help you get started, we’ve selected a few metro-babel-register examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github MetaMask / metamask-mobile / jest.preprocessor.js View on Github external
* found when Flow v0.54 was deployed. To see the error delete this comment and
 * run Flow. */
const babelRegisterOnly = require('metro-babel-register');
/* $FlowFixMe(>=0.54.0 site=react_native_oss) This comment suppresses an error
 * found when Flow v0.54 was deployed. To see the error delete this comment and
 * run Flow. */
const createCacheKeyFunction = require('fbjs-scripts/jest/createCacheKeyFunction');
const generate = require('@babel/generator').default;

const nodeFiles = new RegExp(
	[
		'/metro(?:-[^/]*)?/', // metro, metro-core, metro-source-map, metro-etc.
	].join('|'),
);

const nodeOptions = babelRegisterOnly.config([nodeFiles]);

babelRegisterOnly([]);

/* $FlowFixMe(site=react_native_oss) */
const transformer = require('metro-react-native-babel-transformer');
module.exports = {
	process(src /*: string */, file /*: string */) {
		if (nodeFiles.test(file)) {
			// node specific transforms only
			return babelTransformSync(src, {
				filename: file,
				sourceType: 'script',
				...nodeOptions,
				ast: false
			}).code;
		}
github lieryang / EYDouYin / EYDouYin / node_modules / react-native / jest / preprocessor.js View on Github external
/* $FlowFixMe(>=0.54.0 site=react_native_oss) This comment suppresses an error
 * found when Flow v0.54 was deployed. To see the error delete this comment and
 * run Flow. */
const babelRegisterOnly = require('metro-babel-register');
/* $FlowFixMe(>=0.54.0 site=react_native_oss) This comment suppresses an error
 * found when Flow v0.54 was deployed. To see the error delete this comment and
 * run Flow. */
const createCacheKeyFunction = require('fbjs-scripts/jest/createCacheKeyFunction');
const generate = require('@babel/generator').default;

const nodeFiles = new RegExp(
  [
    '/metro(?:-[^/]*)?/', // metro, metro-core, metro-source-map, metro-etc.
  ].join('|'),
);
const nodeOptions = babelRegisterOnly.config([nodeFiles]);

babelRegisterOnly([]);

const transformer = require('metro-react-native-babel-transformer');
module.exports = {
  process(src /*: string */, file /*: string */) {
    if (nodeFiles.test(file)) {
      // node specific transforms only
      return babelTransformSync(src, {
        filename: file,
        sourceType: 'script',
        ...nodeOptions,
        ast: false,
      }).code;
    }
github Marwan01 / food-converter / node_modules / react-native / jest / preprocessor.js View on Github external
/* $FlowFixMe(>=0.54.0 site=react_native_oss) This comment suppresses an error
 * found when Flow v0.54 was deployed. To see the error delete this comment and
 * run Flow. */
const babelRegisterOnly = require('metro-babel-register');
/* $FlowFixMe(>=0.54.0 site=react_native_oss) This comment suppresses an error
 * found when Flow v0.54 was deployed. To see the error delete this comment and
 * run Flow. */
const createCacheKeyFunction = require('fbjs-scripts/jest/createCacheKeyFunction');
const generate = require('@babel/generator').default;

const nodeFiles = new RegExp(
  [
    '/metro(?:-[^/]*)?/', // metro, metro-core, metro-source-map, metro-etc.
  ].join('|'),
);
const nodeOptions = babelRegisterOnly.config([nodeFiles]);

babelRegisterOnly([]);

const transformer = require('metro-react-native-babel-transformer');
module.exports = {
  process(src /*: string */, file /*: string */) {
    if (nodeFiles.test(file)) {
      // node specific transforms only
      return babelTransformSync(src, {
        filename: file,
        sourceType: 'script',
        ...nodeOptions,
        ast: false,
      }).code;
    }
github react-native-community / cli / packages / local-cli / util / jestPreprocessor.js View on Github external

'use strict';

/* $FlowFixMe: This is a dependency o Metro Babel Register */
const {transformSync: babelTransformSync} = require('@babel/core');
/* $FlowFixMe(>=0.54.0 site=react_native_oss) This comment suppresses an error
 * found when Flow v0.54 was deployed. To see the error delete this comment and
 * run Flow. */
const babelRegisterOnly = require('metro-babel-register');
/* $FlowFixMe(>=0.54.0 site=react_native_oss) This comment suppresses an error
 * found when Flow v0.54 was deployed. To see the error delete this comment and
 * run Flow. */
const createCacheKeyFunction = require('fbjs-scripts/jest/createCacheKeyFunction');

// Get the default transpile configuration from `metro-babel-register`
const config = babelRegisterOnly.config([]);

module.exports = {
  process(src /*:string */, file /*:string */) {
    return babelTransformSync(src, {
      filename: file,
      sourceType: 'script',
      plugins: config.plugins,
      ast: false,
    });
  },
  getCacheKey: createCacheKeyFunction([
    __filename,
    require.resolve('@babel/core/package.json'),
  ]),
};
github facebook / metro / packages / metro-visualizer / src / middleware / build-utils / transformWorker.js View on Github external
* LICENSE file in the root directory of this source tree.
 *
 * @emails oncall+metro_bundler
 * @format
 */

'use strict';

const babelRegister = require('metro-babel-register');
const path = require('path');

const rootPath = path.resolve(
  path.dirname(require.resolve('metro/package.json')),
  '../../..',
);
babelRegister(babelRegister.buildRegExps(rootPath, ['metro/packages/']));

module.exports = require('metro/src/DeltaBundler/Worker');
github react-native-community / cli / packages / local-cli / util / setupBabel.js View on Github external
function setupBabel() {
  babelRegisterOnly(
    babelRegisterOnly.buildRegExps(__dirname, BABEL_ENABLED_PATHS),
  );
}
github facebook / react-native / setupBabel.js View on Github external
function setupBabel() {
  babelRegisterOnly(
    babelRegisterOnly.buildRegExps(__dirname, BABEL_ENABLED_PATHS),
  );
}

metro-babel-register

🚇 babel/register configuration for Metro.

MIT
Latest version published 29 days ago

Package Health Score

95 / 100
Full package analysis

Similar packages