Created
January 8, 2016 17:27
-
-
Save nemtsov/c004cdf580407ed19e44 to your computer and use it in GitHub Desktop.
babel-register/lib/node.js improved performance 10x
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function compile(filename) { | |
| var result = undefined; | |
| var cacheKey = filename + ":" + babel.version; | |
| var env = process.env.BABEL_ENV || process.env.NODE_ENV; | |
| if (env) cacheKey += ":" + env; | |
| if (cache) { | |
| var cached = cache[cacheKey]; | |
| if (cached && cached.mtime === mtime(filename)) { | |
| result = cached; | |
| } | |
| } | |
| if (!result) { | |
| var optsManager = new _babelCore.OptionManager(); | |
| optsManager.mergeOptions(_lodashLangCloneDeep2["default"](transformOpts), "base", null, _path2["default"].dirname(filename)); | |
| var opts = optsManager.init({ filename: filename }); | |
| result = babel.transformFileSync(filename, _lodashObjectExtend2["default"](opts, { | |
| // Do not process config files since has already been done with the OptionManager | |
| // calls above and would introduce duplicates. | |
| babelrc: false, | |
| sourceMap: "both", | |
| ast: false | |
| })); | |
| } | |
| if (cache) { | |
| cache[cacheKey] = result; | |
| result.mtime = mtime(filename); | |
| } | |
| maps[filename] = result.map; | |
| return result.code; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment