Skip to content

Commit 3b509d8

Browse files
committed
switch to electron-react-boilerplate
1 parent a158b2e commit 3b509d8

Some content is hidden

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

64 files changed

+32917
-1573
lines changed

.erb/configs/.eslintrc

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"rules": {
3+
"no-console": "off",
4+
"global-require": "off",
5+
"import/no-dynamic-require": "off"
6+
}
7+
}

.erb/configs/webpack.config.base.ts

+53
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
/**
2+
* Base webpack config used across other specific configs
3+
*/
4+
5+
import webpack from 'webpack';
6+
import webpackPaths from './webpack.paths';
7+
import { dependencies as externals } from '../../release/app/package.json';
8+
9+
const configuration: webpack.Configuration = {
10+
externals: [...Object.keys(externals || {})],
11+
12+
stats: 'errors-only',
13+
14+
module: {
15+
rules: [
16+
{
17+
test: /\.[jt]sx?$/,
18+
exclude: /node_modules/,
19+
use: {
20+
loader: 'ts-loader',
21+
options: {
22+
// Remove this line to enable type checking in webpack builds
23+
transpileOnly: true,
24+
},
25+
},
26+
},
27+
],
28+
},
29+
30+
output: {
31+
path: webpackPaths.srcPath,
32+
// https://github.com/webpack/webpack/issues/1114
33+
library: {
34+
type: 'commonjs2',
35+
},
36+
},
37+
38+
/**
39+
* Determine the array of extensions that should be used to resolve modules.
40+
*/
41+
resolve: {
42+
extensions: ['.js', '.jsx', '.json', '.ts', '.tsx'],
43+
modules: [webpackPaths.srcPath, 'node_modules'],
44+
},
45+
46+
plugins: [
47+
new webpack.EnvironmentPlugin({
48+
NODE_ENV: 'production',
49+
}),
50+
],
51+
};
52+
53+
export default configuration;

