[英]How to use xterm.js with Meteor
I'm trying to user xterm.js in my Meteor app and I can't make it works because I got Terminal is not defined
. 我正在尝试在Meteor应用程序中使用xterm.js ,但由于
Terminal is not defined
。
I use xterm like this in my client's main.html: 我在客户的main.html中使用xterm这样:
<script src="../imports/ui/xterm.js"></script>
<div id="terminal"></div>
<script>
var term = new Terminal();
term.open(document.getElementById('#terminal'));
term.write('Hello from \033[1;3;31mxterm.js\033[0m $ ')
</script>
And xterm is imported because if I take a look in the terminal I can see: xterm是导入的,因为如果在终端中查看,我会看到:
Someone has already used xterm.js with Meteor and could put me on the right track ? 有人已经将xterm.js与Meteor结合使用,可以让我走上正确的轨道吗?
It will not work this way. 它不会以这种方式工作。 You need to import the file in your
client/main.js
file and use its function after: 您需要将文件导入到
client/main.js
文件中,并在之后使用其功能:
client/main.js: 客户端/ main.js:
import '../imports/ui/xterm.js';
Meteor.startup(() => {
var term = new Terminal();
term.open(document.getElementById('#terminal'));
term.write('Hello from \033[1;3;31mxterm.js\033[0m $ ')
});
Remember to remove the two script tag in main.html
file. 记住要删除
main.html
文件中的两个脚本标签。
Update : if it still does not work, then let move the xterm.js
file to client/compatibility/xterm.js
and remove the import
statement in the code above. 更新 :如果仍然无法正常工作,则将
xterm.js
文件移至client/compatibility/xterm.js
并删除上面代码中的import
语句。
This doesn't answer the question here with meteor! 这没有用流星回答这个问题! But it's an add for those who landed here working on an Electron app or a workflow that doesn't support the ES6 import statement.
但这对于那些在这里使用Electron应用程序或不支持ES6 import语句的工作流的人员来说是一个补充。 Node at version 8 and early 9 don't support yet ES6 import statement!
版本8和早期9的节点尚不支持ES6导入声明! if you are in such a situation!
如果您处于这种情况下! Here how you should do to import it:
在这里,您应该如何导入它:
//importing xterm (because node don't support import {Terminal} from 'xterm';)
const xterm = require('xterm');
var Terminal = xterm.Terminal;
it go in two steps! 它分两步走! you require first xterm.
您需要第一个xterm。 then you get a reference to Terminal class.
然后您获得对Terminal类的引用。
Hope it help! 希望对您有所帮助!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.