forked from syncpoint/ODIN
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwebpack.config.js
113 lines (98 loc) · 2.82 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
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
const path = require('path')
const { spawn } = require('child_process')
const HtmlWebpackPlugin = require('html-webpack-plugin')
const webpack = require('webpack')
const ESLintPlugin = require('eslint-webpack-plugin')
const hash = 'hash:base64:8'
const RULES = {
javascript: {
test: /\.js$/,
exclude: /node_modules/,
use: ['babel-loader']
},
css: {
// css-loader: resolve/load required/imported CSS dependencies from JavaScript
// style-loader: wrap CSS string from css-loader with <style> tag
// Note: loaders are applied from right to left, i.e. css-loader -> style-loader
//
test: /\.css$/,
use: ['style-loader', 'css-loader']
},
image: {
test: /\.(png|svg|jpe?g|gif)$/i,
use: [{
loader: 'file-loader',
options: {
name: 'img/[name].[ext]'
}
}]
},
font: {
test: /\.(eot|svg|ttf|woff|woff2)$/,
use: [{ loader: `file-loader?name=font/[name]__[${hash}].[ext]` }]
}
}
const rules = () => Object.values(RULES)
const mode = env => env.production ? 'production' : 'development'
const rendererConfig = (env, argv) => ({
context: path.resolve(__dirname, 'src/renderer'),
target: 'electron-renderer',
// In production mode webpack applies internal optimization/minification:
// no additional plugins necessary.
// For advanced options: babel-minify-webpack-plugin: https://webpack.js.org/plugins/babel-minify-webpack-plugin
mode: mode(env),
stats: 'errors-only',
module: { rules: rules() },
entry: {
renderer: ['./index.js']
},
plugins: [
new HtmlWebpackPlugin({ title: 'ODIN - C2IS' }),
new webpack.IgnorePlugin({ resourceRegExp: /html2canvas|canvg/ }),
new ESLintPlugin()
]
})
const mainConfig = (env, argv) => ({
context: path.resolve(__dirname, 'src/main'),
target: 'electron-main',
mode: mode(env),
stats: 'errors-only',
entry: {
main: './main.js'
}
})
const devServer = env => {
if (env.production) return ({}) // no development server for production
return ({
devServer: {
onListening: function (devServer) {
if (!devServer) throw new Error('Whoa, devServer does not seem to be running.')
spawn(
'electron',
['.'],
{ shell: true, env: process.env, stdio: 'inherit' }
)
.on('close', code => process.exit(code))
.on('error', error => console.error(error))
}
}
})
}
const devtool = env => {
if (env.production) return ({}) // no source maps for production
return ({
devtool: 'cheap-source-map'
})
}
module.exports = (env, argv) => {
env = env || {}
// Merge development server and devtool to renderer configuration when necessary:
const renderer = Object.assign(
{},
rendererConfig(env, argv),
devServer(env),
devtool(env)
)
const main = mainConfig(env, argv)
return [renderer, main]
}