lbry-desktop/webpack.electron-main.config.js

88 lines
2.2 KiB
JavaScript
Raw Normal View History

const config = require('./config');
2019-03-05 05:46:57 +01:00
const path = require('path');
2019-03-13 07:52:14 +01:00
const webpack = require('webpack');
2019-03-05 05:46:57 +01:00
const merge = require('webpack-merge');
const baseConfig = require('./webpack.base.config.js');
const CopyWebpackPlugin = require('copy-webpack-plugin');
2019-09-26 17:06:01 +02:00
const { DefinePlugin, ProvidePlugin } = require('webpack');
2019-03-28 17:53:13 +01:00
const { getIfUtils, removeEmpty } = require('webpack-config-utils');
2019-03-05 05:46:57 +01:00
const STATIC_ROOT = path.resolve(__dirname, 'static/');
const DIST_ROOT = path.resolve(__dirname, 'dist/');
2019-03-28 17:53:13 +01:00
const NODE_ENV = process.env.NODE_ENV || 'development';
const { ifProduction } = getIfUtils(NODE_ENV);
2019-03-05 05:46:57 +01:00
2019-03-15 20:37:51 +01:00
let mainConfig = {
2019-03-05 07:24:03 +01:00
target: 'electron-main',
2019-03-05 05:46:57 +01:00
entry: {
2019-11-07 20:39:22 +01:00
main: './electron/index.js',
2019-03-05 07:24:03 +01:00
},
output: {
2019-03-05 08:47:55 +01:00
filename: '[name].js',
2019-03-15 19:58:42 +01:00
path: __dirname + '/dist/electron/webpack',
2019-03-05 07:24:03 +01:00
},
module: {
rules: [
{
2019-03-29 15:23:32 +01:00
test: /\.(jsx?$|s?css$)/,
2019-03-05 07:24:03 +01:00
use: [
{
loader: 'preprocess-loader',
options: {
TARGET: 'app',
ppOptions: {
type: 'js',
},
},
},
],
},
],
},
plugins: [
new CopyWebpackPlugin([
{
from: `${STATIC_ROOT}/`,
to: `${DIST_ROOT}/electron/static/`,
ignore: ['index-web.html', 'index-electron.html', 'daemon/**/*', 'lbry-first/**/*'],
2019-03-28 17:53:13 +01:00
},
{
from: `${STATIC_ROOT}/index-electron.html`,
2019-09-03 05:01:04 +02:00
to: `${DIST_ROOT}/electron/static/index.html`,
2019-03-05 07:24:03 +01:00
},
2019-12-19 19:42:36 +01:00
{
from: `${STATIC_ROOT}/daemon`,
to: `${DIST_ROOT}/electron/daemon`,
},
{
from: `${STATIC_ROOT}/lbry-first`,
to: `${DIST_ROOT}/electron/lbry-first`,
},
2019-03-05 07:24:03 +01:00
]),
],
};
2019-03-15 20:37:51 +01:00
if (process.env.NODE_ENV === 'production') {
// Apply prod overrides
mainConfig = merge(mainConfig, {
externals: {
2019-03-15 23:09:14 +01:00
electron: 'require("electron")',
2019-03-19 04:33:46 +01:00
express: 'require("express")',
'electron-updater': 'require("electron-updater")',
2019-03-15 20:37:51 +01:00
},
});
} else {
const nodeExternals = require('webpack-node-externals');
// Apply dev overrides
mainConfig = merge(mainConfig, {
2019-03-16 04:44:02 +01:00
externals: {
electron: 'require("electron")',
2019-03-19 04:33:46 +01:00
express: 'require("express")',
'electron-updater': 'require("electron-updater")',
2019-03-16 04:44:02 +01:00
},
2019-03-15 20:37:51 +01:00
});
}
2020-11-12 22:12:25 +01:00
module.exports = merge(baseConfig, mainConfig);