This repository has been archived by the owner on May 6, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
webpack.config.base.js
executable file
·95 lines (90 loc) · 2.55 KB
/
webpack.config.base.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
const R = require("ramda");
const RA = require("ramda-adjunct");
const dotenv = require("dotenv");
const path = require("path");
const WebpackBar = require("webpackbar");
const HtmlWebpackPlugin = require("html-webpack-plugin");
const ReactRefreshWebpackPlugin = require("@pmmmwh/react-refresh-webpack-plugin");
const { EnvironmentPlugin, ProvidePlugin } = require("webpack");
function getAppConfig(envPrefix) {
// Load environment files from .env files
dotenv.config();
const isDevelopment = process.env.NODE_ENV !== "production";
// Pick environment variables start with envIdentifier (REACT_APP_* like)
const environment = R.pickBy(
R.flip(R.startsWith(`${envPrefix}_`)),
process.env,
);
return {
mode: isDevelopment ? "development" : "production",
devtool: isDevelopment ? "eval-source-map" : false,
entry: path.join(__dirname, ".", "src", "index.tsx"),
module: {
rules: [
{
test: /\.(ts|js)x?$/,
exclude: /node_modules/,
use: {
loader: "babel-loader",
options: {
presets: [
"@babel/preset-env",
[
"@babel/preset-react",
{
runtime: "automatic",
},
],
"@babel/preset-typescript",
],
plugins: RA.compact([
[
"@babel/plugin-transform-runtime",
{
regenerator: true,
},
],
isDevelopment && require.resolve("react-refresh/babel"),
]),
},
},
},
{
test: /\.css$/i,
use: ["style-loader", "css-loader"],
},
],
},
resolve: {
extensions: [".tsx", ".ts", ".js"],
},
output: {
path: path.resolve(__dirname, "dist"),
filename: "bundle.js",
publicPath: "/",
},
stats: {
modules: false,
},
devServer: {
static: path.join(__dirname, "dist"),
compress: true,
open: false,
hot: true,
historyApiFallback: true,
},
plugins: RA.compact([
new ProvidePlugin({
process: "process/browser",
}),
new EnvironmentPlugin(environment),
new HtmlWebpackPlugin({
template: path.resolve(module.parent.path, "public", "index.html"),
templateParameters: environment,
}),
new WebpackBar(),
isDevelopment && new ReactRefreshWebpackPlugin(),
]),
};
}
module.exports = getAppConfig;