forked from aparabolica/arco-mineiro
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwebpack.config.js
139 lines (132 loc) · 3.27 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
const path = require("path");
const webpack = require("webpack");
const WebpackPwaManifest = require("webpack-pwa-manifest");
const OfflinePlugin = require("offline-plugin");
const FaviconsWebpackPlugin = require("favicons-webpack-plugin");
const HTMLWebpackPlugin = require("html-webpack-plugin");
let config = {
entry: {
main: ["./src/index"]
},
resolve: {
modules: ["src", "files", "node_modules"]
},
output: {
path: path.resolve("public"),
publicPath: "/",
filename: "[name]-[chunkhash].js"
},
plugins: [
new webpack.DefinePlugin({
"process.env": {
NODE_ENV: JSON.stringify(process.env.NODE_ENV || ""),
SITE_URL: JSON.stringify(process.env.SITE_URL || ""),
DEFAULT_CREDITS: JSON.stringify(process.env.DEFAULT_CREDITS || ""),
GOOGLE_ANALYTICS: JSON.stringify(process.env.GOOGLE_ANALYTICS || ""),
LAUNCH_DATE: JSON.stringify(process.env.LAUNCH_DATE || "")
}
})
],
module: {
loaders: [
{
test: /\.jsx?/,
loader: "babel-loader",
exclude: /node_modules/,
query: {
presets: ["env", "react"],
plugins: [
"transform-object-rest-spread",
"syntax-class-properties",
"transform-class-properties"
]
}
},
{
test: /\.json$/,
loader: "json-loader"
},
{
test: /\.css$/,
loader: "style-loader!css-loader"
},
{
test: /\.(png|jpg|gif|svg|woff2|woff|eot|ttf|mp4|pdf)$/,
loader: "file-loader",
options: {
name(file) {
if (file.indexOf("/documents/") !== -1) {
return "[name]-[hash].[ext]";
} else {
return "[hash].[ext]";
}
}
}
},
{
test: /\.(md|txt)$/,
use: [
{
loader: "raw-loader"
}
]
}
]
}
};
const favicons = new FaviconsWebpackPlugin({
logo: path.resolve("src/images", "logo.png")
});
const pwa = new WebpackPwaManifest({
name: "Digging into the Mining Arc",
short_name: "Digging into the Mining Arc",
description:
"The destruction of 110 thousand square kilometers of forests in the largest mining project in Venezuela",
background_color: "#fff",
orientation: "portrait",
start_url: "/?launcher=true",
icons: [
{
src: path.resolve("src/images", "logo.png"),
sizes: [48, 96, 192, 256, 512]
}
]
});
const html = new HTMLWebpackPlugin({
template: path.resolve("src", "index.html"),
filename: "index.html",
inject: "body"
});
const offline = new OfflinePlugin({
ServiceWorker: {
events: true
},
caches: {
main: [
"index.html",
"*.js",
"*.css",
"*.svg",
"*.ttf",
"*.woff",
"*.woff2"
],
additional: [":externals:", "*.jpg", "*.png"],
optional: ":rest:"
},
cacheMaps: [
{
match: url => {
if (url.origin !== location.origin) return;
return new URL("/", location);
},
requestTypes: ["navigate", "same-origin"]
}
]
});
if (process.env.NODE_ENV == "production") {
config.plugins = config.plugins.concat([favicons, pwa, html, offline]);
} else {
config.plugins = config.plugins.concat([html]);
}
module.exports = config;