ES6语法导入电子(需要..) [英] ES6 syntax import Electron (require..)

查看:129
本文介绍了ES6语法导入电子(需要..)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

要学习新的ES6语法,我一直在尝试重构一些JS代码。

To learn the new ES6 syntax, I've been trying to refactor some JS code.

我完全被整个导入/导出方法所困惑。

I'm absolutely confused though by the whole import / export methods.

如何将这个要求声明更改为ES6?

How do I change this require statement into ES6?

var remote = require('electron').remote

我已经看到这个答案,但是:


  1. 它不起作用

  2. 它似乎不是很像ES6-sque

任何想法?

推荐答案


我完全不知道导入/导出方法是否混淆。

I'm absolutely confused though by the whole import / export methods.

混合不同的模块系统确实会令人困惑。

Mixing different module systems can indeed be confusing.



  1. 它不工作




const electron = require('electron');
const remote = electron.remote;

与您所拥有的完全一样

var remote = require('electron').remote

如果你的工作,另一个也会。但是,我只会坚持你的。

If yours work, the other will as well. However, I would simply stick with yours.



  1. 很多ES6-sque


谁在乎?节点不支持ES6 导入导出,而且CommonJS模块应该映射到ES6模块并不是很清楚。我建议坚持使用 require ,如果你只是为Node编写。

Who cares? Node doesn't support ES6 imports and exports natively and it's not super clear how CommonJS modules should map to ES6 modules. I recommend to stick with require if you are only writing for Node anyway.

您可以尝试

You could try to do

import electron from 'electron';
const {remote} = electron;

这篇关于ES6语法导入电子(需要..)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