This repository has been archived by the owner on Dec 26, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
webpack.config.js
202 lines (184 loc) · 4.5 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
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
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
"use strict";
//--------------------------------------------------------------------------------------------------
// Constants
//--------------------------------------------------------------------------------------------------
const plugin = {
/**
* All required plugins for the webpack config.
*/
path: require("path"),
webpack: require("webpack"),
html: require("html-webpack-plugin"),
clean: require("clean-webpack-plugin"),
extract: require("extract-text-webpack-plugin"),
globSCSS: require("node-sass-glob-importer")
},
modules = {
/**
* Globally required modules & their variables.
* Instead of writing e.g.
* const log = require("logger.module");
* in each module.
*/
global: {
_: "lodash",
log: "app.logger.module",
logapi: "api.logger.module",
connect: "connect.module",
error: "error.module",
loader: "loader.module"
},
/**
* All required modules via
* require("module");
* are searched in these directories (listed by a priority).
*/
search: ["node_modules", "src/config", "src/core/modules", "src/core", "src/local"]
},
paths = {
dest: plugin.path.join(__dirname, "/app"),
bootstrap: plugin.path.join(__dirname, "/src/bootstrap.js"),
electron: plugin.path.join(__dirname, "/electron.config.js"),
rootTpl: plugin.path.join(__dirname, "/src/local/routes/default/template.ejs"),
clean: [plugin.path.join(__dirname, "/app")]
};
//--------------------------------------------------------------------------------------------------
// Application Configuration
//--------------------------------------------------------------------------------------------------
let application = {
mode: process.env.MODE,
target: "electron-renderer",
entry: {
bundle: paths.bootstrap
},
/**
* Modules discribes what webpack should to do with non-javascript files.
*/
module: {
rules: [
// SCSS Styles
{
test: /\.scss$/,
use: plugin.extract.extract({
fallback: "style-loader",
use: [
{
loader: "css-loader",
options: {
minimize: {
discardComments: {
removeAll: process.env.MODE === "development"
}
},
sourceMap: process.env.MODE === "development"
}
},
{
loader: "sass-loader",
options: {
importer: plugin.globSCSS()
}
}
]
})
},
// EJS Templates
{
test: /\.ejs$/,
loader: "ejs-loader"
},
// Images
{
test: /\.(png|svg|jpg|gif)$/,
use: [
{
loader: "file-loader",
options: {
outputPath: "images"
}
}
]
},
// Fonts
{
test: /\.(woff2|otf)$/,
use: [
{
loader: "file-loader",
options: {
outputPath: "fonts"
}
}
]
}
]
},
node: {
// Enable __dirname and __filename passing
__dirname: false,
__filename: false
},
output: {
filename: "[name].[hash].js",
path: paths.dest
},
resolve: {
modules: modules.search
},
plugins:
process.env.MODE === "development"
? [
// Remove app directory
new plugin.clean(paths.clean),
// Globally defined dependencies
new plugin.webpack.ProvidePlugin(modules.global),
// Extract CSS
new plugin.extract({
filename: "[name].[hash].css"
}),
// Main page
new plugin.html({
title: "EvoDoc",
template: paths.rootTpl
}),
// JS Sourcemaps
new plugin.webpack.SourceMapDevToolPlugin({
filename: "[name].[hash].js.map"
})
]
: [
// Remove app directory
new plugin.clean(paths.clean),
// Extract CSS
new plugin.extract({
filename: "[name].[hash].css"
}),
// Globally defined dependencies
new plugin.webpack.ProvidePlugin(modules.global),
// Main page
new plugin.html({
title: "EvoDoc",
template: paths.rootTpl
})
]
};
//--------------------------------------------------------------------------------------------------
// ElectronJS Configuration
//--------------------------------------------------------------------------------------------------
let electron = {
mode: process.env.MODE,
target: "electron-main",
entry: paths.electron,
node: {
__dirname: false,
__filename: false
},
output: {
filename: "app.js",
path: paths.dest
}
};
//--------------------------------------------------------------------------------------------------
// Export
//--------------------------------------------------------------------------------------------------
module.exports = [electron, application];