generated from skedwards88/template-app
-
Notifications
You must be signed in to change notification settings - Fork 0
/
webpack.config.js
122 lines (116 loc) · 3.99 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
const path = require("path");
const WorkboxPlugin = require("workbox-webpack-plugin");
const HtmlWebpackPlugin = require("html-webpack-plugin");
const CopyPlugin = require("copy-webpack-plugin");
const packageJson = require("./package.json");
module.exports = (env, argv) => {
if (argv.mode === "development") {
console.log("RUNNING IN DEV MODE. Service worker will not generate.");
} else {
console.log("RUNNING IN NON-DEV MODE. Service worker will generate.");
}
const htmlPlugin = new HtmlWebpackPlugin({
// Need to use template because need 'root' div for react injection. templateContent doesn't play nice with title, so just use a template file instead.
template: "./src/index.html",
});
const copyPlugin = new CopyPlugin({
patterns: [
{from: "./src/manifest.json", to: "./assets/manifest.json"},
{from: "./src/assetlinks.json", to: "./.well-known/assetlinks.json"},
{from: "./src/privacy.html", to: "./privacy.html"},
{from: "./src/images/favicons/favicon.svg", to: "./assets/favicon.svg"},
{from: "./src/images/favicons/icon_512.png", to: "./assets/icon_512.png"},
{
from: "./src/images/screenshots/blobble_complete_1080x1080.png",
to: "./blobble_complete_1080x1080.png",
},
{
from: "./src/images/screenshots/blobble_new_720x1280.png",
to: "./blobble_new_720x1280.png",
},
{
from: "./src/images/screenshots/blobble_new_1080x1080.png",
to: "./blobble_new_1080x1080.png",
},
{
from: "./src/images/screenshots/blobble_partial_720x1280.png",
to: "./blobble_partial_720x1280.png",
},
{
from: "./src/images/screenshots/blobble_partial_1080x1080.png",
to: "./blobble_partial_1080x1080.png",
},
{
from: "./src/images/screenshots/blobble_progress_720x1280.png",
to: "./blobble_progress_720x1280.png",
},
{
from: "./src/images/screenshots/blobble_progress_1080x1080.png",
to: "./blobble_progress_1080x1080.png",
},
{
from: "./src/images/screenshots/blobble_rules_720x1280.png",
to: "./blobble_rules_720x1280.png",
},
{
from: "./src/images/screenshots/blobble_rules_1080x1080.png",
to: "./blobble_rules_1080x1080.png",
},
],
options: {
concurrency: 100,
},
});
const serviceWorkerPlugin = new WorkboxPlugin.GenerateSW({
// This helps ensure that all pages will be controlled by a service worker immediately after that service worker activates
clientsClaim: true,
// This skips the service worker waiting phase, meaning the service worker activates as soon as it's finished installing
skipWaiting: true,
cacheId: `blobble-${packageJson.version}`,
// special case to cache word list for offline play
maximumFileSizeToCacheInBytes: 4200000,
});
const plugins =
argv.mode === "development"
? [htmlPlugin, copyPlugin]
: [htmlPlugin, copyPlugin, serviceWorkerPlugin];
return {
entry: "./src/index.js",
mode: "production",
module: {
rules: [
{
test: /\.(js|jsx)$/,
exclude: /(node_modules|bower_components)/,
loader: "babel-loader",
options: {presets: ["@babel/env"]},
},
{
test: /\.css$/i,
use: ["style-loader", "css-loader"],
},
{
test: /\.(png|svg|jpg|jpeg|gif|webp)$/i,
type: "asset/resource",
},
],
},
resolve: {extensions: ["*", ".js", ".jsx"]},
output: {
publicPath: "",
filename: "bundle.[fullhash].js",
path: path.resolve(__dirname, "dist"),
clean: true, // removes unused files from output dir
},
performance: {
// special case to cache word list for offline play
maxEntrypointSize: 2700000, // bytes
// special case to cache word list for offline play
maxAssetSize: 2700000, // bytes
},
devServer: {
static: "./dist",
},
plugins: plugins,
};
};