2018-03-07 14:28:48 +01:00
|
|
|
'use strict'
|
|
|
|
|
|
|
|
process.env.BABEL_ENV = 'main'
|
|
|
|
|
|
|
|
const path = require('path')
|
|
|
|
const { dependencies } = require('../package.json')
|
|
|
|
const webpack = require('webpack')
|
|
|
|
|
2018-08-14 17:46:48 +02:00
|
|
|
const CopyWebpackPlugin = require('copy-webpack-plugin')
|
2018-07-27 14:59:44 +02:00
|
|
|
const MinifyPlugin = require('babel-minify-webpack-plugin')
|
2018-03-07 14:28:48 +01:00
|
|
|
|
|
|
|
let mainConfig = {
|
|
|
|
entry: {
|
|
|
|
main: path.join(__dirname, '../src/main/index.js')
|
|
|
|
},
|
|
|
|
externals: [
|
|
|
|
...Object.keys(dependencies || {})
|
|
|
|
],
|
|
|
|
module: {
|
|
|
|
rules: [
|
|
|
|
{
|
|
|
|
test: /\.(js)$/,
|
|
|
|
enforce: 'pre',
|
|
|
|
exclude: /node_modules/,
|
|
|
|
use: {
|
|
|
|
loader: 'eslint-loader',
|
|
|
|
options: {
|
|
|
|
formatter: require('eslint-friendly-formatter')
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
2019-03-20 16:07:21 +01:00
|
|
|
{
|
|
|
|
test: /\.ts$/,
|
|
|
|
exclude: /node_modules/,
|
|
|
|
loader: 'ts-loader'
|
|
|
|
},
|
2018-03-07 14:28:48 +01:00
|
|
|
{
|
|
|
|
test: /\.js$/,
|
|
|
|
use: 'babel-loader',
|
|
|
|
exclude: /node_modules/
|
|
|
|
},
|
|
|
|
{
|
|
|
|
test: /\.node$/,
|
|
|
|
use: 'node-loader'
|
|
|
|
}
|
|
|
|
]
|
|
|
|
},
|
|
|
|
node: {
|
|
|
|
__dirname: process.env.NODE_ENV !== 'production',
|
|
|
|
__filename: process.env.NODE_ENV !== 'production'
|
|
|
|
},
|
|
|
|
output: {
|
|
|
|
filename: '[name].js',
|
|
|
|
libraryTarget: 'commonjs2',
|
|
|
|
path: path.join(__dirname, '../dist/electron')
|
|
|
|
},
|
|
|
|
plugins: [
|
2018-08-14 17:46:48 +02:00
|
|
|
new webpack.NoEmitOnErrorsPlugin(),
|
|
|
|
new CopyWebpackPlugin([
|
|
|
|
{
|
|
|
|
from: path.join(__dirname, '../src/config/locales'),
|
|
|
|
to: path.join(__dirname, '../dist/electron/locales'),
|
|
|
|
ignore: ['.*', '*~']
|
|
|
|
}
|
|
|
|
])
|
2018-03-07 14:28:48 +01:00
|
|
|
],
|
|
|
|
resolve: {
|
2019-03-20 16:07:21 +01:00
|
|
|
extensions: ['.js', '.json', '.node', '.ts']
|
2018-03-07 14:28:48 +01:00
|
|
|
},
|
|
|
|
target: 'electron-main'
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Adjust mainConfig for development settings
|
|
|
|
*/
|
|
|
|
if (process.env.NODE_ENV !== 'production') {
|
|
|
|
mainConfig.plugins.push(
|
|
|
|
new webpack.DefinePlugin({
|
|
|
|
'__static': `"${path.join(__dirname, '../static').replace(/\\/g, '\\\\')}"`
|
|
|
|
})
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Adjust mainConfig for production settings
|
|
|
|
*/
|
|
|
|
if (process.env.NODE_ENV === 'production') {
|
|
|
|
mainConfig.plugins.push(
|
2018-07-27 14:59:44 +02:00
|
|
|
new MinifyPlugin(),
|
2018-03-07 14:28:48 +01:00
|
|
|
new webpack.DefinePlugin({
|
|
|
|
'process.env.NODE_ENV': '"production"'
|
|
|
|
})
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
module.exports = mainConfig
|