久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

ES6 語法導入 Electron (require..)

ES6 syntax import Electron (require..)(ES6 語法導入 Electron (require..))
本文介紹了ES6 語法導入 Electron (require..)的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

問題描述

為了學習新的 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.

如何將這個 require 語句改成 ES6?

How do I change this require statement into ES6?

var remote = require('electron').remote

我看過這個答案但是:

  1. 它不起作用
  2. 看起來并沒有太多 ES6 風格

有什么想法嗎?

推薦答案

似乎在 Node 6 或 Chrome 51 中 導入都沒有實現,所以 Electron 也不支持它們,根據這篇文章:https://discuss.atom.io/t/does-electron-support-es6/19366/18

It seems imports are not implemented in either Node 6 or Chrome 51 so Electron also does not support them, according to this post: https://discuss.atom.io/t/does-electron-support-es6/19366/18

最后一個電子文檔也不使用導入,它們使用 destructuring 語法:

And also the last electron doc doesn't use imports, they use destructuring syntax:

const { BrowserWindow } = require('electron').remote
// or
const { remote } = require('electron')
const { BrowserWindow } = remote

http://electron.atom.io/docs/api/remote/

但是你可以使用帶有 require 鉤子的 babel:http://babeljs.io/docs/usage/require/

But you can use babel with the require hook: http://babeljs.io/docs/usage/require/

自動編譯每個必需的模塊,以便您可以使用導入.當然,給電子的腳本(需要 babel 的腳本)沒有編譯,所以你需要做一個引導程序:

To be auto compile each required modules so you will be able to use imports. Of course the script given to electron (the one that require babel) is not compiled so you need to make a bootstrap:

// bootwithbabel.js
require("babel-register");
require( process.argv.splice(2) );

在外殼(sh)中:

electron bootwithbabel.js app.es
alias electrones="electron bootwithbabel.js "
electrones coron.es // ^^

然后你可以在你的應用中寫:

Then in your app you can then write:

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

你也可以只導入遠程模塊:

You can also import only the remote module:

import { remote } from 'electron';

但你只能在一個語句中同時導入:

But you can only import both in one statement:

import electron, { remote } from 'electron'

electron.ipcRenderer.on();
let win = new remote.BrowserWindow({width: 800, height: 600});
remote.getGlobal(name)

游樂場

這篇關于ES6 語法導入 Electron (require..)的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!

相關文檔推薦

discord.js v12: How do I await for messages in a DM channel?(discord.js v12:我如何等待 DM 頻道中的消息?)
how to make my bot mention the person who gave that bot command(如何讓我的機器人提及發出該機器人命令的人)
How to fix Must use import to load ES Module discord.js(如何修復必須使用導入來加載 ES 模塊 discord.js)
How to list all members from a specific server?(如何列出來自特定服務器的所有成員?)
Discord bot: Fix ‘FFMPEG not found’(Discord bot:修復“找不到 FFMPEG)
Welcome message when joining discord Server using discord.js(使用 discord.js 加入 discord 服務器時的歡迎消息)
主站蜘蛛池模板: 成人a在线 | 国产综合久久 | 日韩视频精品 | 91视频在线 | 日韩综合在线 | 亚洲精品在| av三级| 久久精品一 | 国产精品视频免费观看 | 国产精品日女人 | 亚洲欧美国产一区二区三区 | 91精品国产综合久久福利软件 | 伊人青青久久 | 国产免费一区二区 | 欧美精品一区二区在线观看 | 亚州综合在线 | 成人在线观看免费视频 | 中文天堂在线一区 | 99热精品在线观看 | 男女羞羞视频大全 | 一区二区电影 | 99精品视频一区二区三区 | 久久视频精品在线 | 国产精品不卡一区 | av免费成人 | www.狠狠操| 黄色一级电影免费观看 | 亚洲视频免费观看 | 国产高清无av久久 | 天天狠狠 | 91精品中文字幕一区二区三区 | 男女视频91 | 99视频在线免费观看 | 久久久久久一区 | 国产精品美女久久久久aⅴ国产馆 | 中文字幕一区二区三区乱码在线 | 国产女人与拘做受免费视频 | 欧洲尺码日本国产精品 | 国产极品粉嫩美女呻吟在线看人 | 福利视频亚洲 | 欧美a√|