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