import { defineConfig, loadEnv } from '@rsbuild/core';
import { pluginReact } from '@rsbuild/plugin-react';

const { publicVars, rawPublicVars } = loadEnv({prefixes: ['REACT_APP_']});

export default defineConfig({
    server: {
        base: (rawPublicVars['REACT_APP_ROOT_PATH'] !== undefined) ? rawPublicVars['REACT_APP_ROOT_PATH'] : '/'
    },
	output: {
		filename: {
			js: '[name]_script.[contenthash:8].js',
			css: '[name]_style.[contenthash:8].css',
		},
		assetPrefix: (rawPublicVars['REACT_APP_ROOT_PATH'] !== undefined) ? rawPublicVars['REACT_APP_ROOT_PATH'] : './'
	},
	html: {
		template: './public/index.html',
	},
    source: {
        include: [{ not: /[\\/]core-js[\\/]/ }],
        define: {
            ...publicVars,
            'process.env': JSON.stringify(rawPublicVars),
        }
    },
	plugins: [pluginReact()],
});
