-
Notifications
You must be signed in to change notification settings - Fork 25
Expand file tree
/
Copy pathrsbuild.config.ts
More file actions
126 lines (117 loc) · 3.94 KB
/
Copy pathrsbuild.config.ts
File metadata and controls
126 lines (117 loc) · 3.94 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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
import {defineConfig, loadEnv} from '@rsbuild/core';
import {pluginReact} from '@rsbuild/plugin-react';
import {pluginSass} from '@rsbuild/plugin-sass';
import {pluginSvgr} from '@rsbuild/plugin-svgr';
import MonacoWebpackPlugin from 'monaco-editor-webpack-plugin';
/**
* List of environment variables that should be accessible in HTML and JavaScript files.
* These variables are injected into the client-side code via process.env definitions.
*/
const APP_VARS = [
'DISABLE_ESLINT_PLUGIN',
'TSC_COMPILE_ON_ERROR',
'REACT_APP_DISABLE_CHECKS',
'REACT_APP_E2E_UI_OVERRIDES',
'NODE_ENV',
// Backend configuration
'REACT_APP_BACKEND',
'REACT_APP_META_BACKEND',
'META_YDB_BACKEND',
];
/**
* Prepares environment variables to be exposed in client-side code.
*
* This function:
* 1. Loads environment variables from .env files using rsbuild's loadEnv()
* 2. Explicitly checks process.env for each variable (prioritizes process.env over .env file values)
* 3. Stringifies values for safe injection into JavaScript code via source.define
*
* CRITICAL FOR CI: We must explicitly pass process.env variables to source.define,
* otherwise they are not accessible in client code in CI (GitHub Actions).
* rsbuild's loadEnv() only reads from .env files, not from process.env by default.
*/
const prepareEnvVars = () => {
// Load values from .env files (if they exist)
const {parsed} = loadEnv();
const result: Record<string, string> = {};
APP_VARS.forEach((name) => {
// Priority: process.env > .env file
// This ensures CI-provided env vars (from GitHub Actions, Playwright webServer, etc.)
// take precedence over .env file values
const value = process.env[name] ?? parsed[name];
// Stringify for safe injection into JavaScript code
result[name] = JSON.stringify(value);
});
return {
// Without this, environment variables would not be available in index.html or JavaScript
'process.env': result,
};
};
export default defineConfig({
plugins: [
pluginReact(),
pluginSass(),
pluginSvgr({
svgrOptions: {
exportType: 'default',
},
}),
],
server: {
proxy:
process.env.META_YDB_BACKEND && process.env.META_YDB_BACKEND !== 'undefined'
? {
'/meta': {
target: process.env.META_YDB_BACKEND,
changeOrigin: true,
},
}
: undefined,
},
source: {
entry: {
index: './src/index.tsx',
},
include: [
'node_modules/antlr4-c3',
'node_modules/@gravity-ui/websql-autocomplete',
'node_modules/antlr4ng',
],
define: prepareEnvVars(),
},
output: {
distPath: {
root: './build',
// YDB server that serves static files expects fonts to be in media folder
// and favicon in static folder
font: 'static/media',
favicon: 'static',
},
assetPrefix: 'auto',
sourceMap: {
js: process.env.GENERATE_SOURCEMAP !== 'false' ? 'source-map' : false,
},
// Inline CSS in development to prevent FOUC
injectStyles: process.env.NODE_ENV === 'development',
},
html: {
template: './public/index.html',
favicon: './public/static/favicon.png',
},
tools: {
rspack(config, {appendPlugins}) {
appendPlugins([
new MonacoWebpackPlugin({
languages: ['yaml'],
customLanguages: [
{
label: 'yql',
entry: 'monaco-yql-languages/build/monaco.contribution',
},
],
}),
]);
return config;
},
},
});