app/config/webpack.config.main.js

74 lines
1.9 KiB
JavaScript
Raw Permalink Normal View History

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-10-03 17:20:12 +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 = {
2018-10-03 17:20:12 +00:00
index: root('src', 'electron', 'main.ts')
2018-08-14 12:26:23 +00:00
};
config.output = {
path: PROD ? root('build', 'dist') : root('build', 'dev'),
filename: '[name].js',
2018-10-03 17:20:12 +00:00
sourceMapFilename: '[file].map'
2018-08-14 12:26:23 +00:00
};
2018-08-16 10:49:37 +00:00
config.resolve = {
extensions: ['.ts', '.tsx', '.mjs', '.js'],
2018-10-03 17:20:12 +00:00
modules: [root(), 'node_modules']
};
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-08-15 11:14:23 +00:00
new webpack.DefinePlugin(
Object.assign({}, replacements, {
2018-10-03 17:20:12 +00:00
__PROCESS_KIND__: JSON.stringify('main')
2018-08-15 11:14:23 +00:00
})
),
2018-10-03 17:20:12 +00:00
PROD
? null
: new ElectronConnectWebpackPlugin({
path: root('build', 'dev'),
stopOnClose: true,
logLevel: 0
})
2018-08-14 12:26:23 +00:00
].filter(plugin => plugin !== null);
return config;
2018-10-03 17:20:12 +00:00
})();