-
Notifications
You must be signed in to change notification settings - Fork 0
/
webpack.config.js
executable file
·163 lines (155 loc) · 3.88 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
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
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");
const CopyPlugin = require('copy-webpack-plugin');
let config = {
entry: {
main: ["./src/index"]
},
resolve: {
modules: ["src", "files", "node_modules"]
},
devServer: {
contentBase: path.join(__dirname, "public"),
inline: true,
compress: true,
host: '0.0.0.0',
port: 8080
},
output: {
path: path.join(__dirname, "public"),
// publicPath: path.join(__dirname, "public/"),
filename: "[name]-[chunkhash].js"
},
plugins: [
new webpack.DefinePlugin({
"process.env": {
NODE_ENV: JSON.stringify(process.env.NODE_ENV || "production"),
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 || "")
},
__REACT_DEVTOOLS_GLOBAL_HOOK__: ({ isDisabled: true })
}),
new CopyPlugin([{
context: 'src/',
from: 'CNAME',
to: ''
}])
],
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: "Documentário O Mata Cavalo",
short_name: "Documentário O Mata Cavalo",
description:
"Documentário O Mata Cavalo",
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 html404 = new HTMLWebpackPlugin({
template: path.resolve("src", "index.html"),
filename: "404.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 => {
const extension = url.pathname.split(".").pop();
// Different origin
if (url.origin !== location.origin) return;
// PDF files
if (extension == "pdf") 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, html404]);
}
module.exports = config;