forked from udacity/mws-restaurant-stage-1
-
Notifications
You must be signed in to change notification settings - Fork 0
/
webpack.config.js
85 lines (84 loc) · 2.56 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
const path = require("path");
const { CleanWebpackPlugin } = require("clean-webpack-plugin");
const HtmlWebpackPlugin = require("html-webpack-plugin");
const FaviconsWebpackPlugin = require("favicons-webpack-plugin");
const ServiceWorkerWebpackPlugin = require("serviceworker-webpack-plugin");
const CompressionPlugin = require("compression-webpack-plugin");
const CopyPlugin = require("copy-webpack-plugin");
module.exports = {
mode: "production",
entry: { index: "./src/js/index.js", restaurant: "./src/js/restaurant.js" },
output: { filename: "js/[name].js", path: path.resolve(__dirname, "dist") },
module: {
rules: [
{
test: /\.js$/,
exclude: /(node_modules)|(sw\.js$)/,
use: "babel-loader",
},
{
test: /\.css$/,
use: ["style-loader", "css-loader", "postcss-loader"],
},
{
test: /\.jpg$/,
loader: "responsive-loader",
options: {
min: 400,
max: 800,
steps: 2,
quality: 50,
name: "assets/images/[name]-[width].[ext]",
},
},
],
},
plugins: [
new CleanWebpackPlugin(),
new FaviconsWebpackPlugin({
logo: "./src/assets/favicon.png",
outputPath: "/assets",
favicons: {
appName: "MWS Restaurant",
appShortName: "MWS",
start_url: "/?source=pwa",
background: "#fcf5e4",
theme_color: "#fcf5e4",
icons: {
android: true,
appleIcon: true,
appleStartup: false,
coast: false,
favicons: true,
firefox: false,
windows: false,
yandex: false,
},
},
}),
new HtmlWebpackPlugin({
template: "src/html/common.html",
inject: "body",
chunks: ["index"],
minify: true,
templateParameters: { title: "Restaurant Reviews", restaurantPage: false },
}),
new HtmlWebpackPlugin({
filename: "restaurant.html",
template: "src/html/common.html",
inject: "body",
chunks: ["restaurant"],
minify: true,
templateParameters: { title: "Restaurant Info", restaurantPage: true },
}),
new ServiceWorkerWebpackPlugin({
entry: path.join(__dirname, "src/js/sw.js"),
exclude: ["src/assets/images/*.*"],
transformOptions: ({ assets }) => ({ assets: [...assets, "/?source=pwa"] }),
}),
new CompressionPlugin({ include: [/.html/, /.js$/, /.css/] }),
new CopyPlugin({ patterns: [{ from: "src/js/firebase-messaging-sw.js" }] }),
],
devtool: "source-map",
devServer: { contentBase: "./dist" },
};