简体   繁体   中英

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

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?

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM