-
Notifications
You must be signed in to change notification settings - Fork 14
/
Copy pathwebpack.config.base.js
108 lines (104 loc) · 3.98 KB
/
webpack.config.base.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
const fs = require("fs");
const path = require("path");
const CopyWebpackPlugin = require("copy-webpack-plugin");
const CleanWebpackPlugin = require("clean-webpack-plugin");
const I18nPlugin = require("@zainulbr/i18n-webpack-plugin");
const utils = require("./utils");
module.exports = function () {
// Prepare the dist directories. It has to exist before we attempt to create the .zip archive.
if (!fs.existsSync("dist")) {
fs.mkdirSync("dist");
}
const default_splash_path = utils.getBaseOrCustomPath("src/resources/splash.png");
const default_resources_path = utils.getBaseOrCustomPath("src/www/resources.zip");
var styling_path = utils.getBaseOrCustomPath("src/www/styles/");
// Build the configuration object.
return {
mode: "development",
// The starting point of our app
entry: {
bundle: utils.getBaseOrCustomPath("src/www/scripts/entry.js"),
},
// The output of our build run
output: {
path: path.resolve("build/www"),
filename: "js/bundle.js",
},
devtool: "eval-source-map",
module: {
// Rules are used to process specific file types
rules: [
{
test: /\.css$/,
use: "css-loader",
},
{
test: /\.mustache$/,
use: "mustache-loader",
},
{
test: /\.js$/,
exclude: /node_modules/,
use: {
loader: "babel-loader",
options: {
presets: [
[
"@babel/preset-env",
{
useBuiltIns: "usage",
corejs: 3,
targets: "> 0.25%, not dead",
},
],
],
cacheDirectory: true,
},
},
},
],
},
// This is where the bulk of the action happens
plugins: [
// Clean up previous builds
new CleanWebpackPlugin(["build"], {
root: process.cwd(),
exclude: ["platforms", "plugins", "package.json"],
}),
// Make the static strings translatable / configurable
new I18nPlugin(utils.loadConfiguration("config/texts.json"), {
hideMessage: true,
}),
new CopyWebpackPlugin({
patterns: [
{
context: path.dirname(default_splash_path),
from: path.basename(default_splash_path),
to: path.basename(default_splash_path),
noErrorOnMissing: true,
},
{
context: path.dirname(default_resources_path),
from: path.basename(default_resources_path),
to: path.normalize("resources.zip"),
noErrorOnMissing: true,
},
{
context: path.dirname(styling_path),
from: "**/*.css",
to: path.normalize("css/[name].css"),
noErrorOnMissing: true,
},
...utils.getBaseAndCustomPaths("src/www/images").map(function (dir) {
return {
context: dir,
from: "**/*",
to: path.normalize("img"),
noErrorOnMissing: true,
};
}),
],
})
],
};
};