forked from getstation/desktop-app
-
Notifications
You must be signed in to change notification settings - Fork 0
/
webpack.config.common.js
99 lines (88 loc) · 2.29 KB
/
webpack.config.common.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
const path = require('path');
/* eslint-disable no-param-reassign */
/**
* Disable verbose logs
* @param config {webpack.Configuration}
*/
const mutateStats = (config) => {
config.stats = 'errors-only';
};
/**
* set ts-loader as transpileOnly for now. Also excludes node_modules from compilation
* @param config {webpack.Configuration}
*/
const mutateFixTsLoader = (config) => {
const tsLoader = config.module.rules.find(r => r && r.use && r.use[0] && r.use[0].loader === 'ts-loader');
if (tsLoader) {
tsLoader.use[0].options.transpileOnly = true;
tsLoader.exclude = /node_modules/;
}
};
/**
* minimizer should keep classnames and fnames
* @param config {webpack.Configuration}
*/
const mutateFixTerser = (config) => {
if (config.mode === 'production') {
Object.assign(config.optimization.minimizer[0].options.terserOptions, {
keep_classnames: true,
keep_fnames: true,
});
}
};
/**
* add sources to sourcemap
* @param config {webpack.Configuration}
*/
const mutateDevtool = (config) => {
if (config.mode === 'production') {
config.devtool = 'source-map';
}
};
/**
* loader for graphql schema and .env.* files
* @param config {webpack.Configuration}
*/
const mutateAddRules = (config) => {
config.module.rules.push({
test: /\.graphql$/,
exclude: /node_modules/,
loader: 'graphql-import-loader'
});
config.module.rules.push({
test: /\.svg$/,
loader: 'svg-inline-loader'
});
};
/**
* minimizer should keep classnames and fnames
* @param config {webpack.Configuration}
*/
const mutateAddExternals = (config) => {
// Used by window-open overload
config.externals.push('react-addons-perf');
};
/**
* alias some missing imports
* @param config {webpack.Configuration}
*/
const mutateAlias = (config) => {
// Electron does not bundle `ipcRendererInternal` anymore since 7.x
config.resolve.alias['@electron/internal/renderer/ipc-renderer-internal'] =
path.resolve(__dirname, 'app/lib/ipc-renderer-internal.ts');
};
/**
* @param config {webpack.Configuration}
*/
const mutateWebpackConfig = (config) => {
mutateStats(config);
mutateFixTsLoader(config);
mutateFixTerser(config);
mutateAddRules(config);
mutateAddExternals(config);
mutateDevtool(config);
mutateAlias(config);
};
module.exports = {
mutateWebpackConfig,
};