Autodetect electron version for @babel/preset-env

This commit is contained in:
Christopher Willis-Ford 2019-01-08 14:35:50 -08:00
parent 530857a99b
commit 05bc41389f

View file

@ -1,8 +1,14 @@
const childProcess = require('child_process');
const electronPath = require('electron');
const webpack = require('webpack'); const webpack = require('webpack');
const UglifyJsPlugin = require('uglifyjs-webpack-plugin'); const UglifyJsPlugin = require('uglifyjs-webpack-plugin');
const isProduction = (process.env.NODE_ENV === 'production'); const isProduction = (process.env.NODE_ENV === 'production');
const electronVersion = childProcess.execSync(`${electronPath} --version`, {encoding: 'utf8'}).trim();
console.log(`Targeting Electron ${electronVersion}`);
const makeConfig = function (options) { const makeConfig = function (options) {
// eslint-disable-next-line no-console // eslint-disable-next-line no-console
console.log(`Module "${options.name}" building in production mode? ${isProduction}`); console.log(`Module "${options.name}" building in production mode? ${isProduction}`);
@ -16,7 +22,7 @@ const makeConfig = function (options) {
'@babel/plugin-proposal-object-rest-spread' '@babel/plugin-proposal-object-rest-spread'
], ],
presets: [ presets: [
['@babel/preset-env', {targets: {electron: '3.0.13'}}] ['@babel/preset-env', {targets: {electron: electronVersion}}]
] ]
}; };