-
Notifications
You must be signed in to change notification settings - Fork 0
/
webpack.config.js
executable file
·89 lines (85 loc) · 2.32 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
const R = require("ramda");
const dotenv = require("dotenv");
const path = require("path");
const WebpackBar = require("webpackbar");
const HtmlWebpackPlugin = require("html-webpack-plugin");
const CopyWebpackPlugin = require("copy-webpack-plugin");
const { EnvironmentPlugin, ProvidePlugin } = require("webpack");
const CompressionPlugin = require("compression-webpack-plugin");
const zlib = require("zlib");
// Load environment files from .env files
dotenv.config();
const isDevelopment = process.env.NODE_ENV !== "production";
// Pick environment variables start with RODONES_MAP_ (RODONES_MAP_EXAMPLE)
const environment = R.pickBy(R.flip(R.startsWith(`RODONES_MAP_`)), process.env);
environment.RODONES_MAP_BUILT_DATE = new Date().toUTCString();
module.exports = {
mode: isDevelopment ? "development" : "production",
devtool: isDevelopment ? "eval-source-map" : false,
entry: {
index: "./src/index.js",
},
module: {
rules: [
{
test: /\.js$/i,
exclude: /node_modules/,
use: {
loader: "babel-loader",
options: {
presets: ["@babel/preset-env"],
plugins: [["@babel/plugin-transform-runtime"]],
},
},
},
],
},
resolve: {
extensions: [".js"],
},
output: {
path: path.resolve(__dirname, "dist"),
filename: "[name].bundle.js",
},
stats: {
modules: false,
},
devServer: {
compress: true,
open: false,
hot: false,
liveReload: true,
static: {
directory: path.resolve(__dirname, "./public"),
publicPath: "/",
},
},
plugins: R.filter(R.identity, [
new ProvidePlugin({
process: "process/browser",
}),
new EnvironmentPlugin(environment),
new HtmlWebpackPlugin({
template: path.resolve(__dirname, "src", "index.html"),
templateParameters: environment,
}),
new WebpackBar(),
new CopyWebpackPlugin({
patterns: [{ from: "public" }],
}),
!isDevelopment &&
new CompressionPlugin({
filename: "[path][base].br",
algorithm: "brotliCompress",
test: /\.(js|css|html|svg)$/,
compressionOptions: {
params: {
[zlib.constants.BROTLI_PARAM_QUALITY]: 11,
},
},
threshold: 10240,
minRatio: 0.8,
deleteOriginalAssets: false,
}),
]),
};