forked from getstation/desktop-app
-
Notifications
You must be signed in to change notification settings - Fork 0
/
webpack.config.renderer.js
138 lines (127 loc) · 3.91 KB
/
webpack.config.renderer.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
/* eslint-disable no-param-reassign */
/**
* Build config for electron renderer process
*/
const glob = require('glob');
const path = require('path');
const webpack = require('webpack');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const MiniCssExtractPlugin = require('mini-css-extract-plugin');
const { mutateWebpackConfig } = require('./webpack.config.common');
// Packages that we want to be bundled
const externalsWhitelist = [
'slack', // forces "browser" target
/*'redux-ui',
'redux-ui/transpiled/action-reducer',
'@getstation/theme',
'@storybook/react',
'@storybook/ui',
'react-apollo',
"react-apollo-hooks",
"react-click-outside",
"react-dnd",
"react-dnd-html5-backend",
"react-hover-observer",
"react-image",
"react-immutable-proptypes",
"react-jss",
"react-key-handler",
"react-popper",
"react-redux",
"react-resize-detector",
"react-svg-inline",
"react-tether",
"react-transition-group",
'scrollmonitor-react',
'prop-types',
'classnames',
'scroll-into-view-if-needed',
'use-events',
'use-key-hook'*/
];
/**
* @param config {webpack.Configuration}
*/
module.exports = (config) => {
// console.log(require('util').inspect(config, { depth: 8 }));
mutateWebpackConfig(config);
config.plugins = config.plugins.map((plugin) => {
// default HtmlWebpackPlugin should be the worker
if (plugin.constructor.name === 'HtmlWebpackPlugin') {
plugin.options.chunks = ['worker'];
}
return plugin;
});
config.plugins = config.plugins.concat([
new MiniCssExtractPlugin({
filename: '[name].styles.css',
chunkFilename: '[id].styles.css',
}),
// generates main window html file
new HtmlWebpackPlugin({
chunks: ['mainRenderer'],
filename: 'main.html',
template: './app/app.html',
inject: true,
}),
// generates sub windows html file
new HtmlWebpackPlugin({
chunks: ['subRenderer'],
filename: 'sub.html',
template: './app/app-sub.html',
inject: true,
}),
// generates about window html file
new HtmlWebpackPlugin({
chunks: ['aboutRenderer'],
filename: 'about.html',
template: './app/about-window/about.html',
inject: true,
}),
]);
config.entry = {
// main window
mainRenderer: './app/index.js',
// sub windows
subRenderer: './app/index-sub.js',
// about window
aboutRenderer: './app/about-window/about.js',
// worker
worker: './app/app-worker.ts',
};
// migration files
Object.assign(config.entry, glob.sync('./app/persistence/umzug-runs/*.js')
.reduce((obj, filepath) => {
const filename = path.basename(filepath, path.extname(filepath));
return {
...obj,
[filename]: filepath
};
}, {}));
// '/' is necessary to resolve Icons.svg from theme
if (config.devServer) {
// Mainly for `static` folder, probably a cleaner way to do this that is compatible with dev and prod
config.devServer.contentBase.push(path.resolve(__dirname, 'app'));
config.devServer.contentBase.push('/');
config.devServer.headers = { 'Access-Control-Allow-Origin': '*', 'Access-Control-Allow-Headers': '*' };
}
if (config.mode === 'development') {
// with this we can use preload file in dev mode
config.plugins.push(new webpack.DefinePlugin({
__webpack_public_path__: JSON.stringify(config.output.path),
__webpack_main_path__: JSON.stringify(path.resolve(config.output.path, '../main')),
}));
}
config.output.filename = (chunkData) => {
// umzug-runs files should be in 'umzug-runs' directory to be found by umzug
if (path.basename(chunkData.chunk.entryModule.context) === 'umzug-runs') {
return 'umzug-runs/[name].js';
}
// default
return '[name].js';
};
config.externals.push('react');
config.externals.push('react-dom');
config.externals = config.externals.filter(e => !externalsWhitelist.includes(e));
return config;
};