-
Notifications
You must be signed in to change notification settings - Fork 55
Expand file tree
/
Copy pathwebpack.config.js
More file actions
378 lines (333 loc) · 10.7 KB
/
webpack.config.js
File metadata and controls
378 lines (333 loc) · 10.7 KB
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
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
const path = require("path");
const HtmlWebpackPlugin = require("html-webpack-plugin");
const CopyWebpackPlugin = require("copy-webpack-plugin");
const merge = require("webpack-merge");
const zh_hans = require("./i18n/zh_hans.json");
const zh_hant = require("./i18n/zh_hant.json");
const es = require("./i18n/es.json");
const ar = require("./i18n/ar.json");
const fr = require("./i18n/fr.json");
const ru = require("./i18n/ru.json");
const de = require("./i18n/de.json");
const ja = require("./i18n/ja.json");
const mr = require("./i18n/mr.json");
const pes = require("./i18n/pes.json");
const it = require("./i18n/it.json");
const ro = require("./i18n/ro.json");
const hr = require("./i18n/hr.json");
const nl = require("./i18n/nl.json");
const hu = require("./i18n/hu.json");
const sv = require("./i18n/sv.json");
const ca = require("./i18n/ca.json");
const br = require("./i18n/br.json");
const cs = require("./i18n/cs.json");
const fa = require("./i18n/fa.json");
const id = require("./i18n/id.json");
const ko = require("./i18n/ko.json");
const pl = require("./i18n/pl.json");
const uk = require("./i18n/uk.json");
const nb = require("./i18n/nb.json");
const config = require("./config");
/* ======= WEB TARGET ======= */
const prepTranslation = (langCode, langData) => {
return langData.flatMap(t => {
let target = t.reference.replace('Elm:', `%${langCode}:`) + "%";
let replacement = t.definition;
if (typeof target === "string" && target.startsWith(`%${langCode}`) && typeof replacement === "string" ) {
// Regular replacement
return [{ search: target
, replace: replacement.replace('\n', '\\n').replace(/'/g,"\\'")
, flags : 'g'
}];
} else if (replacement === null) {
return [{ search: target
, replace: t.term.replace(/'/g, "\\'")
, flags : 'g'
}];
} else if (t.hasOwnProperty("term_plural") && typeof replacement == "object" && replacement.hasOwnProperty("one")) {
// Plural replacement
let singReplace = replacement.one.replace(/'/g,"\\'");
let plurReplace = replacement.other.replace(/'/g, "\\'");
plurReplace = plurReplace == "" ? t.term_plural : plurReplace;
return [
{ search: target+":0" , replace: singReplace, flags : 'g' },
{ search: target+":1" , replace: plurReplace, flags: 'g' }];
} else {
return [];
}
});
}
const zhHansT = prepTranslation("zh_hans", zh_hans);
const zhHantT = prepTranslation("zh_hant", zh_hant);
const esT = prepTranslation("es", es);
const arT = prepTranslation("ar", ar);
const frT = prepTranslation("fr", fr);
const ruT = prepTranslation("ru", ru);
const deT = prepTranslation("de", de);
const jaT = prepTranslation("ja", ja);
const mrT = prepTranslation("mr", mr);
const pesT = prepTranslation("pes", pes);
const itT = prepTranslation("it", it);
const roT = prepTranslation("ro", ro);
const hrT = prepTranslation("hr", hr);
const nlT = prepTranslation("nl", nl);
const huT = prepTranslation("hu", hu);
const svT = prepTranslation("sv", sv);
const caT = prepTranslation("ca", ca);
const brT = prepTranslation("br", br);
const csT = prepTranslation("cs", cs);
const faT = prepTranslation("fa", fa);
const idT = prepTranslation("id", id);
const koT = prepTranslation("ko", ko);
const plT = prepTranslation("pl", pl);
const ukT = prepTranslation("uk", uk);
const nbT = prepTranslation("nb", nb);
const allLanguageStrings = [].concat(zhHansT, zhHantT, esT, arT, frT, ruT, deT, jaT,mrT, pesT, itT, roT, hrT, nlT, huT, svT, caT, brT, csT, faT, idT, koT, plT, ukT, nbT)
const otherReplacements = [
{ search: '{%SUPPORT_EMAIL%}', replace: config.SUPPORT_EMAIL, flags: 'g' },
{ search: '{%SUPPORT_URGENT_EMAIL%}', replace: config.SUPPORT_URGENT_EMAIL, flags: 'g' },
{ search: '{%HOMEPAGE_URL%}', replace: config.HOMEPAGE_URL, flags: 'g' },
{ search: '{%TESTIMONIAL_URL%}', replace: config.TESTIMONIAL_URL, flags: 'g' }
]
const isDev = false;
const isDebug = false;
const webConfig = {
// "production" or "development" flag.
mode: isDev ? "development" : "production",
target: "web",
// Set the base directory manually, instead of CWD.
context: path.join(__dirname, "src"),
// Where to output bundled code.
output: {
path: path.join(__dirname, "web"),
publicPath: "/",
filename: "[name].js"
},
// Entry points into the code. The root of the dependency tree.
entry: {
doc: "./shared/doc.js"
},
stats: 'errors-only',
// What file types to attempt to resolve within require/import statements
resolve: {
alias: { Container: path.resolve(__dirname, "src/web/container-web.js") },
extensions: [".js", ".elm"],
fallback: { "crypto": false }
},
// Rules on how to handle specific files.
module: {
rules: [
{
test: /\.css$/,
use: [
'style-loader',
{ loader: 'css-loader', options: { importLoaders: 1 } },
'postcss-loader'
],
},
{
test: /\.elm$/,
include: path.resolve(__dirname, 'src'),
exclude: [/elm-stuff/, /node_modules/],
use: [
{
loader: "string-replace-loader",
options : { multiple : isDev ? [] : allLanguageStrings.concat(otherReplacements) }
},
{
loader: "elm-webpack-loader",
options: {optimize: !isDev, debug: isDebug, verbose: true, pathToElm: "./elm-log-colors.sh"}
}
]
}
]
},
// Source maps in production for Sentry
devtool: !isDev ? "source-map" : false,
/*
externals: {
"pouchdb": "require('pouchdb')",
},
*/
plugins: [
// Plugin to insert only needed chunks of JS into HTML output files.
new HtmlWebpackPlugin({
freshdeskAppId: config.FRESHDESK_APPID,
template: "./index.ejs",
filename: "../web/index.html",
chunks: ["doc"]
}),
// Plugin to copy static assets (css, images).
new CopyWebpackPlugin({ patterns: [{
from: "./static",
to: "../web",
filter: async (resourcePath) => {
if (resourcePath.endsWith('index.html')) {
return false;
} else {
return true;
}
}
}]})
]
};
/* ======= ELECTRON TARGET ======= */
const baseElectronConfig = {
// "production" or "development" flag.
mode: "development",
devtool: "source-map",
// Set the base directory manually, instead of CWD.
context: path.join(__dirname, "src"),
// Without this, __dirname refers to dirname of input file.
// With this, refers to dirname of output file.
// https://github.com/electron/electron/issues/5107
node: {
__dirname: false
},
stats: 'errors-only',
// Where to output bundled code.
output: {
path: path.join(__dirname, "app"),
filename: "[name].js"
}
};
const electronMainConfig = merge(baseElectronConfig, {
// Set the target environment where the code bundles will run.
target: "electron-main",
externals: {
leveldown: "require('leveldown')"
},
// Entry points into the code. The roots of the dependency tree.
entry: {
electron: "./electron/main.js"
},
// What file types to attempt to resolve within require/import statements
resolve: {
alias: { Container: path.resolve(__dirname, 'src/electron/container-electron.js') },
extensions: ['.js', '.elm']
},
// Rules on how to handle specific files.
module: {
rules: [
{
test: /\.elm$/,
exclude: [/elm-stuff/, /node_modules/],
use: {
loader: 'elm-webpack-loader',
options: { verbose: true, pathToElm: './elm-log-colors.sh' }
}
},
{
test: /\.worker\.js$/,
use: { loader: 'worker-loader' }
}
]
}
})
const electronRendererConfig = merge(baseElectronConfig, {
// Set the target environment where the code bundles will run.
target: 'electron-renderer',
// Entry points into the code. The root of the dependency tree.
entry: {
home: './electron/home.js',
shortcuts: './electron/shortcuts-modal.js',
videos: './electron/videos-modal.js',
support: './electron/support-modal.js',
trial: './electron/trial-modal.js',
renderer: './electron/renderer.js'
},
// What file types to attempt to resolve within require/import statements
resolve: {
alias: { Container: path.resolve(__dirname, "src/electron/container-electron.js") },
extensions: [".js", ".elm"]
},
// Rules on how to handle specific files.
module: {
rules: [
{
test: /\.elm$/,
exclude: [/elm-stuff/, /node_modules/],
use:
[
{
loader: 'string-replace-loader',
options: { multiple: otherReplacements }
},
{
loader: 'elm-webpack-loader',
options: { verbose: true, pathToElm: './elm-log-colors.sh' }
}
]
}
]
},
plugins: [
// Plugin to insert only needed chunks of JS into HTML output files.
new HtmlWebpackPlugin({
template: './electron/home.ejs',
filename: '../app/static/home.html',
chunks: ['home']
}),
new HtmlWebpackPlugin({
template: './electron/shortcuts-modal.ejs',
filename: '../app/static/shortcuts-modal.html',
chunks: ['shortcuts']
}),
new HtmlWebpackPlugin({
template: './electron/videos-modal.ejs',
filename: '../app/static/videos-modal.html',
chunks: ['videos']
}),
new HtmlWebpackPlugin({
template: './electron/faq-modal.ejs',
filename: '../app/static/faq-modal.html',
chunks: []
}),
new HtmlWebpackPlugin({
template: './electron/support-modal.ejs',
filename: '../app/static/support-modal.html',
chunks: ['support']
}),
new HtmlWebpackPlugin({
template: './electron/trial-modal.ejs',
filename: '../app/static/trial-modal.html',
chunks: ['trial']
}),
new HtmlWebpackPlugin({
template: './electron/trial-success-modal.ejs',
filename: '../app/static/trial-success-modal.html',
chunks: []
}),
new HtmlWebpackPlugin({
template: './electron/enter-license-modal.ejs',
filename: '../app/static/enter-license-modal.html',
chunks: []
}),
new HtmlWebpackPlugin({
template: './electron/renderer.ejs',
filename: '../app/static/renderer.html',
chunks: ['renderer']
}),
// Plugin to copy electron preload scripts
new CopyWebpackPlugin({
patterns: [{
from: './electron/preload.js',
to: '../app/preload.js'
}]
}),
new CopyWebpackPlugin({
patterns: [{
from: './electron/trial-preload.js',
to: '../app/trial-preload.js'
}]
}),
// Plugin to copy static assets (css, images).
new CopyWebpackPlugin({
patterns: [{
from: './static',
to: '../app/static'
}]
})
]
})
module.exports = [ webConfig];