This repository has been archived by the owner on Aug 1, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwebpack.config.js
116 lines (111 loc) · 2.79 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
const webpack = require("webpack")
const path = require("path")
const UglifyJsPlugin = require("uglifyjs-webpack-plugin")
const HtmlWebpackPlugin = require("html-webpack-plugin")
const FaviconsWebpackPlugin = require("favicons-webpack-plugin")
const CleanWebpackPlugin = require("clean-webpack-plugin")
const CopyWebpackPlugin = require("copy-webpack-plugin")
const HtmlWebpackIncludeAssetsPlugin = require("html-webpack-include-assets-plugin")
const AddAssetsToJSON = require("add-assets-to-json-webpack-plugin")
const GenerateJsonPlugin = require("generate-json-webpack-plugin")
const crypto = require("crypto")
const generateHash = () => {
const md5sum = crypto.createHash("md5")
md5sum.update(new Date().toISOString())
return md5sum.digest("hex")
}
const appConfig = {
entry: {
app: "./src/index.js"
},
output: {
path: path.join(__dirname, "public/"),
filename: "assets/js/[name].min.js"
},
resolve: {
extensions: [".js", "css"]
},
module: {
rules: [
{
test: /\.js$/,
exclude: /node_modules/,
loader: "babel-loader"
},
{
test: /\.css$/,
use: ["style-loader", "css-loader"]
}
]
},
plugins: [
new CleanWebpackPlugin(["public"]),
new webpack.DefinePlugin({
"process.env": {
NODE_ENV: JSON.stringify(process.env.NODE_ENV || "development"),
SW_PATH: JSON.stringify("sw.js")
}
}),
new FaviconsWebpackPlugin({
logo: "./assets/favicon.png",
prefix: "assets/icons/",
title: "Awesome Pokedex"
}),
new CopyWebpackPlugin([
{
from: "node_modules/mdi/css/materialdesignicons.min.css",
to: "assets/css/"
},
{
from: "node_modules/mdi/fonts/",
to: "assets/fonts/"
},
{
from: "src/sw.js",
to: "."
}
]),
new HtmlWebpackPlugin({
template: "assets/index.html",
excludeChunks: ["sw"]
}),
new HtmlWebpackIncludeAssetsPlugin({
assets: ["assets/css/materialdesignicons.min.css"],
append: false
}),
new AddAssetsToJSON({
path: path.resolve(__dirname, "public")
}),
new GenerateJsonPlugin("sw.json", {
IMAGES_CACHE_NAME: "images-content-cache",
CACHE_NAME: `cache-${generateHash()}`,
ASSETS_JSON_PATH: "assets.json",
DEFAULT_ASSETS: [
"/",
"https://fonts.googleapis.com/css?family=VT323",
"https://fonts.gstatic.com/s/vt323/v9/lo_L7yCDHYN9FAxvMCI1vQ.woff2"
],
CACHE_IGNORED: [
"sw.js",
"sw.json",
"assets.json",
"assets/icons/.cache",
"index.html"
],
IMAGES_PREFIX:
"https://raw.githubusercontent.com/PokeAPI/sprites/master/sprites/pokemon/"
})
],
devServer: {
contentBase: path.resolve(__dirname, "./public"),
historyApiFallback: true,
inline: true,
open: true
}
}
if (process.env.NODE_ENV === "production") {
appConfig.plugins.push(new UglifyJsPlugin())
} else {
appConfig.devtool = "eval-source-map"
}
module.exports = appConfig