如何使用"babel-node --presets es2015,stage-3"为电子应用设置npm start; [英] How to set npm start for electron app with "babel-node --presets es2015,stage-3"

查看:205
本文介绍了如何使用"babel-node --presets es2015,stage-3"为电子应用设置npm start;的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试让我的npm start用于电子. 我知道您通常使用electron ../node_modules/.bin/electron .启动未分发/打包的应用程序.由于我一直在使用NodeJS v8.4.0和ES6/7语法,所以我在package.json中最终得到了这个npm start脚本:

I'm trying to get my npm start working for electron. I know that you usually start a not distributed/packed app with electron . or ./node_modules/.bin/electron .. Since I was playing around with NodeJS v8.4.0 together with ES6/7 syntax I did end up with this npm start script in my package.json:

  "scripts": {
    "start": "babel-node main.js --presets es2015,stage-3"
  }

一切正常,例如,我能够使用import而没有任何问题.现在,我想与此脚本一起实时使用电子.我想知道是否有可能?我已经尝试将脚本更改为此:

Everything worked well I was able to use import for example without any issues. Now I want to use electron together on the fly with this script. I was wondering if that is possible anyhow? I already tried to change my script to this:

  "scripts": {
    "start": "./node_modules/.bin/electron . babel-node main.js --presets es2015,stage-3"
}

哪个给了我TypeError以便使用import.

也尝试过这个:

  "scripts": {
    "start": "babel-node main.js ./node_modules/.bin/electron . --presets es2015,stage-3"
  }

这最终什么也不做...

This ended up doing nothing...

在不tried肿这个问题的情况下,我尝试过很多没有运气的改变.

Without bloating this question any further I've tried already changing alot with no luck.

是否可以使用babel-node main.js --presets es2015,stage-3以给定的预设启动电子,以便我可以使用语法而无需使用Gulp来转换我的文件?

Is there any possible way to use babel-node main.js --presets es2015,stage-3 to start electron with the given preset so that I can use my syntax without using Gulp for example to transpile my files?

推荐答案

好的,我已经找到了解决方案. 有一个超级好帮手,叫做电子编译 按照github站点上的说明进行操作后,我可以像这样使用我的npm start:

Alright, I've found a solution. There is a super good helper out there called electron-compile After following the instructions on the github site I can use my npm start like this:

如果电子是本地安装的:

If electron is installed locally:

  "scripts": {
    "start": "./node_modules/.bin/electron ."
  }

如果电子是全局安装的:

If electron is installed globally:

  "scripts": {
    "start": "electron ."
  }

这篇关于如何使用"babel-node --presets es2015,stage-3"为电子应用设置npm start;的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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