How to use the @babel/register function in @babel/register

To help you get started, we’ve selected a few @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 babel / babel / packages / babel-node / src / _babel-node.js View on Github external
envName: program.envName,
  rootMode: program.rootMode,

  // Commander will default the "--no-" arguments to true, but we want to
  // leave them undefined so that @babel/core can handle the
  // default-assignment logic on its own.
  babelrc: program.babelrc === true ? undefined : program.babelrc,
};

for (const key of Object.keys(babelOptions)) {
  if (babelOptions[key] === undefined) {
    delete babelOptions[key];
  }
}

register(babelOptions);

const replPlugin = ({ types: t }) => ({
  visitor: {
    ModuleDeclaration(path) {
      throw path.buildCodeFrameError("Modules aren't supported in the REPL");
    },

    VariableDeclaration(path) {
      if (path.node.kind !== "var") {
        throw path.buildCodeFrameError(
          "Only `var` variables are supported in the REPL",
        );
      }
    },

    Program(path) {
github smooth-code / smooth.js / packages / smooth / src / babel / require.js View on Github external
export default function babelRequire(path) {
  register({ presets: [preset] })
  // eslint-disable-next-line global-require, import/no-dynamic-require
  const mod = require(path)
  revert()
  return mod
}
github sanity-io / sanity / packages / @sanity / server / src / devServer.js View on Github external
export default function getDevServer(config = {}) {
  const staticPath = getStaticBasePath(config)
  const app = getBaseServer(config)
  const webpackConfig = config.webpack || getWebpackDevConfig(config)

  // Serve an empty CSS file for the main stylesheet,
  // as they are injected dynamically in development mode
  app.get(`${staticPath}/css/main.css`, (req, res) => {
    res.set('Content-Type', 'text/css')
    res.send()
  })

  // Use babel-register in order to be able to load things like
  // the document component, which can contain JSX etc
  registerBabel()

  // Apply the dev and hot middlewares to build/serve bundles on the fly
  const compiler = webpack(webpackConfig)
  app.use(
    webpackDevMiddleware(compiler, {
      logLevel: 'silent',
      watchOptions: {
        ignored: /node_modules/
      },
      publicPath: webpackConfig.output.publicPath
    })
  )

  app.use(webpackHotMiddleware(compiler))

  // Expose webpack compiler on server instance
github wintercounter / mhy / src / resources / nodeProcessSetup.js View on Github external
import mhyConfig from '@/configs/mhy'
import babelConfig from '@/configs/babel'
import register from '@babel/register'

babelConfig.presets.find(p => p[0].includes('preset-env'))[1] = {
    modules: 'commonjs',
    targets: {
        node: true,
        browsers: false,
        esmodules: true
    }
}
babelConfig.extensions = ['.es6', '.es', '.jsx', '.js', '.mjs', '.ts', '.tsx']
babelConfig.cache = false

register(babelConfig)
addPath(path.resolve(process.cwd(), 'node_modules'))
addPath(path.resolve(__dirname, '../../node_modules'))

const alias = { ...mhyConfig.defaultAliases }
for (const [key, entry] of Object.entries(alias)) {
    if (!fs.existsSync(entry)) {
        alias[key] = path.resolve(process.cwd(), entry)
    } else {
        // Make sure it's a resolved path indeed
        alias[key] = path.resolve(entry)
    }
}
addAliases(alias)

const scriptKey = '--mhy-script'
const scriptIndex = process.argv.findIndex(v => v.includes(scriptKey))
github intuit / Ignite / src / ignite.js View on Github external
export function initPlugins(options) {
  register();

  options.plugins.forEach(async plugin => {
    let [, pluginPath, pluginOptions] = plugin;
    const pluginPackage = path.join(pluginPath, 'package.json');
    let initFile;

    if (!pluginOptions) {
      pluginOptions = {};
      plugin[2] = pluginOptions;
    }

    try {
      initFile = path.join(pluginPath, require(pluginPackage).init);
    } catch (error) {
      initFile = path.resolve(path.join(pluginPath, 'init.js'));
    }
github sanity-io / sanity / packages / @sanity / core / src / actions / exec / babel.js View on Github external
require.resolve('@babel/preset-react'),
        [
          require.resolve('@babel/preset-env'),
          {
            targets: {
              node: 'current'
            }
          }
        ]
      ],
      plugins: [require.resolve('@babel/plugin-proposal-class-properties')]
    }
  }
}

registerBabel(getConfig())

@babel/register

babel require hook

MIT
Latest version published 4 months ago

Package Health Score

95 / 100
Full package analysis