-
Notifications
You must be signed in to change notification settings - Fork 24
/
webpack.config.ts
87 lines (83 loc) · 2.35 KB
/
webpack.config.ts
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
import CopyPlugin from "copy-webpack-plugin";
import "dotenv/config";
import HtmlWebpackPlugin from "html-webpack-plugin";
import MiniCssExtractPlugin from "mini-css-extract-plugin";
import { Configuration, DefinePlugin } from "webpack";
const config = (
env: Record<string, string>,
{ mode }: { mode: "none" | "development" | "production" }
): Configuration => ({
entry: "./src/app/app.tsx",
output: {
filename: "app.bundle.js",
},
plugins: [
new DefinePlugin({
"process.env": {
REPOSITORY: JSON.stringify(process.env.REPOSITORY),
ELASTIC_URL: JSON.stringify(process.env.ELASTIC_URL),
VALIDATOR_URL: JSON.stringify(process.env.VALIDATOR_URL),
VALIDATOR_REMOTE_URL: JSON.stringify(process.env.VALIDATOR_REMOTE_URL),
FALLBACK_LANGUAGE: JSON.stringify(process.env.FALLBACK_LANGUAGE),
DEFAULT_COUNTRY_SECTIONS: JSON.stringify(process.env.DEFAULT_COUNTRY_SECTIONS),
},
}),
new HtmlWebpackPlugin({
template: "src/index.html",
minify: {
collapseWhitespace: true,
minifyCSS: true,
minifyJS: true,
removeComments: true,
useShortDoctype: true,
},
favicon: "src/asset/img/favicon-32x32.png",
}),
new MiniCssExtractPlugin({
filename: mode !== "production" ? "[name].css" : "[name].[fullhash].css",
chunkFilename: mode !== "production" ? "[id].css" : "[id].[fullhash].css",
}),
new CopyPlugin({
patterns: ["src/generated/main.wasm", "src/generated/wasm_exec.js"],
}),
],
module: {
rules: [
{
enforce: "pre",
test: /\.s(c)ss/,
loader: "import-glob-loader",
},
{
test: /\.(js|jsx|ts|tsx)$/,
exclude: /node_modules/,
use: "swc-loader",
},
{
test: /\.(sa|sc|c)ss$/,
use: [
mode !== "production" ? "style-loader" : MiniCssExtractPlugin.loader,
"css-loader",
"postcss-loader",
"sass-loader",
],
},
{
test: /\.(png|jpg|gif)$/,
type: "asset/inline",
},
{
test: /\.(woff|woff2|eot|ttf|otf|svg)$/,
type: "asset/resource",
},
],
},
resolve: {
extensions: [".js", ".jsx", ".json", ".yml", ".tsx", ".ts"],
alias: {
cldr$: "cldrjs",
cldr: "cldrjs/dist/cldr",
},
},
});
export default config;