How to use the babel-core.transformFile function in babel-core

To help you get started, we’ve selected a few babel-core 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 ant-ife / apfe-cli / src / lib / compose-apps / utils.js View on Github external
return new Promise((resolve, reject) => {
    babel.transformFile(file, {
      ...options,
      babelrc: false, // Keep the file origin smell
    }, function (err, result) {
      if (err) {
        if (err.loc) {
          console.log(`${file} syntax error:`)
          console.log(codeFrame(readFileSync(file, 'utf8'), err.loc.line, err.loc.column))
        }
        reject(err)
        return
      }
      writeFileSync(file, result.code)
      try {
        beautifulFile(file)
      } catch (err) {
github wdfe / weweb / lib / util.js View on Github external
function loadJavascript (full_path, useBabel, cb) {
  if (useBabel && useBabel != '0') {
    // console.log('useBabel:true',useBabel)
    babel.transformFile(
      full_path,
      {
        presets: ['babel-preset-env', 'babel-preset-stage-0'].map(
          require.resolve
        ),
        sourceMaps: !inProd,
        sourceRoot: process.cwd(),
        sourceFileName: full_path,
        babelrc: false,
        ast: false,
        resolveModuleSource: false
      },
      function (err, result) {
        if (err) return cb(err)
        if (inProd) {
          result.code = UglifyJS.minify(result.code, { fromString: true }).code
github apicase / core / build.js View on Github external
files.forEach(function(filename) {
      // Temporarily removed index.js from cjs
      babel.transformFile('./lib/' + filename, esConfig, function(err, res) {
        if (err) throw err
        fs.writeFile('./es/' + filename, res.code, function(err) {
          if (err) throw err
        })
      })
      babel.transformFile('./lib/' + filename, cjsConfig, function(err, res) {
        if (err) throw err
        fs.writeFile('./cjs/' + filename, res.code, function(err) {
          if (err) throw err
        })
      })
    })
  })
github SteveSanderson / generator-ko / app / templates / _gulpfile.js View on Github external
function babelTranspile(pathname, callback) {
    if (babelIgnoreRegexes.some(function (re) { return re.test(pathname); })) return callback();
    if (!babelCore.canCompile(pathname)) return callback();
    var src  = path.join(transpilationConfig.root, pathname);
    var opts = objectAssign({ sourceFileName: '/source/' + pathname }, transpilationConfig.babelConfig);
    babelCore.transformFile(src, opts, callback);
}
github SaulDoesCode / Crafter.js / build.js View on Github external
function BabelizeBeautifyMinify(inloc, outloc) {

    babel.transformFile(inloc, BabelOptions, (err, result) => {
        if (err) throw err;
        let beautifiedCode = beautify(result.code, {
            indent_size: 2
        });
        fs.writeFile(outloc, beautifiedCode, 'utf8', err => {
            if (err) throw err;
            console.log('Success -> Crafter.js Babelized!\n');

            minjs(outloc).then(out => {
                fs.writeFile(outloc.replace('.js', '.min.js'), out, 'utf8', err => {
                    if (err) throw err;
                    console.log('Success -> Crafter.js Babelized and Minified!\n')
                })
            });

        });
github cs-education / sysbuild / webapp / gulp-tasks / babel-transpiler.js View on Github external
transpile(pathname, callback) {
        pathname = slash(pathname);
        if (this.config.babelIgnoreRegexes.some((re) => re.test(pathname))) return callback();
        if (!babelCore.canCompile(pathname)) return callback();
        const src = path.join(this.config.root, pathname);
        const opts = objectAssign({ sourceFileName: '/source/' + pathname }, this.config.babelConfig);
        babelCore.transformFile(src, opts, callback);
    }
github plasma-umass / Stopify / stopify-continuations / src / common / cleanupGlobals.ts View on Github external
function main() {
  const filename = process.argv[2];
  const opts = { plugins: [() => ({ visitor })], babelrc: false };
  babel.transformFile(filename, opts, (err, result) => {
    if (err !== null) {
      throw err;
    }
    console.log(result.code);
  });
}
github misterfresh / react-without-webpack / middleware / file / transpile.js View on Github external
return new Promise((resolve, reject) => {
    babel.transformFile(file, conf, function(err, transpiled) {
      if (err) {
        reject(err)
      } else {
        resolve(transpiled.code)
      }
    })
  })
}
github zeit / next.js / server / build / transpile.js View on Github external
const code = await new Promise((resolve, reject) => {
    transformFile(src, babelOptions, (err, result) => {
      if (err) return reject(err)
      resolve(result.code)
    })
  })