Ale*_*nts 4 javascript node.js nashorn reactjs babeljs
我试图用babel.transform而不是JSXTranformer反应.
...
ScriptEngineManager mgr = new ScriptEngineManager();
ScriptEngine nashorn = mgr.getEngineByName("nashorn");
nashorn.eval("var process = {env:{}}"); // node-modules expect that
nashorn.eval(getScript("com/facebook/babel/jvm-npm.js"));
babel = (JSObject) nashorn.eval("require('babel');");
...
Run Code Online (Sandbox Code Playgroud)
Babel和babel-core安装为全局节点模块,我有一个错误:
Testsuite:com.my.app.BabelTransformerTest
找不到模块./lib/api/node.js
无法加载模块babel-core LOAD_ERROR
无法加载模块babel LOAD_ERROR
无法加载模块babel-core LOAD_ERROR
无法加载模块babel LOAD_ERROR
无法找到模块./ lib/api/node.js
无法加载模块babel-core LOAD_ERROR
无法加载模块babel LOAD_ERROR
该./lib/api/node.js中有C:\Users\***\AppData\Roaming\npm\node_modules
我听说有可能babel.transform从Nashorn出发吗?
也许有办法只加载某个babel模块作为JavaScript文件?
我使用以下脚本在jdk1.8.0_45中使用Babel Standalone:
FileReader babelScript = new FileReader("babel.js");
ScriptEngine engine = new ScriptEngineManager().getEngineByMimeType("text/javascript");
SimpleBindings bindings = new SimpleBindings();
engine.eval(babelScript, bindings);
bindings.put("input", "<Component />");
Object output = engine.eval("Babel.transform(input, { presets: ['react'] }).code", bindings);
System.out.println(output);
Run Code Online (Sandbox Code Playgroud)
哪个回报:
React.createElement(Component, null);
Run Code Online (Sandbox Code Playgroud)
es2015预设也可以使用.
| 归档时间: |
|
| 查看次数: |
3156 次 |
| 最近记录: |