-
Notifications
You must be signed in to change notification settings - Fork 3
/
webpack.config.js
110 lines (108 loc) · 3.44 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
const path = require("node:path");
const webpack = require("webpack");
const HtmlWebpackPlugin = require("html-webpack-plugin");
const CopyWebpackPlugin = require("copy-webpack-plugin");
const package = require("./package.json");
const env = require("./server/utils/environment.js");
const CLIENTS = {
LOCAL: path.join(__dirname, "app/clients/local.js"),
REMOTE: path.join(__dirname, "app/clients/remote.js"),
};
module.exports = {
mode: process.env.NODE_ENV || "development", // "production",
target: "web",
entry: path.join(__dirname, "app", "index.jsx"),
output: {
path: path.join(__dirname, "www"),
publicPath: "./",
filename: "[name].[contenthash].js",
chunkFilename: "[name].[contenthash].chunk.js",
assetModuleFilename: "assets/[hash][ext][query]",
},
resolve:{
alias: {
"@folio/client": CLIENTS[(env?.CLIENT || "LOCAL").toUpperCase()],
},
},
optimization: {
splitChunks: {
chunks: "all",
},
},
devServer: {
hot: false,
static: {
directory: path.join(__dirname, "www"),
staticOptions: {
extensions: ["html"],
},
},
historyApiFallback: {
rewrites: [
{from: /^\/$/, to: "app.html"},
{from: /^\/index.html$/, to: "app.html"},
],
},
devMiddleware: {
writeToDisk: true,
},
},
module: {
rules: [
{
test: /\.(js|jsx)$/,
include: [
path.join(__dirname, "app"),
path.join(__dirname, "packages"),
],
exclude: /(node_modules|www)/,
loader: "babel-loader",
options: {
presets: [
"@babel/preset-env",
"@babel/preset-react",
],
plugins: [
"@babel/plugin-transform-react-jsx",
"@babel/plugin-transform-runtime",
],
},
},
{
test: /\.(png|jpg|jpeg|svg)$/,
type: "asset/resource",
},
{
test: /\.(woff(2)?|ttf|eot|svg)(\?v=\d+\.\d+\.\d+)?$/,
type: "asset/resource",
},
{
test: /resources\/stickers\/([\w-]+)\.svg$/,
type: "asset/inline",
},
],
},
plugins: [
new webpack.ProgressPlugin(),
new webpack.DefinePlugin({
// Global values
"process.env.VERSION": JSON.stringify(package.version),
"process.env.URL_REPOSITORY": JSON.stringify(package.repository),
"process.env.URL_ISSUES": JSON.stringify(package.bugs),
"process.env.URL_HOMEPAGE": JSON.stringify(package.homepage),
// ENV values
"process.env.APP": JSON.stringify(env.APP || "LITE"),
"process.env.CLIENT": JSON.stringify(env.CLIENT || "LOCAL"),
}),
new CopyWebpackPlugin({
patterns: [
path.join(__dirname, "node_modules/lowcss/low.css"),
],
}),
new HtmlWebpackPlugin({
template: path.join(__dirname, "app", "template.html"),
filename: "app.html",
minify: true,
}),
],
};