How to use the transformFileSync function from babel-core

Find comprehensive JavaScript babel-core.transformFileSync code examples handpicked from public code repositorys.

11
12
13
14
15
16
17
18
19
20
if (os.platform() === 'win32') moduleName = moduleName.replace(/\\/gm, '/');
let content = `define("${moduleName}", `;
content += `function(require, module, exports, window,document,frames,self,location,navigator,localStorage,history,Caches,screen,alert,confirm,prompt,fetch,XMLHttpRequest,WebSocket,webkit,WeixinJSCore,Reporter,print,URL,DOMParser,upload,preview,build,showDecryptedInfo,syncMessage,checkProxy,showSystemInfo,openVendor,openToolsLog,showRequestInfo,help,showDebugInfoTable,closeDebug,showDebugInfo,__global,WeixinJSBridge){\n`;

if (projectConfig.setting.es6 && fs.statSync(sourceFile).size / 1024 < 500) {
  content += babel.transformFileSync(sourceFile, {presets: ['babel-preset-env', 'babel-preset-stage-0'].map(require.resolve)}).code;
} else {
  content += fs.readFileSync(path.resolve(sourceFile), {encoding: 'utf8'});
}
content += '\n});';
fork icon446
star icon0
watch icon121

+ 3 other calls in file

42
43
44
45
46
47
48
49
50
51
            var dist = path.normalize(dist +'/'+ src);
            var src = path.normalize(jdf.currentDir +'/'+ src);
    
    if(jdf.config.build.hasCmdLog) console.log('buildES6js---'+ src);
            
    var result = babelCore.transformFileSync(src, options);
            f.write(dist, result.code);

} catch (e) {
    console.log('jdf error [jdf.buildJS.ES6] - ' + src);
fork icon160
star icon614
watch icon56

+ 3 other calls in file

2
3
4
5
6
7
8
9
10
11
12
const babel = require('babel-core');
const jsdom = require('jsdom');
const path = require('path');


before(function(done) {
  const babelResult = babel.transformFileSync(
    path.resolve(__dirname, '..', 'index.js'), {
      presets: ['es2015']
    }
  );
fork icon0
star icon0
watch icon0

3
4
5
6
7
8
9
10
11
12
13
14
15
const jsdom = require('jsdom');
const path = require('path');




before(function(done) {
  const babelResult = babel.transformFileSync(path.resolve(__dirname, '..', 'index.js'), {
    presets: ['env']
  });


  //const src = path.resolve(__dirname, '..', 'index.js');
fork icon0
star icon0
watch icon0

16
17
18
19
20
21
22
23
24
25
26
function include(fn) {
  var options = {
    plugins: ["transform-es2015-modules-commonjs"]
  };


  var code = babel.transformFileSync(fn, options).code;
  fs.writeFileSync("." + fn + "_nodejs.js", code);
  var imp = require("./." + fn + "_nodejs.js");
  fs.unlinkSync("./." + fn + "_nodejs.js");

fork icon0
star icon0
watch icon0

64
65
66
67
68
69
70
71
72
73
        // babel requires an actual object
        options.inputSourceMap = JSON.parse(inputSourceMap.map);
}

// include test file
var transpiled = babel.transformFileSync(testPath, options);
sourceMapCache[testPath] = transpiled.map;
requireFromString(transpiled.code, testPath, {
        appendPaths: module.paths
});
fork icon0
star icon0
watch icon2

+ 3 other calls in file

26
27
28
29
30
31
32
33
34
35

let allMessages = []

compile(glob.sync(tsFiles), options.options)
glob.sync(jsFiles).forEach(file => {
  const stuff = babel.transformFileSync(file, {
    presets: ['env', 'react'],
    plugins: ['react-intl'],
  })
  allMessages = allMessages.concat(stuff.metadata['react-intl'].messages)
fork icon0
star icon0
watch icon4

+ 3 other calls in file