forked from udacity/mws-restaurant-stage-1
-
Notifications
You must be signed in to change notification settings - Fork 0
/
webpack.common.js
98 lines (97 loc) · 2.5 KB
/
webpack.common.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
const path = require("path");
const CleanWebpackPlugin = require("clean-webpack-plugin");
const HtmlWebpackPlugin = require("html-webpack-plugin");
const WorkboxPlugin = require("workbox-webpack-plugin");
module.exports = {
entry: {
shared: [
"@babel/polyfill",
path.resolve(__dirname, "src/js/pages/shared.js"),
path.resolve(__dirname, "src/sass/index.scss")
],
main: path.resolve(__dirname, "src/js/pages/main/index.js"),
restaurant: path.resolve(__dirname, "src/js/pages/restaurant/index.js")
},
output: {
path: path.resolve(__dirname, "build/"),
publicPath: "/"
},
module: {
rules: [
{
test: /\.js$/,
exclude: /(node_modules|bower_components)/,
use: {
loader: "babel-loader"
}
},
{
test: /\.scss$/,
use: [
"style-loader", // creates style nodes from JS strings
"css-loader", // translates CSS into CommonJS
"sass-loader" // compiles Sass to CSS, using Node Sass by default
]
},
{
test: /\.(png|svg|jpg|gif)$/,
use: [
{
loader: "file-loader",
options: {
name: "img/[hash].[ext]"
}
},
{
loader: "image-webpack-loader",
options: {
disable: process.env.NODE_ENV != "production"
}
}
]
},
{
test: /restaurants\.json$/,
type: "javascript/auto",
use: [
{
loader: "file-loader",
options: { name: "data/[name].[ext]" }
}
]
}
]
},
resolve: {
modules: [__dirname, "node_modules"]
},
plugins: [
new CleanWebpackPlugin(["build"]),
new HtmlWebpackPlugin({
chunks: ["shared", "main"],
template: path.resolve(__dirname, "src/index.html")
}),
new HtmlWebpackPlugin({
chunks: ["shared", "restaurant"],
template: path.resolve(__dirname, "src/restaurant.html"),
filename: "restaurant.html"
}),
new WorkboxPlugin.GenerateSW({
// these options encourage the ServiceWorkers to get in there fast
// and not allow any straggling "old" SWs to hang around
clientsClaim: true,
skipWaiting: true,
runtimeCaching: [
{
urlPattern: /restaurant\.html/,
handler: "networkFirst",
options: {
cacheableResponse: {
statuses: [0, 200]
}
}
}
]
})
]
};