Skip to content

Commit 49cb3f4

Browse files
Merge pull request #2174 from RedisInsight/build/feature/RI-4265_Enchance_opening_window_Electron
#RI-4265 - Enhance the window opening in Electron
2 parents 46fbb77 + bd76a67 commit 49cb3f4

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

46 files changed

+695
-812
lines changed

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ lerna-debug.log*
3636
.vscode
3737

3838
# App packaged
39+
redisinsight/electron/preload.js
3940
release
4041
main.prod.js
4142
main.prod.js.map
@@ -56,6 +57,9 @@ dll
5657
main.js
5758
main.js.map
5859
vendor
60+
redisinsight/main.js.LICENSE.txt
61+
redisinsight/main.prod.js.LICENSE.txt
62+
5963

6064
# E2E tests report
6165
/tests/e2e/report

configs/paths.js

Lines changed: 0 additions & 17 deletions
This file was deleted.

configs/webpack.config.base.js renamed to configs/webpack.config.base.ts

Lines changed: 18 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
1-
import path from 'path';
21
import webpack from 'webpack';
3-
import TsconfigPathsPlugin from 'tsconfig-paths-webpack-plugin';
2+
import TsconfigPathsPlugins from 'tsconfig-paths-webpack-plugin';
3+
import webpackPaths from './webpack.paths';
44
import { dependencies as externals } from '../redisinsight/package.json';
55

