-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathwebpack.config.js
70 lines (63 loc) · 1.85 KB
/
webpack.config.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
'use strict';
const { resolve } = require('path');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const CopyWebpackPlugin = require('copy-webpack-plugin');
const webpack = require('webpack');
const mode = process.env.NODE_ENV === 'production' ? 'production' : 'development';
const distPath = resolve(__dirname, 'dist');
const base = {
mode,
devtool: mode === 'production' ? 'nosources-source-map' : 'eval-source-map',
output: {
path: distPath,
chunkFilename: '[name].chunk.js',
filename: '[name].js'
},
resolve: {
extensions: ['.js', '.dylib', '.dll']
}
};
const renderPlugins = [
new HtmlWebpackPlugin({ template: resolve(__dirname, 'index.html') })
];
const config = env => {
const preload = !!(env && env.preload);
const main = Object.assign({}, base, {
target: preload ? 'electron-preload' : 'electron-main',
output: Object.assign({}, base.output, {
path: resolve(base.output.path, 'main')
}),
entry: preload ? { preload: resolve(__dirname, 'preload.js') }
: { index: resolve(__dirname, 'main.js') },
plugins: preload ? undefined : [
new CopyWebpackPlugin({
patterns: [
{
from: resolve(__dirname, 'lib'),
to: resolve(base.output.path, 'lib')
}
]
}),
new webpack.DefinePlugin({
'__dist': `"${distPath}"`
})
]
});
if (!preload) {
main.plugins.push(
new webpack.DefinePlugin({
'__goLib': `"${resolve(__dirname, 'lib').replace(/\\/g, '\\\\')}"`,
})
);
}
const renderer = Object.assign({}, base, {
target: 'electron-renderer',
output: Object.assign({}, base.output, {
path: resolve(base.output.path, 'renderer')
}),
entry: { renderer: resolve(__dirname, 'renderer.js') },
plugins: renderPlugins
});
return [main, renderer];
};
module.exports = config;