2018-08-14 12:26:23 +00:00
|
|
|
const path = require('path');
|
|
|
|
const webpack = require('webpack');
|
2018-10-02 01:32:32 +00:00
|
|
|
const CopyWebpackPlugin = require('copy-webpack-plugin');
|
2018-10-02 08:54:45 +00:00
|
|
|
|
2018-08-14 12:26:23 +00:00
|
|
|
const ElectronConnectWebpackPlugin = require('electron-connect-webpack-plugin');
|
|
|
|
const nodeExternals = require('webpack-node-externals');
|
|
|
|
|
|
|
|
const { hasProcessFlag, root } = require('./helpers.js');
|
2018-08-15 11:14:23 +00:00
|
|
|
const { getReplacements } = require('./app-info');
|
|
|
|
|
|
|
|
const replacements = getReplacements();
|
2018-08-14 12:26:23 +00:00
|
|
|
|
|
|
|
const EVENT = process.env.npm_lifecycle_event || '';
|
|
|
|
const PROD = EVENT.includes('prod');
|
|
|
|
|
|
|
|
|
2018-08-15 11:14:23 +00:00
|
|
|
module.exports = function () {
|
2018-08-14 12:26:23 +00:00
|
|
|
const tsConfigBase = './src/tsconfig.electron.json';
|
|
|
|
|
|
|
|
const atlConfig = {
|
|
|
|
configFileName: tsConfigBase
|
|
|
|
};
|
|
|
|
|
|
|
|
let config = Object.assign({});
|
|
|
|
config.target = 'electron-main';
|
|
|
|
config.mode = PROD ? 'production' : 'development';
|
2018-09-27 09:44:56 +00:00
|
|
|
config.devtool = PROD ? false : 'cheap-module-source-map';
|
2018-08-14 12:26:23 +00:00
|
|
|
config.externals = [nodeExternals()];
|
|
|
|
config.entry = {
|
|
|
|
'index': root('src', 'electron', 'main.ts')
|
|
|
|
};
|
|
|
|
config.output = {
|
|
|
|
path: PROD ? root('build', 'dist') : root('build', 'dev'),
|
|
|
|
filename: '[name].js',
|
|
|
|
sourceMapFilename: '[file].map',
|
|
|
|
};
|
2018-08-16 10:49:37 +00:00
|
|
|
config.resolve = {
|
|
|
|
extensions: ['.ts', '.tsx', '.mjs', '.js'],
|
|
|
|
modules: [
|
|
|
|
root(),
|
2018-10-02 08:54:45 +00:00
|
|
|
'node_modules',
|
2018-08-16 10:49:37 +00:00
|
|
|
],
|
|
|
|
}
|
2018-08-14 12:26:23 +00:00
|
|
|
config.module = {
|
|
|
|
rules: [
|
|
|
|
{
|
|
|
|
test: /\.ts$/,
|
|
|
|
loader: 'awesome-typescript-loader?' + JSON.stringify(atlConfig)
|
|
|
|
},
|
|
|
|
{
|
|
|
|
test: /\.json$/,
|
|
|
|
loader: 'json-loader'
|
|
|
|
}
|
|
|
|
]
|
|
|
|
};
|
|
|
|
config.node = {
|
|
|
|
__dirname: false,
|
|
|
|
__filename: false
|
|
|
|
};
|
|
|
|
config.plugins = [
|
|
|
|
PROD ? new webpack.NoEmitOnErrorsPlugin() : null,
|
2018-10-02 08:54:45 +00:00
|
|
|
// PROD ? new CopyWebpackPlugin(
|
|
|
|
// [
|
|
|
|
// 'config/package.json'
|
|
|
|
// ]
|
|
|
|
// ) : null,
|
2018-08-15 11:14:23 +00:00
|
|
|
new webpack.DefinePlugin(
|
|
|
|
Object.assign({}, replacements, {
|
|
|
|
__PROCESS_KIND__: JSON.stringify('main'),
|
|
|
|
})
|
|
|
|
),
|
2018-09-27 07:57:49 +00:00
|
|
|
PROD ? null : new ElectronConnectWebpackPlugin({
|
2018-08-14 12:26:23 +00:00
|
|
|
path: root('build', 'dev'),
|
|
|
|
stopOnClose: true,
|
|
|
|
logLevel: 0
|
|
|
|
})
|
|
|
|
].filter(plugin => plugin !== null);
|
|
|
|
|
|
|
|
return config;
|
|
|
|
|
|
|
|
}();
|