6-
export default {
6+
const configuration: webpack.Configuration = {
77
externals: [...Object.keys(externals || {})],
88

9+
stats: 'errors-only',
10+
911
module: {
1012
rules: [
1113
{
@@ -22,28 +24,27 @@ export default {
2224
},
2325

2426
output: {
25-
path: path.join(__dirname, '..'),
26-
// commonjs2 https://github.com/webpack/webpack/issues/1114
27-
libraryTarget: 'commonjs2',
27+
path: webpackPaths.riPath,
28+
// https://github.com/webpack/webpack/issues/1114
29+
library: {
30+
type: 'commonjs2',
31+
},
2832
},
2933

3034
resolve: {
3135
extensions: ['.js', '.jsx', '.json', '.ts', '.tsx', '.scss'],
32-
plugins: [
33-
new TsconfigPathsPlugin({
34-
configFile: path.join(__dirname, '..', 'tsconfig.json'),
35-
}),
36-
],
36+
modules: [webpackPaths.apiPath, 'node_modules'],
37+
plugins: [new TsconfigPathsPlugins()],
3738
alias: {
38-
src: path.resolve(__dirname, '../redisinsight/api/src'),
39-
apiSrc: path.resolve(__dirname, '../redisinsight/api/src'),
40-
uiSrc: path.resolve(__dirname, '../redisinsight/ui/src'),
39+
src: webpackPaths.apiSrcPath,
40+
apiSrc: webpackPaths.apiSrcPath,
41+
uiSrc: webpackPaths.uiSrcPath,
4142
},
42-
modules: [path.join(__dirname, '../redisinsight/api'), 'node_modules'],
4343
},
4444

4545
plugins: [
4646
new webpack.EnvironmentPlugin({
47+
NODE_ENV: 'production',
4748
}),
4849

4950
new webpack.IgnorePlugin({
@@ -81,3 +82,5 @@ export default {
8182
}),
8283
],
8384
};
85+
86+
export default configuration;

configs/webpack.config.eslint.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@
22
/* eslint import/no-unresolved: off, import/no-self-import: off */
33
require('@babel/register');
44

5-
module.exports = require('./webpack.config.renderer.dev.babel').default;
5+
module.exports = require('./webpack.config.renderer.dev').default;

configs/webpack.config.main.prod.babel.js renamed to configs/webpack.config.main.prod.ts

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
import path from 'path';
22
import webpack from 'webpack';
33
import { merge } from 'webpack-merge';
4-
import { toString } from 'lodash'
54
import { BundleAnalyzerPlugin } from 'webpack-bundle-analyzer';
65
import baseConfig from './webpack.config.base';
76
import DeleteSourceMaps from '../scripts/DeleteSourceMaps';
87
import { version } from '../redisinsight/package.json';
8+
import webpackPaths from './webpack.paths';
99

1010
DeleteSourceMaps();
1111

@@ -23,19 +23,25 @@ export default merge(baseConfig, {
2323

2424
target: 'electron-main',
2525

26-
entry: './redisinsight/main.dev.ts',
26+
entry: {
27+
main: path.join(webpackPaths.electronPath, 'main.dev.ts'),
28+
preload: path.join(webpackPaths.electronPath, 'preload.ts'),
29+
},
2730

2831
resolve: {
2932
alias: {
30-
['apiSrc']: path.resolve(__dirname, '../redisinsight/api/src'),
31-
['src']: path.resolve(__dirname, '../redisinsight/api/src'),
33+
['apiSrc']: webpackPaths.apiSrcPath,
34+
['src']: webpackPaths.apiSrcPath,
3235
},
3336
extensions: ['.tsx', '.ts', '.js', '.jsx'],
3437
},
3538

3639
output: {
37-
path: path.join(__dirname, '../redisinsight'),
38-
filename: 'main.prod.js',
40+
path: webpackPaths.distMainPath,
41+
filename: '[name].js',
42+
library: {
43+
type: 'umd',
44+
},
3945
},
4046

4147
// optimization: {
@@ -46,10 +52,6 @@ export default merge(baseConfig, {
4652
// ],
4753
// },
4854

49-
// alias: {
50-
// 'apiSrc': path.resolve(__dirname, '../redisinsight/api/src/')
51-
// },
52-
5355
plugins: [
5456
new BundleAnalyzerPlugin({
5557
analyzerMode: process.env.OPEN_ANALYZER === 'true' ? 'server' : 'disabled',
@@ -71,9 +73,10 @@ export default merge(baseConfig, {
7173
APP_VERSION: version,
7274
AWS_BUCKET_NAME: 'AWS_BUCKET_NAME' in process.env ? process.env.AWS_BUCKET_NAME : '',
7375
SEGMENT_WRITE_KEY: 'SEGMENT_WRITE_KEY' in process.env ? process.env.SEGMENT_WRITE_KEY : 'SOURCE_WRITE_KEY',
74-
CONNECTIONS_TIMEOUT_DEFAULT: 'CONNECTIONS_TIMEOUT_DEFAULT' in process.env
75-
? process.env.CONNECTIONS_TIMEOUT_DEFAULT
76-
: toString(30 * 1000), // 30 sec
76+
}),
77+
78+
new webpack.DefinePlugin({
79+
'process.type': '"browser"',
7780
}),
7881
],
7982

configs/webpack.config.main.stage.babel.js renamed to configs/webpack.config.main.stage.ts

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
import webpack from 'webpack';
22
import { merge } from 'webpack-merge';
33
import { BundleAnalyzerPlugin } from 'webpack-bundle-analyzer';
4-
import { toString } from 'lodash'
5-
import mainProdConfig from './webpack.config.main.prod.babel';
4+
import mainProdConfig from './webpack.config.main.prod';
65
import DeleteSourceMaps from '../scripts/DeleteSourceMaps';
76
import { version } from '../redisinsight/package.json';
87

@@ -31,9 +30,6 @@ export default merge(mainProdConfig, {
3130
APP_VERSION: version,
3231
AWS_BUCKET_NAME: 'AWS_BUCKET_NAME' in process.env ? process.env.AWS_BUCKET_NAME : '',
3332
SEGMENT_WRITE_KEY: 'SEGMENT_WRITE_KEY' in process.env ? process.env.SEGMENT_WRITE_KEY : 'SOURCE_WRITE_KEY',
34-
CONNECTIONS_TIMEOUT_DEFAULT: 'CONNECTIONS_TIMEOUT_DEFAULT' in process.env
35-
? process.env.CONNECTIONS_TIMEOUT_DEFAULT
36-
: toString(30 * 1000), // 30 sec
3733
}),
3834
],
3935
});
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
import path from 'path';
2+
import webpack from 'webpack';
3+
import { merge } from 'webpack-merge';
4+
import { BundleAnalyzerPlugin } from 'webpack-bundle-analyzer';
5+
import baseConfig from './webpack.config.base';
6+
import webpackPaths from './webpack.paths';
7+
8+
const configuration: webpack.Configuration = {
9+
devtool: 'inline-source-map',
10+
11+
mode: 'development',
12+
13+
target: 'electron-preload',
14+
15+
entry: path.join(webpackPaths.electronPath, 'preload.ts'),
16+
17+
output: {
18+
path: webpackPaths.dllPath,
19+
filename: 'preload.js',
20+
library: {
21+
type: 'umd',
22+
},
23+
},
24+
25+
plugins: [
26+
new BundleAnalyzerPlugin({
27+
analyzerMode: process.env.ANALYZE === 'true' ? 'server' : 'disabled',
28+
}),
29+
30+
/**
31+
* Create global constants which can be configured at compile time.
32+
*
33+
* Useful for allowing different behaviour between development builds and
34+
* release builds
35+
*
36+
* NODE_ENV should be production so that modules do not perform certain
37+
* development checks
38+
*
39+
* By default, use 'development' as NODE_ENV. This can be overriden with
40+
* 'staging', for example, by changing the ENV variables in the npm scripts
41+
*/
42+
new webpack.EnvironmentPlugin({
43+
NODE_ENV: 'development',
44+
}),
45+
46+
new webpack.LoaderOptionsPlugin({
47+
debug: true,
48+
}),
49+
],
50+
51+
/**
52+
* Disables webpack processing of __dirname and __filename.
53+
* If you run the bundle in node.js it falls back to these values of node.js.
54+
* https://github.com/webpack/webpack/issues/2010
55+
*/
56+
node: {
57+
__dirname: false,
58+
__filename: false,
59+
},
60+
61+
watch: true,
62+
};
63+
64+
export default merge(baseConfig, configuration);
Lines changed: 10 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
11
import webpack from 'webpack';
22
import path from 'path';
33
import { merge } from 'webpack-merge';
4-
import { toString } from 'lodash'
54
import baseConfig from './webpack.config.base';
5+
import webpackPaths from './webpack.paths';
66
import { dependencies } from '../package.json';
77
import { dependencies as dependenciesApi } from '../redisinsight/package.json';
88

99
console.log('dependenciesApi', dependenciesApi);
1010

11-
const dist = path.join(__dirname, '../dll');
11+
const dist = webpackPaths.dllPath;
1212

1313
export default merge(baseConfig, {
14-
context: path.join(__dirname, '..'),
14+
context: webpackPaths.rootPath,
1515

1616
devtool: 'eval',
1717

@@ -24,17 +24,19 @@ export default merge(baseConfig, {
2424
/**
2525
* Use `module` from `webpack.config.renderer.dev.js`
2626
*/
27-
module: require('./webpack.config.renderer.dev.babel').default.module,
27+
module: require('./webpack.config.renderer.dev').default.module,
2828

2929
entry: {
3030
renderer: [...Object.keys(dependencies || {}), ...Object.keys(dependenciesApi || {})],
3131
},
3232

3333
output: {
34-
library: 'renderer',
3534
path: dist,
3635
filename: '[name].dev.dll.js',
37-
libraryTarget: 'var',
36+
library: {
37+
name: 'renderer',
38+
type: 'var',
39+
},
3840
},
3941

4042
stats: 'errors-only',
@@ -47,29 +49,16 @@ export default merge(baseConfig, {
4749

4850
new webpack.EnvironmentPlugin({
4951
NODE_ENV: 'development',
50-
APP_ENV: 'electron',
51-
API_PREFIX: 'api',
52-
BASE_API_URL: 'http://localhost',
53-
RESOURCES_BASE_URL: 'http://localhost',
54-
SCAN_COUNT_DEFAULT: '500',
55-
SCAN_TREE_COUNT_DEFAULT: '10000',
56-
PIPELINE_COUNT_DEFAULT: '5',
57-
SEGMENT_WRITE_KEY:
58-
'SEGMENT_WRITE_KEY' in process.env ? process.env.SEGMENT_WRITE_KEY : 'SOURCE_WRITE_KEY',
59-
CONNECTIONS_TIMEOUT_DEFAULT: 'CONNECTIONS_TIMEOUT_DEFAULT' in process.env
60-
? process.env.CONNECTIONS_TIMEOUT_DEFAULT
61-
: toString(30 * 1000), // 30 sec
6252
}),
6353

6454
new webpack.LoaderOptionsPlugin({
6555
debug: true,
6656
options: {
67-
context: path.join(__dirname, '..'),
57+
context: webpackPaths.electronPath,
6858
output: {
69-
path: path.join(__dirname, '../dll'),
59+
path: webpackPaths.dllPath,
7060
},
7161
},
7262
}),
73-
7463
],
7564
});

0 commit comments

Comments
 (0)