forked from muffinista/before-dawn
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwebpack.main.config.js
124 lines (115 loc) · 2.72 KB
/
webpack.main.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
114
115
116
117
118
119
120
121
122
123
124
'use strict'
const path = require('path')
const packageJSON = require('./package.json')
const dependencies = packageJSON.dependencies
const optionalDependencies = packageJSON.optionalDependencies;
const webpack = require('webpack')
const outputDir = path.join(__dirname, "output");
const BabiliWebpackPlugin = require('babili-webpack-plugin')
const CopyWebpackPlugin = require('copy-webpack-plugin');
const deps = [].concat(Object.keys(dependencies),Object.keys(optionalDependencies));
let mainConfig = {
devtool: '#source-map',
entry: {
main: path.join(__dirname, 'src/main/index.js')
},
externals: [
deps
],
module: {
rules: [
{
test: /\.(js)$/,
enforce: 'pre',
exclude: [
/node_modules/,
/lib/
],
use: {
loader: 'eslint-loader',
options: {
formatter: require('eslint-friendly-formatter')
}
}
},
{
test: /\.js$/,
use: 'babel-loader',
exclude: /node_modules/
},
{
test: /\.node$/,
use: 'node-loader'
}
]
},
node: {
__dirname: false,
__filename: false
},
output: {
filename: '[name].js',
libraryTarget: 'commonjs2',
path: outputDir
},
plugins: [
new CopyWebpackPlugin([
{
from: path.join(__dirname, 'src', 'main', 'assets'),
to: path.join(outputDir, 'assets'),
ignore: ['.*']
}
]),
new CopyWebpackPlugin([
{
from: path.join(__dirname, 'src', 'bin'),
to: path.join(outputDir, 'bin'),
ignore: ['.*']
}
]),
new CopyWebpackPlugin([
{
from: path.join(__dirname, 'src', 'system-savers'),
to: path.join(outputDir, 'system-savers'),
ignore: ['.*']
}
]),
new CopyWebpackPlugin([
{
from: path.join(__dirname, 'src', 'main', '__template'),
to: path.join(outputDir, '__template'),
ignore: ['.*']
}
]),
new webpack.DefinePlugin({
'process.env.PACKAGE_VERSION': JSON.stringify(packageJSON.version)
}),
new webpack.NoEmitOnErrorsPlugin()
],
resolve: {
extensions: ['.js', '.json', '.node']
},
target: 'electron-main'
}
/**
* Adjust mainConfig for development settings
*/
if (process.env.NODE_ENV !== 'production') {
mainConfig.plugins.push(
new webpack.DefinePlugin({
'__static': `"${path.join(__dirname, '../static').replace(/\\/g, '\\\\')}"`
})
)
}
/**
* Adjust mainConfig for production settings
*/
if (process.env.NODE_ENV === 'production') {
mainConfig.plugins.push(
new BabiliWebpackPlugin(),
new webpack.DefinePlugin({
'process.env.NODE_ENV': '"production"'
})
)
}
module.exports = mainConfig