-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathwebpack.config.js
142 lines (140 loc) · 3.8 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
const path = require("path");
const CopyPlugin = require("copy-webpack-plugin");
const HtmlWebpackPlugin = require("html-webpack-plugin");
const MiniCssExtractPlugin = require("mini-css-extract-plugin");
const WebpackBar = require("webpackbar");
const { CleanWebpackPlugin } = require("clean-webpack-plugin");
const { InjectManifest } = require("workbox-webpack-plugin");
const webpack = require("webpack");
const sveltePreprocess = require("svelte-preprocess");
const mode = process.env.NODE_ENV || "development";
const prod = mode === "production";
module.exports = {
entry: {
bundle: ["./src/entrypoints/main.js"],
android: ["./src/entrypoints/android.js"],
ios: ["./src/entrypoints/ios.js"],
},
resolve: {
alias: {
svelte: path.resolve("node_modules", "svelte"),
},
extensions: [".mjs", ".js", ".svelte", ".ts", ".tsx", "", ".webpack.js", ".web.js"],
mainFields: ["svelte", "browser", "module", "main"],
},
output: {
path: `${__dirname}/dist`,
filename: "[name].js",
chunkFilename: "[name].js",
},
ignoreWarnings: [/Failed to parse source map/],
module: {
rules: [
// All files with a '.ts' or '.tsx' extension will be handled by 'ts-loader'.
{ test: /\.tsx?$/, loader: "ts-loader" },
{
test: /\.js$/,
exclude: /node_modules/,
use: {
loader: "babel-loader",
},
},
// All output '.js' files will have any sourcemaps re-processed by 'source-map-loader'.
{ test: /\.(js|tsx?)$/, loader: "source-map-loader" },
{ test: /\.svelte$/,
use: {
loader: "svelte-loader",
options: {
emitCss: true,
preprocess: sveltePreprocess({}),
hotReload: true,
},
},
},
{
test: /\.css$/,
use: [
/**
* MiniCssExtractPlugin doesn't support HMR.
* For developing, use 'style-loader' instead.
* */
prod ? MiniCssExtractPlugin.loader : "style-loader",
"css-loader",
],
},
{
test: /\.(png|svg|jpg|gif)$/,
use: [
"url-loader",
],
},
],
},
mode,
optimization: {
splitChunks: {
chunks: "all",
},
usedExports: true,
},
plugins: [
new CleanWebpackPlugin(),
new webpack.DefinePlugin({
GIT_COMMIT_HASH: JSON.stringify(process.env.COMMIT_REF),
BACKEND: JSON.stringify(process.env.BACKEND),
}),
new HtmlWebpackPlugin({
filename: "index.html",
template: "src/html/index.html",
chunks: ["bundle"],
}),
new HtmlWebpackPlugin({
filename: "android.html",
template: "src/html/android.html",
chunks: ["android"],
}),
new HtmlWebpackPlugin({
filename: "ios.html",
template: "src/html/ios.html",
chunks: ["ios"],
}),
new HtmlWebpackPlugin({
filename: "imprint.html",
template: "src/html/imprint.html",
chunks: [],
}),
new HtmlWebpackPlugin({
filename: "privacy.html",
template: "src/html/privacy.html",
chunks: [],
}),
new MiniCssExtractPlugin({
filename: "[name].css",
}),
new CopyPlugin({
patterns: [
// Copy Shoelace assets to dist/shoelace
{
from: path.resolve(__dirname, "node_modules/@shoelace-style/shoelace/dist/assets"),
to: path.resolve(__dirname, "dist/shoelace/assets"),
},
{ from: "public" },
],
}),
new WebpackBar(),
new InjectManifest({
swSrc: "./src/sw.js",
swDest: "sw.js",
maximumFileSizeToCacheInBytes: 50000000,
exclude: [
/volunteers\.png$/,
/imprint\.html$/,
/_headers$/,
/_redirects$/,
/\.map$/,
/shoelace\/assets\/icons\/(.*)$/,
],
}),
],
devtool: "source-map",
};