How to set npm start for electron app with “babel-node --presets es2015,stage-3”

落爺英雄遲暮 提交于 2019-12-11 16:42:36

问题


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"
  }

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"
}

Which gave me a TypeError for using import.

Also tried this:

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

This ended up doing nothing...

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

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?


回答1:


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 ."
  }


来源:https://stackoverflow.com/questions/46014152/how-to-set-npm-start-for-electron-app-with-babel-node-presets-es2015-stage-3

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!