forked from fterdal/Capstone-1-Frontend
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwebpack.config.js
More file actions
89 lines (86 loc) · 2.43 KB
/
webpack.config.js
File metadata and controls
89 lines (86 loc) · 2.43 KB
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
const path = require("path");
const HtmlWebpackPlugin = require("html-webpack-plugin");
const webpack = require("webpack");
const { GenerateSW } = require('workbox-webpack-plugin');
const CopyWebpackPlugin = require('copy-webpack-plugin');
require("dotenv").config();
const isProduction = process.env.NODE_ENV === 'production';
const useHttps = process.env.USE_HTTPS === 'true';
module.exports = {
watch: false,
mode: isProduction ? "production" : "development",
entry: "./src/App.jsx",
output: {
path: path.resolve(__dirname, "dist"),
filename: "main.js",
publicPath: "/", // needed for React Router
},
devtool: "source-map",
plugins: [
new webpack.EnvironmentPlugin({
API_URL: process.env.API_URL || "http://127.0.0.1:8080",
REACT_APP_AUTH0_DOMAIN: process.env.REACT_APP_AUTH0_DOMAIN || "",
REACT_APP_AUTH0_CLIENT_ID: process.env.REACT_APP_AUTH0_CLIENT_ID || "",
REACT_APP_AUTH0_AUDIENCE: process.env.REACT_APP_AUTH0_AUDIENCE || "",
REACT_APP_GOOGLE_MAPS_API_KEY: process.env.REACT_APP_GOOGLE_MAPS_API_KEY || "",
}),
new HtmlWebpackPlugin({
template: "./public/index.html",
}),
...(isProduction
? [
new GenerateSW({
clientsClaim: true,
skipWaiting: true,
maximumFileSizeToCacheInBytes: 5 * 1024 * 1024, // allow files up to 5MB
cleanupOutdatedCaches: true,
navigateFallback: '/index.html',
exclude: [/index\.html/],
})
]
: []),
new CopyWebpackPlugin({
patterns: [
{ from: "public/manifest.json", to: "manifest.json" },
{ from: "public/icons", to: "icons" },
{ from: "public/screenshots", to: "screenshots" },
],
}),
],
module: {
rules: [
{
test: /\.(js|jsx)$/,
exclude: /node_modules/,
use: {
loader: "babel-loader",
options: {
presets: ["@babel/preset-react"],
},
},
},
{
test: /\.(png|jpe?g|gif|svg)$/i,
type: "asset/resource",
generator: {
filename: "images/[hash][ext][query]",
},
},
{
test: /\.css$/,
use: ["style-loader", "css-loader"],
},
],
},
resolve: {
extensions: [".js", ".jsx"],
},
devServer: {
host: "127.0.0.1",
port: 3000,
allowedHosts: "all",
historyApiFallback: true,
server: useHttps ? "https" : "http",
hot: true,
},
};