久久久久久久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 服務器時的歡迎消息)
主站蜘蛛池模板: 中文字幕免费 | 国产日韩欧美综合 | 久久久久久免费毛片精品 | 91视频在线看 | 色婷婷亚洲一区二区三区 | 最新一级毛片 | 亚洲一区二区三区免费观看 | 久久69精品久久久久久国产越南 | 亚洲国产精品一区二区三区 | 91福利电影在线观看 | 精品视频亚洲 | 中文字幕日韩专区 | 一区二区三区精品视频 | 久久国产精品免费一区二区三区 | 羞羞视频在线观免费观看 | 精品在线一区 | 日韩一区二区在线视频 | 国产视频中文字幕在线观看 | 一区二区三区视频在线观看 | 91麻豆精品国产91久久久久久 | 久久av.com | 久久99精品久久久 | 日韩精品 电影一区 亚洲 | 久久久激情 | 成人影视网址 | 国产成人免费视频网站高清观看视频 | 国产成人99久久亚洲综合精品 | 精品免费视频 | 免费视频99 | 久久不卡 | 精品福利在线 | 成人欧美一区二区 | 欧美精品欧美精品系列 | 成人午夜电影在线观看 | 日本精品一区二区三区视频 | 久久69精品久久久久久久电影好 | 日韩视频区 | 成人在线精品视频 | 亚洲高清av在线 | 亚洲视频免费在线观看 | 免费午夜视频 |