-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild.js
28 lines (26 loc) · 821 Bytes
/
build.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
const fs = require('fs');
const esbuild = require('esbuild');
// Load the environment variables from the .env file
const ENV_FILE = '.env.local';
const envFileContent = fs.readFileSync(ENV_FILE, 'utf8');
const envVariables = envFileContent
.split('\n')
.filter(line => line.trim() !== '')
.filter(line => line.startsWith('REACT_APP'))
.reduce((result, line) => {
const [key, value] = line.split('=');
result[`process.env.${key}`] = JSON.stringify(value);
return result;
}, {});
// Build your React app with esbuild
esbuild.build({
entryPoints: ['app/javascript/application.js'],
bundle: true,
sourcemap: true,
publicPath: '/assets',
outdir: 'app/assets/builds',
define: envVariables, // Inject environment variables
}).catch((error) => {
console.error(error);
process.exit(1);
});