.erb/configs/webpack.config.eslint.ts

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
/* eslint import/no-unresolved: off, import/no-self-import: off */
2+
3+
module.exports = require('./webpack.config.renderer.dev').default;
+75
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
/**
2+
* Webpack config for production electron main process
3+
*/
4+
5+
import path from 'path';
6+
import webpack from 'webpack';
7+
import { merge } from 'webpack-merge';
8+
import TerserPlugin from 'terser-webpack-plugin';
9+
import { BundleAnalyzerPlugin } from 'webpack-bundle-analyzer';
10+
import baseConfig from './webpack.config.base';
11+
import webpackPaths from './webpack.paths';
12+
import checkNodeEnv from '../scripts/check-node-env';
13+
import deleteSourceMaps from '../scripts/delete-source-maps';
14+
15+
checkNodeEnv('production');
16+
deleteSourceMaps();
17+
18+
const configuration: webpack.Configuration = {
19+
devtool: 'source-map',
20+
21+
mode: 'production',
22+
23+
target: 'electron-main',
24+
25+
entry: {
26+
main: path.join(webpackPaths.srcMainPath, 'main.ts'),
27+
preload: path.join(webpackPaths.srcMainPath, 'preload.ts'),
28+
},
29+
30+
output: {
31+
path: webpackPaths.distMainPath,
32+
filename: '[name].js',
33+
},
34+
35+
optimization: {
36+
minimizer: [
37+
new TerserPlugin({
38+
parallel: true,
39+
}),
40+
],
41+
},
42+
43+
plugins: [
44+
new BundleAnalyzerPlugin({
45+
analyzerMode: process.env.ANALYZE === 'true' ? 'server' : 'disabled',
46+
}),
47+
48+
/**
49+
* Create global constants which can be configured at compile time.
50+
*
51+
* Useful for allowing different behaviour between development builds and
52+
* release builds
53+
*
54+
* NODE_ENV should be production so that modules do not perform certain
55+
* development checks
56+
*/
57+
new webpack.EnvironmentPlugin({
58+
NODE_ENV: 'production',
59+
DEBUG_PROD: false,
60+
START_MINIMIZED: false,
61+
}),
62+
],
63+
64+
/**
65+
* Disables webpack processing of __dirname and __filename.
66+
* If you run the bundle in node.js it falls back to these values of node.js.
67+
* https://github.com/webpack/webpack/issues/2010
68+
*/
69+
node: {
70+
__dirname: false,
71+
__filename: false,
72+
},
73+
};
74+
75+
export default merge(baseConfig, configuration);
+68
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
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+
import checkNodeEnv from '../scripts/check-node-env';
8+
9+
// When an ESLint server is running, we can't set the NODE_ENV so we'll check if it's
10+
// at the dev webpack config is not accidentally run in a production environment
11+
if (process.env.NODE_ENV === 'production') {
12+
checkNodeEnv('development');
13+
}
14+
15+
const configuration: webpack.Configuration = {
16+
devtool: 'inline-source-map',
17+
18+
mode: 'development',
19+
20+
target: 'electron-preload',
21+
22+
entry: path.join(webpackPaths.srcMainPath, 'preload.ts'),
23+
24+
output: {
25+
path: webpackPaths.dllPath,
26+
filename: 'preload.js',
27+
},
28+
29+
plugins: [
30+
new BundleAnalyzerPlugin({
31+
analyzerMode: process.env.ANALYZE === 'true' ? 'server' : 'disabled',
32+
}),
33+
34+
/**
35+
* Create global constants which can be configured at compile time.
36+
*
37+
* Useful for allowing different behaviour between development builds and
38+
* release builds
39+
*
40+
* NODE_ENV should be production so that modules do not perform certain
41+
* development checks
42+
*
43+
* By default, use 'development' as NODE_ENV. This can be overriden with
44+
* 'staging', for example, by changing the ENV variables in the npm scripts
45+
*/
46+
new webpack.EnvironmentPlugin({
47+
NODE_ENV: 'development',
48+
}),
49+
50+
new webpack.LoaderOptionsPlugin({
51+
debug: true,
52+
}),
53+
],
54+
55+
/**
56+
* Disables webpack processing of __dirname and __filename.
57+
* If you run the bundle in node.js it falls back to these values of node.js.
58+
* https://github.com/webpack/webpack/issues/2010
59+
*/
60+
node: {
61+
__dirname: false,
62+
__filename: false,
63+
},
64+
65+
watch: true,
66+
};
67+
68+
export default merge(baseConfig, configuration);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
/**
2+
* Builds the DLL for development electron renderer process
3+
*/
4+
5+
import webpack from 'webpack';
6+
import path from 'path';
7+
import { merge } from 'webpack-merge';
8+
import baseConfig from './webpack.config.base';
9+
import webpackPaths from './webpack.paths';
10+
import { dependencies } from '../../package.json';
11+
import checkNodeEnv from '../scripts/check-node-env';
12+
13+
checkNodeEnv('development');
14+
15+
const dist = webpackPaths.dllPath;
16+
17+
const configuration: webpack.Configuration = {
18+
context: webpackPaths.rootPath,
19+
20+
devtool: 'eval',
21+
22+
mode: 'development',
23+
24+
target: 'electron-renderer',
25+
26+
externals: ['fsevents', 'crypto-browserify'],
27+
28+
/**
29+
* Use `module` from `webpack.config.renderer.dev.js`
30+
*/
31+
module: require('./webpack.config.renderer.dev').default.module,
32+
33+
entry: {
34+
renderer: Object.keys(dependencies || {}),
35+
},
36+
37+
output: {
38+
path: dist,
39+
filename: '[name].dev.dll.js',
40+
library: {
41+
name: 'renderer',
42+
type: 'var',
43+
},
44+
},
45+
46+
plugins: [
47+
new webpack.DllPlugin({
48+
path: path.join(dist, '[name].json'),
49+
name: '[name]',
50+
}),
51+
52+
/**
53+
* Create global constants which can be configured at compile time.
54+
*
55+
* Useful for allowing different behaviour between development builds and
56+
* release builds
57+
*
58+
* NODE_ENV should be production so that modules do not perform certain
59+
* development checks
60+
*/
61+
new webpack.EnvironmentPlugin({
62+
NODE_ENV: 'development',
63+
}),
64+
65+
new webpack.LoaderOptionsPlugin({
66+
debug: true,
67+
options: {
68+
context: webpackPaths.srcPath,
69+
output: {
70+
path: webpackPaths.dllPath,
71+
},
72+
},
73+
}),
74+
],
75+
};
76+
77+
export default merge(baseConfig, configuration);

0 commit comments

Comments
 (0)